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

(-)a/Koha/Template/Plugin/AdditionalContents.pm (-21 / +2 lines)
Lines 36-48 sub get { Link Here
36
    my $blocktitle = $params->{blocktitle};
36
    my $blocktitle = $params->{blocktitle};
37
    my $lang       = $params->{lang} || 'default';
37
    my $lang       = $params->{lang} || 'default';
38
    my $library    = $params->{library};
38
    my $library    = $params->{library};
39
    my $id         = $params->{id};
39
40
40
    my $content = Koha::AdditionalContents->search_for_display(
41
    my $content = Koha::AdditionalContents->search_for_display(
41
        {
42
        {
42
            category   => $category,
43
            category   => $category,
43
            location   => $location,
44
            location   => $location,
44
            lang       => $lang,
45
            lang       => $lang,
45
            library_id => $library,
46
            ( $library ? ( library_id => $library ) : () ),
46
        }
47
        }
47
    );
48
    );
48
49
Lines 56-81 sub get { Link Here
56
    return;
57
    return;
57
}
58
}
58
59
59
sub get_opac_news_by_id {
60
    my ( $self, $params ) = @_;
61
62
    my $news_id   = $params->{news_id};
63
64
    my $content = Koha::AdditionalContents->search(
65
        {
66
            location   => ['opac_only', 'staff_and_opac'],
67
            idnew => $news_id,
68
            category => 'news',
69
        }
70
    );
71
72
    if ( $content->count ) {
73
        return {
74
            content    => $content,
75
        };
76
    }
77
}
78
79
1;
60
1;
80
61
81
=head1 NAME
62
=head1 NAME
(-)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_opac_news_by_id( news_id => news_id ) %]
92
            [% SET koha_news = AdditionalContents.get( category => 'news', location => ['opac_only', 'staff_and_opac'], lang => lang, news_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 (-35 / +11 lines)
Lines 16-22 Link Here
16
16
17
use Modern::Perl;
17
use Modern::Perl;
18
18
19
use Test::More tests => 2;
19
use Test::More tests => 1;
20
20
21
use C4::Context;
21
use C4::Context;
22
use Koha::Caches;
22
use Koha::Caches;
Lines 37-51 subtest 'get' => sub { Link Here
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({ category => 'news', location => ['opac_only', 'staff_and_opac'], lang => 'default', library => '%' });
39
    my $before_count = $additional_contents ? $additional_contents->{content}->count() : 0;
39
    my $before_count = $additional_contents ? $additional_contents->{content}->count() : 0;
40
    $builder->build_object({
40
    my $additional_content = $builder->build_object({
41
        class => 'Koha::AdditionalContents',
41
        class => 'Koha::AdditionalContents',
42
        value => {
42
        value => {
43
            category   => 'news',
43
            category   => 'news',
44
            location   => 'opac_only',
44
            location   => 'opac_only',
45
            lang       => 'default',
46
            branchcode => undef
45
            branchcode => undef
47
        }
46
        }
48
    });
47
    });
48
    $builder->build_object(
49
        {
50
            class => 'Koha::AdditionalContentsLocalizations',
51
            value => {
52
                additional_content_id => $additional_content->id,
53
                lang                  => 'default',
54
            }
55
        }
56
    );
49
    $additional_contents = Koha::Template::Plugin::AdditionalContents->get({ category => 'news', location => ['opac_only', 'staff_and_opac'], lang => 'default' });
57
    $additional_contents = Koha::Template::Plugin::AdditionalContents->get({ category => 'news', location => ['opac_only', 'staff_and_opac'], lang => 'default' });
50
    is( $additional_contents->{content}->count, $before_count + 1, "We get the additional one we added");
58
    is( $additional_contents->{content}->count, $before_count + 1, "We get the additional one we added");
51
59
Lines 54-90 subtest 'get' => sub { Link Here
54
    is( $additional_contents->{blocktitle}, 'blockhead', "Block title is passed through");
62
    is( $additional_contents->{blocktitle}, 'blockhead', "Block title is passed through");
55
63
56
64
57
};
58
59
subtest 'get_opac_news_by_id' => sub {
60
61
    plan tests => 4;
62
63
    my $news_item = $builder->build_object({
64
        class => 'Koha::AdditionalContents',
65
        value => {
66
            category => 'news',
67
            location => 'opac_only'
68
        }
69
    });
70
71
   my $fetched_news = Koha::Template::Plugin::AdditionalContents->get_opac_news_by_id({ news_id => $news_item->id });
72
   is( $fetched_news->{content}->next->content, $news_item->content, "Correct news fetched for opac location" );
73
74
   $news_item->location('staff_and_opac')->store();
75
   $fetched_news = Koha::Template::Plugin::AdditionalContents->get_opac_news_by_id({ news_id => $news_item->id });
76
   is( $fetched_news->{content}->next->content, $news_item->content, "Correct news fetched for oac and staff location" );
77
78
   $news_item->location('staff_only')->store();
79
   $fetched_news = Koha::Template::Plugin::AdditionalContents->get_opac_news_by_id({ news_id => $news_item->id });
80
   is( $fetched_news, 0, "News item not fetched when location is staff_only" );
81
82
   $news_item->location('opac_only')->category('HtmlCustomizations')->store();
83
   $fetched_news = Koha::Template::Plugin::AdditionalContents->get_opac_news_by_id({ news_id => $news_item->id });
84
   is( $fetched_news, 0, "News not fetched from a different category" );
85
86
87
88
};
65
};
89
66
90
$schema->storage->txn_rollback;
67
$schema->storage->txn_rollback;
91
- 

Return to bug 31383