Lines 125-131
sub del_opac_new {
Link Here
|
125 |
sub get_opac_new { |
125 |
sub get_opac_new { |
126 |
my ($idnew) = @_; |
126 |
my ($idnew) = @_; |
127 |
my $dbh = C4::Context->dbh; |
127 |
my $dbh = C4::Context->dbh; |
128 |
my $query = q{ SELECT * FROM opac_news WHERE idnew = ? }; |
128 |
my $query = q{ |
|
|
129 |
SELECT opac_news.*,branches.branchname |
130 |
FROM opac_news LEFT JOIN branches |
131 |
ON opac_news.branchcode=branches.branchcode |
132 |
WHERE opac_news.idnew = ?; |
133 |
}; |
129 |
my $sth = $dbh->prepare($query); |
134 |
my $sth = $dbh->prepare($query); |
130 |
$sth->execute($idnew); |
135 |
$sth->execute($idnew); |
131 |
my $data = $sth->fetchrow_hashref; |
136 |
my $data = $sth->fetchrow_hashref; |
Lines 136-149
sub get_opac_new {
Link Here
|
136 |
} |
141 |
} |
137 |
|
142 |
|
138 |
sub get_opac_news { |
143 |
sub get_opac_news { |
139 |
my ($limit, $lang) = @_; |
144 |
my ($limit, $lang, $branchcode) = @_; |
140 |
my @values; |
145 |
my @values; |
141 |
my $dbh = C4::Context->dbh; |
146 |
my $dbh = C4::Context->dbh; |
142 |
my $query = q{ SELECT *, timestamp AS newdate FROM opac_news }; |
147 |
my $query = q{ |
|
|
148 |
SELECT opac_news.*, branches.branchname, |
149 |
timestamp AS newdate |
150 |
FROM opac_news LEFT JOIN branches |
151 |
ON opac_news.branchcode=branches.branchcode |
152 |
}; |
153 |
$query = ' WHERE 1'; |
143 |
if ($lang) { |
154 |
if ($lang) { |
144 |
$query.= " WHERE (lang='' OR lang=?)"; |
155 |
$query .= " AND (opac_news.lang='' OR opac_news.lang=?)"; |
145 |
push @values,$lang; |
156 |
push @values,$lang; |
146 |
} |
157 |
} |
|
|
158 |
if ($branchcode) { |
159 |
$query .= ' AND (opac_news.branchcode IS NULL OR opac_news.branchcode=?)'; |
160 |
push @values,$branchcode; |
161 |
} |
147 |
$query.= ' ORDER BY timestamp DESC '; |
162 |
$query.= ' ORDER BY timestamp DESC '; |
148 |
#if ($limit) { |
163 |
#if ($limit) { |
149 |
# $query.= 'LIMIT 0, ' . $limit; |
164 |
# $query.= 'LIMIT 0, ' . $limit; |
Lines 163-176
sub get_opac_news {
Link Here
|
163 |
|
178 |
|
164 |
=head2 GetNewsToDisplay |
179 |
=head2 GetNewsToDisplay |
165 |
|
180 |
|
166 |
$news = &GetNewsToDisplay($lang); |
181 |
$news = &GetNewsToDisplay($lang,$branch); |
167 |
C<$news> is a ref to an array which containts |
182 |
C<$news> is a ref to an array which containts |
168 |
all news with expirationdate > today or expirationdate is null. |
183 |
all news with expirationdate > today or expirationdate is null |
|
|
184 |
that is applicable for a given branch. |
169 |
|
185 |
|
170 |
=cut |
186 |
=cut |
171 |
|
187 |
|
172 |
sub GetNewsToDisplay { |
188 |
sub GetNewsToDisplay { |
173 |
my ($lang) = @_; |
189 |
my ($lang,$branch) = @_; |
174 |
my $dbh = C4::Context->dbh; |
190 |
my $dbh = C4::Context->dbh; |
175 |
# SELECT *,DATE_FORMAT(timestamp, '%d/%m/%Y') AS newdate |
191 |
# SELECT *,DATE_FORMAT(timestamp, '%d/%m/%Y') AS newdate |
176 |
my $query = q{ |
192 |
my $query = q{ |
Lines 183-195
sub GetNewsToDisplay {
Link Here
|
183 |
) |
199 |
) |
184 |
AND `timestamp` < CURRENT_DATE()+1 |
200 |
AND `timestamp` < CURRENT_DATE()+1 |
185 |
AND (lang = '' OR lang = ?) |
201 |
AND (lang = '' OR lang = ?) |
|
|
202 |
AND (branchcode IS NULL OR branchcode = ?) |
186 |
ORDER BY number |
203 |
ORDER BY number |
187 |
}; # expirationdate field is NOT in ISO format? |
204 |
}; # expirationdate field is NOT in ISO format? |
188 |
# timestamp has HH:mm:ss, CURRENT_DATE generates 00:00:00 |
205 |
# timestamp has HH:mm:ss, CURRENT_DATE generates 00:00:00 |
189 |
# by adding 1, that captures today correctly. |
206 |
# by adding 1, that captures today correctly. |
190 |
my $sth = $dbh->prepare($query); |
207 |
my $sth = $dbh->prepare($query); |
191 |
$lang = $lang // q{}; |
208 |
$lang = $lang // q{}; |
192 |
$sth->execute($lang); |
209 |
$sth->execute($lang,$branch); |
193 |
my @results; |
210 |
my @results; |
194 |
while ( my $row = $sth->fetchrow_hashref ){ |
211 |
while ( my $row = $sth->fetchrow_hashref ){ |
195 |
$row->{newdate} = format_date($row->{newdate}); |
212 |
$row->{newdate} = format_date($row->{newdate}); |