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

(-)a/C4/NewsChannels.pm (-18 / +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 123-145 sub del_opac_new { Link Here
123
    }
123
    }
124
}
124
}
125
125
126
sub get_opac_new {
127
    my ($idnew) = @_;
128
    my $dbh = C4::Context->dbh;
129
    my $query = q{
130
                  SELECT opac_news.*,branches.branchname
131
                  FROM opac_news LEFT JOIN branches
132
                      ON opac_news.branchcode=branches.branchcode
133
                  WHERE opac_news.idnew = ?;
134
                };
135
    my $sth = $dbh->prepare($query);
136
    $sth->execute($idnew);
137
    my $data = $sth->fetchrow_hashref;
138
    $data->{expirationdate} = output_pref({ dt => dt_from_string( $data->{expirationdate} ), dateonly => 1 }) if ( $data->{expirationdate} );
139
    $data->{published_on} = output_pref({ dt => dt_from_string( $data->{published_on} ), dateonly => 1 });
140
    return $data;
141
}
142
143
sub get_opac_news {
126
sub get_opac_news {
144
    my ($limit, $lang, $branchcode) = @_;
127
    my ($limit, $lang, $branchcode) = @_;
145
    my @values;
128
    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 82-88 foreach my $language ( @$tlangs ) { Link Here
82
        push @lang_list,
83
        push @lang_list,
83
        {
84
        {
84
            language => $sublanguage->{'rfc4646_subtag'},
85
            language => $sublanguage->{'rfc4646_subtag'},
85
            selected => ( $new_detail->{lang} eq $sublanguage->{'rfc4646_subtag'} ? 1 : 0 ),
86
            selected => ( $new_detail && $new_detail->lang eq $sublanguage->{'rfc4646_subtag'} ? 1 : 0 ),
86
        };
87
        };
87
    }
88
    }
88
}
89
}
Lines 95-104 my $op = $cgi->param('op') // ''; Link Here
95
if ( $op eq 'add_form' ) {
96
if ( $op eq 'add_form' ) {
96
    $template->param( add_form => 1 );
97
    $template->param( add_form => 1 );
97
    if ($id) {
98
    if ($id) {
98
        if($new_detail->{lang} eq "slip"){ $template->param( slip => 1); }
99
        if($new_detail->lang eq "slip"){ $template->param( slip => 1); }
99
        $template->param( 
100
        $template->param( 
100
            op => 'edit',
101
            op => 'edit',
101
            id => $new_detail->{'idnew'}
102
            id => $new_detail->idnew
102
        );
103
        );
103
        $template->{VARS}->{'new_detail'} = $new_detail;
104
        $template->{VARS}->{'new_detail'} = $new_detail;
104
    }
105
    }
105
- 

Return to bug 22544