View | Details | Raw Unified | Return to bug 38050
Collapse All | Expand All

(-)a/Koha/Virtualshelf.pm (+25 lines)
Lines 70-75 sub store { Link Here
70
    $self->created_on(dt_from_string)
70
    $self->created_on(dt_from_string)
71
        unless defined $self->created_on;
71
        unless defined $self->created_on;
72
72
73
    $self->sortfield( $self->_validate_sortfield( $self->sortfield ) )
74
        if $self->sortfield;
75
73
    return $self->SUPER::store($self);
76
    return $self->SUPER::store($self);
74
}
77
}
75
78
Lines 547-552 sub public_read_list { Link Here
547
550
548
=head2 Internal methods
551
=head2 Internal methods
549
552
553
=head3 _validate_sortfield
554
555
Validates and normalizes the sortfield value.
556
Defaults to 'title' if invalid, and converts 'copyrightdate' to 'publicationyear' for UNIMARC.
557
558
=cut
559
560
sub _validate_sortfield {
561
    my ( $self, $sortfield ) = @_;
562
563
    # Default to 'title' if invalid
564
    $sortfield = 'title'
565
        unless grep { $_ eq $sortfield } qw( title author copyrightdate publicationyear itemcallnumber dateadded );
566
567
    # Convert copyrightdate to publicationyear for UNIMARC
568
    if ( $sortfield eq 'copyrightdate' && C4::Context->preference('marcflavour') eq 'UNIMARC' ) {
569
        $sortfield = 'publicationyear';
570
    }
571
572
    return $sortfield;
573
}
574
550
=head3 _type
575
=head3 _type
551
576
552
=cut
577
=cut
(-)a/virtualshelves/shelves.pl (-12 / +2 lines)
Lines 123-133 if ( $op eq 'add_form' ) { Link Here
123
    if ($shelf) {
123
    if ($shelf) {
124
        $op = $referer;
124
        $op = $referer;
125
        my $sortfield = $query->param('sortfield');
125
        my $sortfield = $query->param('sortfield');
126
        $sortfield = 'title'
126
        $sortfield = $shelf->_validate_sortfield($sortfield);
127
            unless grep { $_ eq $sortfield } qw( title author copyrightdate publicationyear itemcallnumber dateadded );
128
        if ( $sortfield eq 'copyrightdate' and C4::Context->preference('marcflavour') eq 'UNIMARC' ) {
129
            $sortfield = 'publicationyear';
130
        }
131
        if ( $shelf->can_be_managed($loggedinuser) ) {
127
        if ( $shelf->can_be_managed($loggedinuser) ) {
132
            $shelf->shelfname( scalar $query->param('shelfname') );
128
            $shelf->shelfname( scalar $query->param('shelfname') );
133
            $shelf->sortfield($sortfield);
129
            $shelf->sortfield($sortfield);
Lines 294-305 if ( $op eq 'view' ) { Link Here
294
                   $query->param('sortfield')
290
                   $query->param('sortfield')
295
                || $shelf->sortfield
291
                || $shelf->sortfield
296
                || 'title';    # Passed in sorting overrides default sorting
292
                || 'title';    # Passed in sorting overrides default sorting
297
            $sortfield = 'title'
293
            $sortfield = $shelf->_validate_sortfield($sortfield);
298
                unless grep { $_ eq $sortfield }
299
                qw( title author copyrightdate publicationyear itemcallnumber dateadded );
300
            if ( $sortfield eq 'copyrightdate' and C4::Context->preference('marcflavour') eq 'UNIMARC' ) {
301
                $sortfield = 'publicationyear';
302
            }
303
            my $direction = $query->param('direction') || 'asc';
294
            my $direction = $query->param('direction') || 'asc';
304
            $direction = 'asc' if $direction ne 'asc' and $direction ne 'desc';
295
            $direction = 'asc' if $direction ne 'asc' and $direction ne 'desc';
305
            my $rows;
296
            my $rows;
306
- 

Return to bug 38050