Bug 31306: Add search_ordered sub to order items with extra conditions

Commit message from JD:

On bug 27272 we are going to replace C4::Items::GetItemsInfo with Koha::Items
methods, but we need to keep the existing behaviour that is:

Order by publisheddate, enumchron for searisl, or by homebranch.branchname,
enumchron, LPAD( copynumber, 8, '0' ), desc dateaccessioned

Test plan:
Confirm that the code from the new method makes sense
Run t/db_dependent/Koha/Items.t

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Petro Vashchuk 2022-07-18 12:47:21 +03:00 committed by Tomas Cohen Arazi
parent 4b9179b0d5
commit 999014d3e8
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
1 changed files with 28 additions and 0 deletions

View File

@ -398,6 +398,34 @@ sub apply_regex {
return $value;
}
=head3 search_ordered
$items->search_ordered;
Search and sort items in a specific order, depending if serials are present or not
=cut
sub search_ordered {
my ($self) = @_;
if ( $self->search({ select => ["enumchron IS NOT NULL"] }) ) {
return $self->search( {}, { order_by => 'enumchron' } );
} else {
return $self->search(
{},
{
order_by => [
'homebranch.branchname',
'me.enumchron',
\"LPAD( me.copynumber, 8, '0' )",
{-desc => 'me.dateaccessioned'}
],
join => ['homebranch']
}
);
}
}
=head2 Internal methods