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

(-)a/C4/NewsChannels.pm (-19 / +1 lines)
Lines 28-34 BEGIN { Link Here
28
    @ISA = qw(Exporter);
28
    @ISA = qw(Exporter);
29
    @EXPORT = qw(
29
    @EXPORT = qw(
30
        &GetNewsToDisplay
30
        &GetNewsToDisplay
31
        &add_opac_new &upd_opac_new &del_opac_new &get_opac_new &get_opac_news
31
        &add_opac_new &upd_opac_new &del_opac_new &get_opac_news
32
    );
32
    );
33
}
33
}
34
34
Lines 121-144 sub del_opac_new { Link Here
121
    }
121
    }
122
}
122
}
123
123
124
sub get_opac_new {
125
    my ($idnew) = @_;
126
    my $dbh = C4::Context->dbh;
127
    my $query = q{
128
                  SELECT opac_news.*,branches.branchname
129
                  FROM opac_news LEFT JOIN branches
130
                      ON opac_news.branchcode=branches.branchcode
131
                  WHERE opac_news.idnew = ?;
132
                };
133
    my $sth = $dbh->prepare($query);
134
    $sth->execute($idnew);
135
    my $data = $sth->fetchrow_hashref;
136
    $data->{$data->{'lang'}} = 1 if defined $data->{lang};
137
    $data->{expirationdate} = output_pref({ dt => dt_from_string( $data->{expirationdate} ), dateonly => 1 }) if ( $data->{expirationdate} );
138
    $data->{timestamp}      = output_pref({ dt => dt_from_string( $data->{timestamp} ), dateonly => 1 }) ;
139
    return $data;
140
}
141
142
sub get_opac_news {
124
sub get_opac_news {
143
    my ($limit, $lang, $branchcode) = @_;
125
    my ($limit, $lang, $branchcode) = @_;
144
    my @values;
126
    my @values;
(-)a/t/db_dependent/NewsChannels.t (-52 / +1 lines)
Lines 5-11 use Koha::Database; Link Here
5
use Koha::DateUtils;
5
use Koha::DateUtils;
6
use Koha::Libraries;
6
use Koha::Libraries;
7
7
8
use Test::More tests => 14;
8
use Test::More tests => 11;
9
9
10
BEGIN {
10
BEGIN {
11
    use_ok('C4::NewsChannels');
11
    use_ok('C4::NewsChannels');
Lines 134-190 $href_entry2->{idnew} = $idnew2; Link Here
134
$rv                   = upd_opac_new($href_entry2);
134
$rv                   = upd_opac_new($href_entry2);
135
is( $rv, 1, 'Successfully updated second dummy news item!' );
135
is( $rv, 1, 'Successfully updated second dummy news item!' );
136
136
137
# Test get_opac_new (single news item)
138
$timestamp1      = output_pref( { dt => dt_from_string( $timestamp1 ), dateonly => 1 } );
139
$expirationdate1 = output_pref( { dt => dt_from_string( $expirationdate1 ), dateonly => 1 } );
140
$timestamp2      = output_pref( { dt => dt_from_string( $timestamp2 ), dateonly => 1 } );
141
$expirationdate2 = output_pref( { dt => dt_from_string( $expirationdate2) , dateonly => 1 } );
142
143
is_deeply(
144
    get_opac_new($idnew1),
145
    {
146
        title          => $title1,
147
        content        => $new1,
148
        lang           => $lang1,
149
        expirationdate => $expirationdate1,
150
        timestamp      => $timestamp1,
151
        number         => $number1,
152
        borrowernumber => undef,
153
        idnew          => $idnew1,
154
        branchname     => "$addbra branch",
155
        branchcode     => $addbra,
156
        # this represents $lang => 1 in the hash
157
        # that's returned... which seems a little
158
        # redundant given that there's a perfectly
159
        # good 'lang' key in the hash
160
        ''             => 1,
161
    },
162
    'got back expected news item via get_opac_new - ID 1'
163
);
164
165
# Test get_opac_new (single news item)
166
is_deeply(
167
    get_opac_new($idnew2),
168
    {  
169
        title          => $title2,
170
        content        => $new2,
171
        lang           => $lang2,
172
        expirationdate => $expirationdate2,
173
        timestamp      => $timestamp2,
174
        number         => $number2,
175
        borrowernumber => $brwrnmbr,
176
        idnew          => $idnew2,
177
        branchname     => "$addbra branch",
178
        branchcode     => $addbra,
179
        ''             => 1,
180
    },
181
    'got back expected news item via get_opac_new - ID 2'
182
);
183
184
# Test get_opac_new (single news item without expiration date)
185
my $news3 = get_opac_new($idnew3);
186
is($news3->{ expirationdate }, undef, "Expiration date should be empty");
187
188
# Test get_opac_news (multiple news items)
137
# Test get_opac_news (multiple news items)
189
my ( $opac_news_count, $arrayref_opac_news ) = get_opac_news( 0, q{}, 'LIB1' );
138
my ( $opac_news_count, $arrayref_opac_news ) = get_opac_news( 0, q{}, 'LIB1' );
190
139
(-)a/tools/koha-news.pl (-5 / +5 lines)
Lines 32-37 use C4::NewsChannels; Link Here
32
use C4::Languages qw(getTranslatedLanguages);
32
use C4::Languages qw(getTranslatedLanguages);
33
use Date::Calc qw/Date_to_Days Today/;
33
use Date::Calc qw/Date_to_Days Today/;
34
use Koha::DateUtils;
34
use Koha::DateUtils;
35
use Koha::News;
35
36
36
my $cgi = new CGI;
37
my $cgi = new CGI;
37
38
Lines 52-58 my $error_message = $cgi->param('error_message'); Link Here
52
# NULL = All branches.
53
# NULL = All branches.
53
$branchcode = undef if (defined($branchcode) && $branchcode eq '');
54
$branchcode = undef if (defined($branchcode) && $branchcode eq '');
54
55
55
my $new_detail = get_opac_new($id);
56
my $new_detail = Koha::News->find( $id );
56
57
57
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
58
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
58
    {
59
    {
Lines 77-83 foreach my $language ( @$tlangs ) { Link Here
77
        push @lang_list,
78
        push @lang_list,
78
        {
79
        {
79
            language => $sublanguage->{'rfc4646_subtag'},
80
            language => $sublanguage->{'rfc4646_subtag'},
80
            selected => ( $new_detail->{lang} eq $sublanguage->{'rfc4646_subtag'} ? 1 : 0 ),
81
            selected => ( $new_detail && $new_detail->lang eq $sublanguage->{'rfc4646_subtag'} ? 1 : 0 ),
81
        };
82
        };
82
    }
83
    }
83
}
84
}
Lines 90-99 my $op = $cgi->param('op') // ''; Link Here
90
if ( $op eq 'add_form' ) {
91
if ( $op eq 'add_form' ) {
91
    $template->param( add_form => 1 );
92
    $template->param( add_form => 1 );
92
    if ($id) {
93
    if ($id) {
93
        if($new_detail->{lang} eq "slip"){ $template->param( slip => 1); }
94
        if($new_detail->lang eq "slip"){ $template->param( slip => 1); }
94
        $template->param( 
95
        $template->param( 
95
            op => 'edit',
96
            op => 'edit',
96
            id => $new_detail->{'idnew'}
97
            id => $new_detail->idnew
97
        );
98
        );
98
        $template->{VARS}->{'new_detail'} = $new_detail;
99
        $template->{VARS}->{'new_detail'} = $new_detail;
99
    }
100
    }
100
- 

Return to bug 22544