[Koha-devel] Library limits

Tomas Cohen Arazi tomascohen at gmail.com
Fri Jul 5 21:46:29 CEST 2019


Hi, I have filed this the following bugs now:

https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=23272 <- this one
has patches
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=23271

The idea is that we have Koha::Object::Limit::Library, currently only used
in Koha::Patron::Attribute::Type, and we should use it as a reference.

But I have a question: I noticed in Koha::AuthorisedValues we overload
->search by allowing it to have a (surprise?) parameter: branchcode. I use
the word 'surprise' because we've been leaning to the 'least surprise'
principle and allowing to pass an attribute name that isn't in the model,
seems like a surprise we would like to avoid.

I would like to propose we create an analogous
Koha::Objects::Limit::Library class (notice the plural), implementing a
specialized search method, with a name that clearly states the goal as
discussed previously in the context of a bug I now don't remember :-D In
the lines of

sub search_with_branch_limits {
    my ( $self, $params, $attributes, $library_id ) = @_;

    my $or =
      $library_id
      ? {
        '-or' => [
            'authorised_values_branches.branchcode' => undef,
            'authorised_values_branches.branchcode' => $library_id,
        ]
      }
      : {};
    my $join = $library_id ? { join => 'authorised_values_branches' } : {};
    $attributes //= {};
    $attributes = { %$attributes, %$join };
    return $self->SUPER::search( { %$params, %$or, }, $attributes );
}

Note: I'd replace the table and column names for the configured ones.

Opinions?

-- 
Tomás Cohen Arazi
Theke Solutions (http://theke.io)
✆ +54 9351 3513384
GPG: B2F3C15F
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.koha-community.org/pipermail/koha-devel/attachments/20190705/562024dd/attachment.html>


More information about the Koha-devel mailing list