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

(-)a/Koha/Virtualshelves.pm (+39 lines)
Lines 119-124 sub get_some_shelves { Link Here
119
    );
119
    );
120
}
120
}
121
121
122
sub get_shelves_containing_record {
123
    my ( $self, $params ) = @_;
124
    my $borrowernumber = $params->{borrowernumber};
125
    my $biblionumber   = $params->{biblionumber};
126
127
    my @conditions = ( 'virtualshelfcontents.biblionumber' => $biblionumber );
128
    if ($borrowernumber) {
129
        push @conditions,
130
          {
131
              -or => [
132
                {
133
                    category => 1,
134
                    -or      => {
135
                        'me.owner' => $borrowernumber,
136
                        -or        => {
137
                            'virtualshelfshares.borrowernumber' => $borrowernumber,
138
                            "me.allow_add"                      => 1,
139
                        },
140
                    }
141
                },
142
                { category => 2 },
143
            ]
144
          };
145
    } else {
146
        push @conditions, { category => 2 };
147
    }
148
149
    return Koha::Virtualshelves->search(
150
        {
151
            -and => \@conditions
152
        },
153
        {
154
            join     => [ 'virtualshelfcontents', 'virtualshelfshares' ],
155
            group_by => 'shelfnumber',
156
            order_by => { -asc => 'shelfname' },
157
        }
158
    );
159
}
160
122
sub _type {
161
sub _type {
123
    return 'Virtualshelve';
162
    return 'Virtualshelve';
124
}
163
}
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt (+13 lines)
Lines 459-464 Link Here
459
                                                    </div>
459
                                                    </div>
460
                                                [% END %]
460
                                                [% END %]
461
461
462
                                                [% IF Koha.Preference('virtualshelves') AND SEARCH_RESULT.shelves.count %]
463
                                                    <div class="results_summary shelves">
464
                                                        <span class="label">Lists:</span>
465
                                                            <ul>
466
                                                                [% FOREACH shelf IN SEARCH_RESULT.shelves %]
467
                                                                    <li><a href="/cgi-bin/koha/opac-shelves.pl?op=view&amp;shelfnumber=[% shelf.shelfnumber %]">[% shelf.shelfname %]</a></li>
468
                                                                    [%~ UNLESS loop.last %], [% ELSE %].[% END ~%]
469
                                                                [% END %]
470
                                                            </ul>
471
                                                        </span>
472
                                                    </div>
473
                                                [% END %]
474
462
                                                [% IF ( SEARCH_RESULT.searchhighlightblob ) %]
475
                                                [% IF ( SEARCH_RESULT.searchhighlightblob ) %]
463
                                                    <span class="results_summary">
476
                                                    <span class="results_summary">
464
                                                        <span class="label">Match:</span>
477
                                                        <span class="label">Match:</span>
(-)a/koha-tmpl/opac-tmpl/bootstrap/less/opac.less (-1 / +1 lines)
Lines 2214-2220 td img { Link Here
2214
        line-height: 135%;
2214
        line-height: 135%;
2215
    }
2215
    }
