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

(-)a/Koha/AdditionalContents.pm (-7 / +8 lines)
Lines 81-93 sub search_for_display { Link Here
81
        qq|(SELECT COUNT(*) FROM additional_contents_localizations WHERE lang='$lang' AND additional_content_id=me.additional_content_id)=0|;
81
        qq|(SELECT COUNT(*) FROM additional_contents_localizations WHERE lang='$lang' AND additional_content_id=me.additional_content_id)=0|;
82
82
83
    my $search_params;
83
    my $search_params;
84
    $search_params->{location}       = $params->{location};
84
    $search_params->{'additional_content.id'} = $params->{id} if $params->{id};
85
    $search_params->{branchcode}     = $params->{library_id} ? [ $params->{library_id}, undef ] : undef;
85
    $search_params->{location}                = $params->{location};
86
    $search_params->{published_on}   = { '<=' => \'CAST(NOW() AS DATE)' };
86
    $search_params->{branchcode}              = $params->{library_id} ? [ $params->{library_id}, undef ] : undef;
87
    $search_params->{expirationdate} = [ '-or', { '>=' => \'CAST(NOW() AS DATE)' }, undef ];
87
    $search_params->{published_on}            = { '<=' => \'CAST(NOW() AS DATE)' };
88
    $search_params->{category}       = $params->{category} if $params->{category};
88
    $search_params->{expirationdate}          = [ '-or', { '>=' => \'CAST(NOW() AS DATE)' }, undef ];
89
    $search_params->{lang}           = 'default' if !$lang || $lang eq 'default';
89
    $search_params->{category}                = $params->{category} if $params->{category};
90
    $search_params->{-or}            = [ { 'lang' => $lang }, '-and' => [ 'lang', 'default', \$subquery ] ]
90
    $search_params->{lang}                    = 'default' if !$lang || $lang eq 'default';
91
    $search_params->{-or}                     = [ { 'lang' => $lang }, '-and' => [ 'lang', 'default', \$subquery ] ]
91
        if !$search_params->{lang};
92
        if !$search_params->{lang};
92
93
93
    my $attribs = { prefetch => 'additional_content', order_by => 'additional_content.number' };
94
    my $attribs = { prefetch => 'additional_content', order_by => 'additional_content.number' };
(-)a/Koha/Template/Plugin/AdditionalContents.pm (-3 / +4 lines)
Lines 40-49 sub get { Link Here
40
40
41
    my $content = Koha::AdditionalContents->search_for_display(
41
    my $content = Koha::AdditionalContents->search_for_display(
42
        {
42
        {
43
            category   => $category,
43
            category => $category,
44
            location   => $location,
44
            location => $location,
45
            lang       => $lang,
45
            lang     => $lang,
46
            ( $library ? ( library_id => $library ) : () ),
46
            ( $library ? ( library_id => $library ) : () ),
47
            ( $id      ? ( id         => $id )      : () ),
47
        }
48
        }
48
    );
49
    );
49
50
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt (-1 / +1 lines)
Lines 89-95 Link Here
89
        [% END %]
89
        [% END %]
90
90
91
        [% IF news_id %]
91
        [% IF news_id %]
92
            [% SET koha_news = AdditionalContents.get( category => 'news', location => ['opac_only', 'staff_and_opac'], lang => lang, news_id => news_id ) %]
92
            [% SET koha_news = AdditionalContents.get( category => 'news', location => ['opac_only', 'staff_and_opac'], lang => lang, id => news_id ) %]
93
        [% ELSE %]
93
        [% ELSE %]
94
            [% SET koha_news = AdditionalContents.get( category => 'news', location => ['opac_only', 'staff_and_opac'], lang => lang, library => branchcode ) %]
94
            [% SET koha_news = AdditionalContents.get( category => 'news', location => ['opac_only', 'staff_and_opac'], lang => lang, library => branchcode ) %]
95
        [% END %]
95
        [% END %]
(-)a/t/db_dependent/Template/Plugin/AdditionalContents.t (-15 / +38 lines)
Lines 33-50 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 => 2;
36
    plan tests => 4;
37
37
38
    my $additional_contents = Koha::Template::Plugin::AdditionalContents->get({ category => 'news', location => ['opac_only', 'staff_and_opac'], lang => 'default', library => '%' });
38
    my $additional_contents = Koha::Template::Plugin::AdditionalContents->get(
39
    my $before_count = $additional_contents ? $additional_contents->{content}->count() : 0;
39
        { category => 'news', location => [ 'opac_only', 'staff_and_opac' ], lang => 'default', library => '%' } );
40
    my $additional_content = $builder->build_object({
40
    my $before_count       = $additional_contents ? $additional_contents->{content}->count() : 0;
41
        class => 'Koha::AdditionalContents',
41
    my $additional_content = $builder->build_object(
42
        value => {
42
        {
43
            category   => 'news',
43
            class => 'Koha::AdditionalContents',
44
            location   => 'opac_only',
44
            value => {
45
            branchcode => undef
45
                category   => 'news',
46
                location   => 'opac_only',
47
                branchcode => undef
48
            }
46
        }
49
        }
47
    });
50
    );
48
    $builder->build_object(
51
    $builder->build_object(
49
        {
52
        {
50
            class => 'Koha::AdditionalContentsLocalizations',
53
            class => 'Koha::AdditionalContentsLocalizations',
Lines 54-66 subtest 'get' => sub { Link Here
54
            }
57
            }
55
        }
58
        }
56
    );
59
    );
57
    $additional_contents = Koha::Template::Plugin::AdditionalContents->get({ category => 'news', location => ['opac_only', 'staff_and_opac'], lang => 'default' });
60
    $additional_contents = Koha::Template::Plugin::AdditionalContents->get(
58
    is( $additional_contents->{content}->count, $before_count + 1, "We get the additional one we added");
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" );
63
64
    $additional_contents = Koha::Template::Plugin::AdditionalContents->get(
65
        {
66
            category   => 'news', location => [ 'opac_only', 'staff_and_opac' ], lang => 'default',
67
            blocktitle => 'blockhead'
68
        }
69
    );
59
70
60
    $additional_contents = Koha::Template::Plugin::AdditionalContents->get({ category => 'news', location => ['opac_only', 'staff_and_opac'], lang => 'default', blocktitle => 'blockhead' });
71
    is( $additional_contents->{blocktitle}, 'blockhead', "Block title is passed through" );
61
72
62
    is( $additional_contents->{blocktitle}, 'blockhead', "Block title is passed through");
73
    $additional_contents = Koha::Template::Plugin::AdditionalContents->get(
74
        {
75
            id   => $additional_content->id, category => 'news', location => [ 'opac_only', 'staff_and_opac' ],
76
            lang => 'default'
77
        }
78
    );
79
    is( $additional_contents->{content}->count, 1 );
63
80
81
    $additional_contents = Koha::Template::Plugin::AdditionalContents->get(
82
        {
83
            id       => $additional_content->id,           category => 'html_customizations',
84
            location => [ 'opac_only', 'staff_and_opac' ], lang     => 'default'
85
        }
86
    );
87
    is( $additional_contents, undef );
64
88
65
};
89
};
66
90
67
- 

Return to bug 31383