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

(-)a/C4/NewsChannels.pm (-40 / +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
31
        &add_opac_new
32
    );
32
    );
33
}
33
}
34
34
Lines 72-116 sub add_opac_new { Link Here
72
    return $retval;
72
    return $retval;
73
}
73
}
74
74
75
=head2 upd_opac_new
76
77
    $retval = upd_opac_new($hashref);
78
79
    $hashref should contains all the fields found in opac_news,
80
    including idnew, since it is the key for the SQL UPDATE.
81
82
=cut
83
84
sub upd_opac_new {
85
    my ($href_entry) = @_;
86
    my $retval = 0;
87
88
    if ($href_entry) {
89
        $href_entry->{number} = 0 if $href_entry->{number} !~ /^\d+$/;
90
        # take the keys of hash entry and make a list, but...
91
        my @fields = keys %{$href_entry};
92
        my @values;
93
        $#values = -1;
94
        my $field_string = q{};
95
        foreach my $field_name (@fields) {
96
            # exclude idnew
97
            if ( $field_name ne 'idnew' ) {
98
                $field_string = $field_string . "$field_name = ?,";
99
                push @values,$href_entry->{$field_name};
100
            }
101
        }
102
        # put idnew at the end, so we know which record to update
103
        push @values,$href_entry->{'idnew'};
104
        chop $field_string; # remove that excess ,
105
106
        my $dbh = C4::Context->dbh;
107
        my $sth = $dbh->prepare("UPDATE opac_news SET $field_string WHERE idnew = ?;");
108
        $sth->execute(@values);
109
        $retval = 1;
110
    }
111
    return $retval;
112
}
113
114
=head2 GetNewsToDisplay
75
=head2 GetNewsToDisplay
115
76
116
    $news = &GetNewsToDisplay($lang,$branch);
77
    $news = &GetNewsToDisplay($lang,$branch);
(-)a/t/db_dependent/NewsChannels.t (-11 / +1 lines)
Lines 6-12 use Koha::DateUtils; Link Here
6
use Koha::Libraries;
6
use Koha::Libraries;
7
use Koha::News;
7
use Koha::News;
8
8
9
use Test::More tests => 9;
9
use Test::More tests => 7;
10
10
11
BEGIN {
11
BEGIN {
12
    use_ok('C4::NewsChannels');
12
    use_ok('C4::NewsChannels');
Lines 125-140 $query = Link Here
125
q{ SELECT idnew from opac_news WHERE published_on='2000-01-02'; };
125
q{ SELECT idnew from opac_news WHERE published_on='2000-01-02'; };
126
my ( $idnew3 ) = $dbh->selectrow_array( $query );
126
my ( $idnew3 ) = $dbh->selectrow_array( $query );
127
127
128
# Test upd_opac_new
129
$rv = upd_opac_new();    # intentionally bad parmeters
130
is( $rv, 0, 'Correctly failed on no parameter!' );
131
132
$new2                 = '<p>Update! There is no news!</p>';
133
$href_entry2->{content}   = $new2;
134
$href_entry2->{idnew} = $idnew2;
135
$rv                   = upd_opac_new($href_entry2);
136
is( $rv, 1, 'Successfully updated second dummy news item!' );
137
138
# Test GetNewsToDisplay
128
# Test GetNewsToDisplay
139
my ( $opac_news_count, $arrayref_opac_news ) = GetNewsToDisplay( q{}, 'LIB1' );
129
my ( $opac_news_count, $arrayref_opac_news ) = GetNewsToDisplay( q{}, 'LIB1' );
140
ok( $opac_news_count >= 2, 'Successfully tested GetNewsToDisplay for LIB1!' );
130
ok( $opac_news_count >= 2, 'Successfully tested GetNewsToDisplay for LIB1!' );
(-)a/tools/koha-news.pl (-6 / +5 lines)
Lines 128-136 elsif ( $op eq 'add' ) { Link Here
128
    }
128
    }
129
}
129
}
130
elsif ( $op eq 'edit' ) {
130
elsif ( $op eq 'edit' ) {
131
    upd_opac_new(
131
    my $news_item = Koha::News->find( $id );
132
        {
132
    if ( $news_item ) {
133
            idnew          => $id,
133
        $news_item->set({
134
            title          => $title,
134
            title          => $title,
135
            content        => $content,
135
            content        => $content,
136
            lang           => $lang,
136
            lang           => $lang,
Lines 138-145 elsif ( $op eq 'edit' ) { Link Here
138
            published_on=> $published_on,
138
            published_on=> $published_on,
139
            number         => $number,
139
            number         => $number,
140
            branchcode     => $branchcode,
140
            branchcode     => $branchcode,
141
        }
141
        })->store;
142
    );
142
    }
143
    print $cgi->redirect("/cgi-bin/koha/tools/koha-news.pl");
143
    print $cgi->redirect("/cgi-bin/koha/tools/koha-news.pl");
144
}
144
}
145
elsif ( $op eq 'del' ) {
145
elsif ( $op eq 'del' ) {
146
- 

Return to bug 22544