|
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{ |
| 143 |
if ($lang) { |
148 |
SELECT opac_news.*, branches.branchname, |
| 144 |
$query.= " WHERE (lang='' OR lang=?)"; |
149 |
timestamp AS newdate |
|
|
150 |
FROM opac_news LEFT JOIN branches |
| 151 |
ON opac_news.branchcode=branches.branchcode |
| 152 |
}; |
| 153 |
if ($lang && $branchcode) { |
| 154 |
$query .= " WHERE (opac_news.lang='' OR opac_news.lang=?)"; |
| 155 |
$query .= " AND (opac_news.branchcode IS NULL OR opac_news.branchcode=?)"; |
| 156 |
push @values,$lang; |
| 157 |
push @values,$branchcode; |
| 158 |
} |
| 159 |
elsif ($lang) { |
| 160 |
$query .= " WHERE (opac_news.lang='' OR opac_news.lang=?)"; |
| 145 |
push @values,$lang; |
161 |
push @values,$lang; |
| 146 |
} |
162 |
} |
|
|
163 |
elsif ($branchcode) { |
| 164 |
$query .= " WHERE (opac_news.branchcode IS NULL OR opac_news.branchcode=?)"; |
| 165 |
push @values,$branchcode; |
| 166 |
} |
| 167 |
else { |
| 168 |
# nothing |
| 169 |
} |
| 147 |
$query.= ' ORDER BY timestamp DESC '; |
170 |
$query.= ' ORDER BY timestamp DESC '; |
| 148 |
#if ($limit) { |
171 |
#if ($limit) { |
| 149 |
# $query.= 'LIMIT 0, ' . $limit; |
172 |
# $query.= 'LIMIT 0, ' . $limit; |
|
Lines 165-178
sub get_opac_news {
Link Here
|
| 165 |
|
188 |
|
| 166 |
=head2 GetNewsToDisplay |
189 |
=head2 GetNewsToDisplay |
| 167 |
|
190 |
|
| 168 |
$news = &GetNewsToDisplay($lang); |
191 |
$news = &GetNewsToDisplay($lang,$branch); |
| 169 |
C<$news> is a ref to an array which containts |
192 |
C<$news> is a ref to an array which containts |
| 170 |
all news with expirationdate > today or expirationdate is null. |
193 |
all news with expirationdate > today or expirationdate is null |
|
|
194 |
that is applicable for a given branch. |
| 171 |
|
195 |
|
| 172 |
=cut |
196 |
=cut |
| 173 |
|
197 |
|
| 174 |
sub GetNewsToDisplay { |
198 |
sub GetNewsToDisplay { |
| 175 |
my ($lang) = @_; |
199 |
my ($lang,$branch) = @_; |
| 176 |
my $dbh = C4::Context->dbh; |
200 |
my $dbh = C4::Context->dbh; |
| 177 |
# SELECT *,DATE_FORMAT(timestamp, '%d/%m/%Y') AS newdate |
201 |
# SELECT *,DATE_FORMAT(timestamp, '%d/%m/%Y') AS newdate |
| 178 |
my $query = q{ |
202 |
my $query = q{ |
|
Lines 185-197
sub GetNewsToDisplay {
Link Here
|
| 185 |
) |
209 |
) |
| 186 |
AND `timestamp` < CURRENT_DATE()+1 |
210 |
AND `timestamp` < CURRENT_DATE()+1 |
| 187 |
AND (lang = '' OR lang = ?) |
211 |
AND (lang = '' OR lang = ?) |
|
|
212 |
AND (branchcode IS NULL OR branchcode = ?) |
| 188 |
ORDER BY number |
213 |
ORDER BY number |
| 189 |
}; # expirationdate field is NOT in ISO format? |
214 |
}; # expirationdate field is NOT in ISO format? |
| 190 |
# timestamp has HH:mm:ss, CURRENT_DATE generates 00:00:00 |
215 |
# timestamp has HH:mm:ss, CURRENT_DATE generates 00:00:00 |
| 191 |
# by adding 1, that captures today correctly. |
216 |
# by adding 1, that captures today correctly. |
| 192 |
my $sth = $dbh->prepare($query); |
217 |
my $sth = $dbh->prepare($query); |
| 193 |
$lang = $lang // q{}; |
218 |
$lang = $lang // q{}; |
| 194 |
$sth->execute($lang); |
219 |
$sth->execute($lang,$branch); |
| 195 |
my @results; |
220 |
my @results; |
| 196 |
while ( my $row = $sth->fetchrow_hashref ){ |
221 |
while ( my $row = $sth->fetchrow_hashref ){ |
| 197 |
$row->{newdate} = format_date($row->{newdate}); |
222 |
$row->{newdate} = format_date($row->{newdate}); |