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

(-)a/Koha/AdditionalContents.pm (-5 / +5 lines)
Lines 84-94 sub search_for_display { Link Here
84
    $search_params->{'additional_content.id'} = $params->{id} if $params->{id};
84
    $search_params->{'additional_content.id'} = $params->{id} if $params->{id};
85
    $search_params->{location}                = $params->{location};
85
    $search_params->{location}                = $params->{location};
86
    $search_params->{branchcode}              = $params->{library_id} ? [ $params->{library_id}, undef ] : undef;
86
    $search_params->{branchcode}              = $params->{library_id} ? [ $params->{library_id}, undef ] : undef;
87
    $search_params->{published_on}            = { '<=' => \'CAST(NOW() AS DATE)' };
87
    $search_params->{published_on}   = { '<=' => \'CAST(NOW() AS DATE)' }                   unless $params->{id};
88
    $search_params->{expirationdate}          = [ '-or', { '>=' => \'CAST(NOW() AS DATE)' }, undef ];
88
    $search_params->{expirationdate} = [ '-or', { '>=' => \'CAST(NOW() AS DATE)' }, undef ] unless $params->{id};
89
    $search_params->{category}                = $params->{category} if $params->{category};
89
    $search_params->{category}       = $params->{category} if $params->{category};
90
    $search_params->{lang}                    = 'default' if !$lang || $lang eq 'default';
90
    $search_params->{lang}           = 'default'           if !$lang || $lang eq 'default';
91
    $search_params->{-or}                     = [ { 'lang' => $lang }, '-and' => [ 'lang', 'default', \$subquery ] ]
91
    $search_params->{-or}            = [ { 'lang' => $lang }, '-and' => [ 'lang', 'default', \$subquery ] ]
92
        if !$search_params->{lang};
92
        if !$search_params->{lang};
93
93
94
    my $attribs = { prefetch => 'additional_content', order_by => 'additional_content.number' };
94
    my $attribs = { prefetch => 'additional_content', order_by => 'additional_content.number' };
(-)a/t/db_dependent/Template/Plugin/AdditionalContents.t (-2 / +30 lines)
Lines 33-39 my $builder = t::lib::TestBuilder->new; Link Here
33
$schema->storage->txn_begin;
33
$schema->storage->txn_begin;
34
34
35
subtest 'get' => sub {
35
subtest 'get' => sub {
36
    plan tests => 4;
36
    plan tests => 6;
37
37
38
    my $additional_contents = Koha::Template::Plugin::AdditionalContents->get(
38
    my $additional_contents = Koha::Template::Plugin::AdditionalContents->get(
39
        { category => 'news', location => [ 'opac_only', 'staff_and_opac' ], lang => 'default', library => '%' } );
39
        { category => 'news', location => [ 'opac_only', 'staff_and_opac' ], lang => 'default', library => '%' } );
Lines 61-66 subtest 'get' => sub { Link Here
61
        { category => 'news', location => [ 'opac_only', 'staff_and_opac' ], lang => 'default' } );
61
        { category => 'news', location => [ 'opac_only', 'staff_and_opac' ], lang => 'default' } );
62
    is( $additional_contents->{content}->count, $before_count + 1, "We get the additional one we added" );
62
    is( $additional_contents->{content}->count, $before_count + 1, "We get the additional one we added" );
63
63
64
    my $expired_additional_content = $builder->build_object(
65
        {
66
            class => 'Koha::AdditionalContents',
67
            value => {
68
                category       => 'news',
69
                location       => 'opac_only',
70
                branchcode     => undef,
71
                expirationdate => '0001-01-01',
72
            }
73
        }
74
    );
75
    $builder->build_object(
76
        {
77
            class => 'Koha::AdditionalContentsLocalizations',
78
            value => {
79
                additional_content_id => $expired_additional_content->id,
80
                lang                  => 'default',
81
            }
82
        }
83
    );
84
    $additional_contents = Koha::Template::Plugin::AdditionalContents->get(
85
        { category => 'news', location => [ 'opac_only', 'staff_and_opac' ], lang => 'default' } );
86
87
    is( $additional_contents->{content}->count, $before_count + 1, "We do not get the expired content" );
88
89
    $additional_contents = Koha::Template::Plugin::AdditionalContents->get(
90
        { category => 'news', location => [ 'opac_only', 'staff_and_opac' ], id => $expired_additional_content->id } );
91
    is( $additional_contents->{content}->count, 1, "We still get expired news through direct link" );
92
64
    $additional_contents = Koha::Template::Plugin::AdditionalContents->get(
93
    $additional_contents = Koha::Template::Plugin::AdditionalContents->get(
65
        {
94
        {
66
            category   => 'news', location => [ 'opac_only', 'staff_and_opac' ], lang => 'default',
95
            category   => 'news', location => [ 'opac_only', 'staff_and_opac' ], lang => 'default',
67
- 

Return to bug 37684