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

(-)a/C4/NewsChannels.pm (-18 / +1 lines)
Lines 30-36 BEGIN { Link Here
30
    @ISA = qw(Exporter);
30
    @ISA = qw(Exporter);
31
    @EXPORT = qw(
31
    @EXPORT = qw(
32
        &GetNewsToDisplay
32
        &GetNewsToDisplay
33
        &add_opac_new &upd_opac_new &del_opac_new &get_opac_new &get_opac_news
33
        &add_opac_new &upd_opac_new &del_opac_new &get_opac_news
34
    );
34
    );
35
}
35
}
36
36
Lines 145-167 sub del_opac_new { Link Here
145
145
146
}
146
}
147
147
148
sub get_opac_new {
149
    my ($idnew) = @_;
150
    my $dbh = C4::Context->dbh;
151
    my $query = q{
152
                  SELECT opac_news.*,branches.branchname
153
                  FROM opac_news LEFT JOIN branches
154
                      ON opac_news.branchcode=branches.branchcode
155
                  WHERE opac_news.idnew = ?;
156
                };
157
    my $sth = $dbh->prepare($query);
158
    $sth->execute($idnew);
159
    my $data = $sth->fetchrow_hashref;
160
    $data->{expirationdate} = output_pref({ dt => dt_from_string( $data->{expirationdate} ), dateonly => 1 }) if ( $data->{expirationdate} );
161
    $data->{published_on} = output_pref({ dt => dt_from_string( $data->{published_on} ), dateonly => 1 });
162
    return $data;
163
}
164
165
sub get_opac_news {
148
sub get_opac_news {
166
    my ($limit, $lang, $branchcode) = @_;
149
    my ($limit, $lang, $branchcode) = @_;
167
    my @values;
150
    my @values;
(-)a/t/db_dependent/NewsChannels.t (-50 / +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-188 $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
my $updated_on = %{get_opac_new($idnew1)}{updated_on};
144
is_deeply(
145
    get_opac_new($idnew1),
146
    {
147
        title          => $title1,
148
        content        => $new1,
149
        lang           => $lang1,
150
        expirationdate => $expirationdate1,
151
        published_on=> $timestamp1,
152
        number         => $number1,
153
        borrowernumber => undef,
154
        idnew          => $idnew1,
155
        branchname     => "$addbra branch",
156
        branchcode     => $addbra,
157
        updated_on     => $updated_on,
158
    },
159
    'got back expected news item via get_opac_new - ID 1'
160
);
161
162
# Test get_opac_new (single news item)
163
$updated_on = %{get_opac_new($idnew2)}{updated_on};
164
is_deeply(
165
    get_opac_new($idnew2),
166
    {  
167
        title          => $title2,
168
        content        => $new2,
169
        lang           => $lang2,
170
        expirationdate => $expirationdate2,
171
        published_on=> $timestamp2,
172
        number         => $number2,
173
        borrowernumber => $brwrnmbr,
174
        idnew          => $idnew2,
175
        branchname     => "$addbra branch",
176
        branchcode     => $addbra,
177
        updated_on     => $updated_on,
178
    },
179
    'got back expected news item via get_opac_new - ID 2'
180
);
181
182
# Test get_opac_new (single news item without expiration date)
183
my $news3 = get_opac_new($idnew3);
184
is($news3->{ expirationdate }, undef, "Expiration date should be empty");
185
186
# Test get_opac_news (multiple news items)
137
# Test get_opac_news (multiple news items)
187
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' );
188
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 = CGI->new;
37
my $cgi = CGI->new;
37
38
Lines 58-64 if( $cgi->param('editmode') ){ Link Here
58
# NULL = All branches.
59
# NULL = All branches.
59
$branchcode = undef if (defined($branchcode) && $branchcode eq '');
60
$branchcode = undef if (defined($branchcode) && $branchcode eq '');
60
61
61
my $new_detail = get_opac_new($id);
62
my $new_detail = Koha::News->find( $id );
62
63
63
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
64
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
64
    {
65
    {
Lines 81-87 foreach my $language ( @$tlangs ) { Link Here
81
        push @lang_list,
82
        push @lang_list,
82
        {
83
        {
83
            language => $sublanguage->{'rfc4646_subtag'},
84
            language => $sublanguage->{'rfc4646_subtag'},
84
            selected => ( $new_detail->{lang} eq $sublanguage->{'rfc4646_subtag'} ? 1 : 0 ),
85
            selected => ( $new_detail && $new_detail->lang eq $sublanguage->{'rfc4646_subtag'} ? 1 : 0 ),
85
        };
86
        };
86
    }
87
    }
87
}
88
}
Lines 94-103 my $op = $cgi->param('op') // ''; Link Here
94
if ( $op eq 'add_form' ) {
95
if ( $op eq 'add_form' ) {
95
    $template->param( add_form => 1 );
96
    $template->param( add_form => 1 );
96
    if ($id) {
97
    if ($id) {
97
        if($new_detail->{lang} eq "slip"){ $template->param( slip => 1); }
98
        if($new_detail->lang eq "slip"){ $template->param( slip => 1); }
98
        $template->param( 
99
        $template->param( 
99
            op => 'edit',
100
            op => 'edit',
100
            id => $new_detail->{'idnew'}
101
            id => $new_detail->idnew
101
        );
102
        );
102
        $template->{VARS}->{'new_detail'} = $new_detail;
103
        $template->{VARS}->{'new_detail'} = $new_detail;
103
    }
104
    }
104
- 

Return to bug 22544