[Koha-devel] [Koha::Object] Related records and calling methods from templates

David Cook dcook at prosentient.com.au
Fri Sep 16 01:28:46 CEST 2016


I'm not entirely sure what you mean in the first paragraph, so I don't have
much to add there.

 

Personally, I like having access to objects in the templates. In terms of
CRUD, it seems to make writing interfaces much easier and cleaner. I suppose
you could say that more code ends up in the template, but you could also say
that more of the presentation ends up in the template as well I think. I
suppose that's a debateable point. As for borrower.something vs
borrower->something, I don't know if it matters if it looks like a method or
a column. It would be quick enough to find out if it mattered. 

 

I'm not sure what you mean by the wrapper approach exactly, but personally I
think we could do with fewer wrappers and just try to keep things as simple
as possible.  Re-reading your example, do you mean that you'd pass a branch
code to the template and then use Branches.GetName from the Branches plugin
to replace that with the branch name? In theory, it would be nice if you
could do item.branchcode.branchname (where branchcode is a foreign key and
using the branchname method causes the Item object to fetch the
corresponding Branch object), which is something that I recall Jonathan
doing perhaps in some of the templates? Of course, I think using the plugin
approach, you might be able to add more multilingual support for other
things. For instance. item.itype would retrieve "BOOK".
Item.itype.item_description would be "Book", but if you used
ItemTypes.GetName (or something like that), you could possibly choose a
translated template instead of just the value from the database.

 

Since most of my work is in English, I'll defer to others regarding
translations in templates.

David Cook

Systems Librarian

Prosentient Systems

72/330 Wattle St

Ultimo, NSW 2007

Australia

 

Office: 02 9212 0899

Direct: 02 8005 0595

 

From: koha-devel-bounces at lists.koha-community.org
[mailto:koha-devel-bounces at lists.koha-community.org] On Behalf Of Marcel de
Rooy
Sent: Thursday, 15 September 2016 9:03 PM
To: koha-devel at lists.koha-community.org
Subject: [Koha-devel] [Koha::Object] Related records and calling methods
from templates

 

Hi devs,

 

I am seeing more Koha objects that include methods for related records like
Koha::Patron, sub image referring to Koha::Patron::Images.

As a second example, on bug 14610 (article requests), a biblio, item, branch
and borrower method is added to Koha::ArticleRequest.

Obviously, they all follow the same pattern.

Could we generalize that, and keep our code cleaner?

 

And do we always need the full Koha object? For use in a template we may
need only a few columns.

We start passing these objects to the templates now too, making it possible
to call methods from the template. It is possible, but do we really want
that? More code ends up in the template, maybe harder to find since you now
use borrower.method instead of borrower->method etc. Secondly, reading
borrower.something might not immediately tell you that something is a method
instead of a column.

In other cases we have added a sort of wrapper like Branches.GetName from
the Branches plugin.

I am interested to know if we want to enforce this wrapper approach for
instance, or just continue on the current road.

 

Thx,

 

Marcel

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.koha-community.org/pipermail/koha-devel/attachments/20160916/ad175a07/attachment-0001.html>


More information about the Koha-devel mailing list