Bug 17971

Summary: TT syntax for notices - Add support for plurals
Product: Koha Reporter: Jonathan Druart <jonathan.druart>
Component: Architecture, internals, and plumbingAssignee: Jonathan Druart <jonathan.druart>
Status: CLOSED FIXED QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: kyle, m.de.rooy
Version: unspecified   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:
Bug Depends on: 17958, 17970    
Bug Blocks: 17966, 18620    
Attachments: Bug 17971: TT syntax for notices - Add support for plurals
Bug 17971: Add support for objects represented by fk
[SIGNED-OFF] Bug 17971: TT syntax for notices - Add support for plurals
[SIGNED-OFF] Bug 17971: Add support for objects represented by fk
Bug 17971: TT syntax for notices - Add support for plurals
Bug 17971: Add support for objects represented by fk
Bug 17971: TT syntax for notices - Add support for plurals
Bug 17971: Add support for objects represented by fk
Bug 17971 (QA Followup) Clarify comment

Description Jonathan Druart 2017-01-23 14:31:12 UTC
On of the awesome things we will be able to do with the TT syntax is the support of plurals.

For instance we will be able to send a list of items, checkouts, etc. to the notice template.
That way we will get rid of our custom syntax like <<items.content>> or <item></item> for instance.

The existing code already has the playground for that but it is not used.
Comment 1 Jonathan Druart 2017-01-23 15:05:14 UTC
Created attachment 59426 [details] [review]
Bug 17971: TT syntax for notices - Add support for plurals

On of the awesome things we will be able to do with the TT syntax is the support of plurals.

For instance we will be able to send a list of items, checkouts, etc. to the notice template.
That way we will get rid of our custom syntax like <<items.content>> or <item></item> for instance.

The existing code already has the playground for that but it is not used.

Basically the idea is to add a "loops" key which can contain a list of
object to retrieve from the DB and send to the template.
For instance:
    loops => { overdues => [ $itemnumber_1, .., $itemnumber_N ] }

will send a variable "overdues" to the template. It will contain the
Koha::Checkout objects relative to the id passed.

There is one quite big inconvenient to this approach so far: since we
are still supporting the historical syntax, the objects can be fetch by
a script, then the script will send the id to GetPreparedLetter which
will refetch them.
This must be improved, but I suggest to do that later.

Test plan:
  prove t/db_dependent/Letters/TemplateToolkit.t
should return green
Comment 2 Jonathan Druart 2017-01-23 15:05:21 UTC
Created attachment 59427 [details] [review]
Bug 17971: Add support for objects represented by fk

For instance an issue is not fetch from its fk but using the fk
itemnumber.
We need to support them.
Comment 3 Josef Moravec 2017-01-24 19:58:46 UTC
Created attachment 59529 [details] [review]
[SIGNED-OFF] Bug 17971: TT syntax for notices - Add support for plurals

On of the awesome things we will be able to do with the TT syntax is the support of plurals.

For instance we will be able to send a list of items, checkouts, etc. to the notice template.
That way we will get rid of our custom syntax like <<items.content>> or <item></item> for instance.

The existing code already has the playground for that but it is not used.

Basically the idea is to add a "loops" key which can contain a list of
object to retrieve from the DB and send to the template.
For instance:
    loops => { overdues => [ $itemnumber_1, .., $itemnumber_N ] }

will send a variable "overdues" to the template. It will contain the
Koha::Checkout objects relative to the id passed.

There is one quite big inconvenient to this approach so far: since we
are still supporting the historical syntax, the objects can be fetch by
a script, then the script will send the id to GetPreparedLetter which
will refetch them.
This must be improved, but I suggest to do that later.

Test plan:
  prove t/db_dependent/Letters/TemplateToolkit.t
should return green

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Comment 4 Josef Moravec 2017-01-24 19:58:55 UTC
Created attachment 59530 [details] [review]
[SIGNED-OFF] Bug 17971: Add support for objects represented by fk

For instance an issue is not fetch from its fk but using the fk
itemnumber.
We need to support them.

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Comment 5 Marcel de Rooy 2017-03-10 09:49:02 UTC
Applying on top of 17970:

Applying: Bug 17971: TT syntax for notices - Add support for plurals
fatal: sha1 information is lacking or useless (C4/Letters.pm).
Repository lacks necessary blobs to fall back on 3-way merge.
Cannot fall back to three-way merge.
Comment 6 Jonathan Druart 2017-03-10 12:32:08 UTC
Created attachment 60987 [details] [review]
Bug 17971: TT syntax for notices - Add support for plurals

On of the awesome things we will be able to do with the TT syntax is the support of plurals.

For instance we will be able to send a list of items, checkouts, etc. to the notice template.
That way we will get rid of our custom syntax like <<items.content>> or <item></item> for instance.

The existing code already has the playground for that but it is not used.

Basically the idea is to add a "loops" key which can contain a list of
object to retrieve from the DB and send to the template.
For instance:
    loops => { overdues => [ $itemnumber_1, .., $itemnumber_N ] }

will send a variable "overdues" to the template. It will contain the
Koha::Checkout objects relative to the id passed.

There is one quite big inconvenient to this approach so far: since we
are still supporting the historical syntax, the objects can be fetch by
a script, then the script will send the id to GetPreparedLetter which
will refetch them.
This must be improved, but I suggest to do that later.

Test plan:
  prove t/db_dependent/Letters/TemplateToolkit.t
should return green

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Comment 7 Jonathan Druart 2017-03-10 12:32:22 UTC
Created attachment 60988 [details] [review]
Bug 17971: Add support for objects represented by fk

For instance an issue is not fetch from its fk but using the fk
itemnumber.
We need to support them.

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Comment 8 Nick Clemens (kidclamp) 2017-03-29 20:12:33 UTC
Created attachment 61710 [details] [review]
Bug 17971: TT syntax for notices - Add support for plurals

On of the awesome things we will be able to do with the TT syntax is the support of plurals.

For instance we will be able to send a list of items, checkouts, etc. to the notice template.
That way we will get rid of our custom syntax like <<items.content>> or <item></item> for instance.

The existing code already has the playground for that but it is not used.

Basically the idea is to add a "loops" key which can contain a list of
object to retrieve from the DB and send to the template.
For instance:
    loops => { overdues => [ $itemnumber_1, .., $itemnumber_N ] }

will send a variable "overdues" to the template. It will contain the
Koha::Checkout objects relative to the id passed.

There is one quite big inconvenient to this approach so far: since we
are still supporting the historical syntax, the objects can be fetch by
a script, then the script will send the id to GetPreparedLetter which
will refetch them.
This must be improved, but I suggest to do that later.

Test plan:
  prove t/db_dependent/Letters/TemplateToolkit.t
should return green

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Comment 9 Nick Clemens (kidclamp) 2017-03-29 20:12:38 UTC
Created attachment 61711 [details] [review]
Bug 17971: Add support for objects represented by fk

For instance an issue is not fetch from its fk but using the fk
itemnumber.
We need to support them.

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Comment 10 Nick Clemens (kidclamp) 2017-03-29 20:12:45 UTC
Created attachment 61712 [details] [review]
Bug 17971 (QA Followup) Clarify comment
Comment 11 Kyle M Hall (khall) 2017-03-31 11:53:47 UTC
Pushed to master for 17.05, thanks Jonathan, Nick!
Comment 12 Katrin Fischer 2017-04-02 16:23:10 UTC
This won't get ported back to 16.11.x as it is an enhancement.