2216
}
2216
}
2217
.tags {
2217
.tags, .shelves {
2218
    ul {
2218
    ul {
2219
        display: inline;
2219
        display: inline;
2220
        list-style: none;
2220
        list-style: none;
(-)a/opac/opac-search.pl (+8 lines)
Lines 54-59 use C4::External::OverDrive; Link Here
54
54
55
use Koha::LibraryCategories;
55
use Koha::LibraryCategories;
56
use Koha::Ratings;
56
use Koha::Ratings;
57
use Koha::Virtualshelves;
57
58
58
use POSIX qw(ceil floor strftime);
59
use POSIX qw(ceil floor strftime);
59
use URI::Escape;
60
use URI::Escape;
Lines 692-697 for (my $i=0;$i<@servers;$i++) { Link Here
692
                }
693
                }
693
            }
694
            }
694
695
696
            $res->{shelves} = Koha::Virtualshelves->get_shelves_containing_record(
697
                {
698
                    biblionumber   => $res->{biblionumber},
699
                    borrowernumber => $borrowernumber
700
                }
701
            );
702
695
            if ( C4::Context->preference('OpacStarRatings') eq 'all' ) {
703
            if ( C4::Context->preference('OpacStarRatings') eq 'all' ) {
696
                my $ratings = Koha::Ratings->search({ biblionumber => $res->{biblionumber} });
704
                my $ratings = Koha::Ratings->search({ biblionumber => $res->{biblionumber} });
697
                $res->{ratings} = $ratings;
705
                $res->{ratings} = $ratings;
(-)a/t/db_dependent/Virtualshelves.t (-2 / +89 lines)
Lines 1-7 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use Test::More tests => 5;
4
use Test::More tests => 6;
5
use DateTime::Duration;
5
use DateTime::Duration;
6
6
7
use C4::Context;
7
use C4::Context;
Lines 404-409 subtest 'Get shelves' => sub { Link Here
404
    teardown();
404
    teardown();
405
};
405
};
406
406
407
subtest 'Get shelves containing biblios' => sub {
408
409
    plan tests => 9;
410
    my $patron1 = $builder->build( { source => 'Borrower', } );
411
    my $patron2 = $builder->build( { source => 'Borrower', } );
412
    my $biblio1 = $builder->build( { source => 'Biblio', } );
413
    my $biblio2 = $builder->build( { source => 'Biblio', } );
414
    my $biblio3 = $builder->build( { source => 'Biblio', } );
415
    my $biblio4 = $builder->build( { source => 'Biblio', } );
416
417
    my $shelf1 = Koha::Virtualshelf->new(
418
        {   shelfname    => "my first shelf",
419
            owner        => $patron1->{borrowernumber},
420
            category     => 1,
421
        }
422
    )->store;
423
    my $shelf2 = Koha::Virtualshelf->new(
424
        {   shelfname    => "my x second shelf", # 'x' to make it sorted after 'third'
425
            owner        => $patron2->{borrowernumber},
426
            category     => 1,
427
        }
428
    )->store;
429
    my $shelf3 = Koha::Virtualshelf->new(
430
        {   shelfname    => "my third shelf",
431
            owner        => $patron1->{borrowernumber},
432
            category     => 2,
433
        }
434
    )->store;
435
436
    my $content1 = $shelf1->add_biblio( $biblio1->{biblionumber}, $patron1->{borrowernumber} );
437
    my $content2 = $shelf1->add_biblio( $biblio2->{biblionumber}, $patron1->{borrowernumber} );
438
    my $content3 = $shelf2->add_biblio( $biblio2->{biblionumber}, $patron2->{borrowernumber} );
439
    my $content4 = $shelf2->add_biblio( $biblio3->{biblionumber}, $patron2->{borrowernumber} );
440
    my $content5 = $shelf2->add_biblio( $biblio4->{biblionumber}, $patron2->{borrowernumber} );
441
    my $content6 = $shelf3->add_biblio( $biblio4->{biblionumber}, $patron2->{borrowernumber} );
442
443
    my $shelves_with_biblio1_for_any_patrons = Koha::Virtualshelves->get_shelves_containing_record(
444
        {
445
            biblionumber => $biblio1->{biblionumber},
446
        }
447
    );
448
    is ( $shelves_with_biblio1_for_any_patrons->count, 0, 'shelf1 is private and should not be displayed if patron is not logged in' );
449
450
    my $shelves_with_biblio4_for_any_patrons = Koha::Virtualshelves->get_shelves_containing_record(
451
        {
452
            biblionumber => $biblio4->{biblionumber},
453
        }
454
    );
455
    is ( $shelves_with_biblio4_for_any_patrons->count, 1, 'shelf3 is public and should be displayed for any patrons' );
456
    is ( $shelves_with_biblio4_for_any_patrons->next->shelfname, $shelf3->shelfname, 'The correct shelf (3) should be displayed' );
457
458
    my $shelves_with_biblio1_for_other_patrons = Koha::Virtualshelves->get_shelves_containing_record(
459
        {
460
            biblionumber => $biblio1->{biblionumber},
461
            borrowernumber => $patron2->{borrowernumber},
462
        }
463
    );
464
    is ( $shelves_with_biblio1_for_other_patrons->count, 0, 'shelf1 is private and should not be displayed for other patrons' );
465
466
    my $shelves_with_biblio1_for_owner = Koha::Virtualshelves->get_shelves_containing_record(
467
        {
468
            biblionumber => $biblio1->{biblionumber},
469
            borrowernumber => $patron1->{borrowernumber},
470
        }
471
    );
472
    is ( $shelves_with_biblio1_for_owner->count, 1, 'shelf1 is private and should be displayed for the owner' );
473
474
    my $shelves_with_biblio2_for_patron1 = Koha::Virtualshelves->get_shelves_containing_record(
475
        {
476
            biblionumber => $biblio2->{biblionumber},
477
            borrowernumber => $patron1->{borrowernumber},
478
        }
479
    );
480
    is ( $shelves_with_biblio2_for_patron1->count, 1, 'Only shelf1 should be displayed for patron 1 and biblio 1' );
481
    is ( $shelves_with_biblio2_for_patron1->next->shelfname, $shelf1->shelfname, 'The correct shelf (1) should be displayed for patron 1' );
482
483
    my $shelves_with_biblio4_for_patron2 = Koha::Virtualshelves->get_shelves_containing_record(
484
        {
485
            biblionumber => $biblio4->{biblionumber},
486
            borrowernumber => $patron2->{borrowernumber},
487
        }
488
    );
489
    is ( $shelves_with_biblio4_for_patron2->count, 2, 'Patron should shown private and public lists for a given biblio' );
490
    is ( $shelves_with_biblio4_for_patron2->next->shelfname, $shelf3->shelfname, 'The shelves should be sorted by shelfname' );
491
492
    teardown();
493
};
494
407
sub teardown {
495
sub teardown {
408
    $dbh->do(q|DELETE FROM virtualshelfshares|);
496
    $dbh->do(q|DELETE FROM virtualshelfshares|);
409
    $dbh->do(q|DELETE FROM virtualshelfcontents|);
497
    $dbh->do(q|DELETE FROM virtualshelfcontents|);
410
- 

Return to bug 16551