Lines 266-289
sub DelLetter {
Link Here
|
266 |
, undef, $branchcode, $module, $code, ( $mtt ? $mtt : () ), ( $lang ? $lang : () ) ); |
266 |
, undef, $branchcode, $module, $code, ( $mtt ? $mtt : () ), ( $lang ? $lang : () ) ); |
267 |
} |
267 |
} |
268 |
|
268 |
|
269 |
=head2 addalert ($borrowernumber, $type, $externalid) |
269 |
=head2 addalert ($borrowernumber, $subscriptionid) |
270 |
|
270 |
|
271 |
parameters : |
271 |
parameters : |
272 |
- $borrowernumber : the number of the borrower subscribing to the alert |
272 |
- $borrowernumber : the number of the borrower subscribing to the alert |
273 |
- $type : the type of alert. |
273 |
- $subscriptionid |
274 |
- $externalid : the primary key of the object to put alert on. For issues, the alert is made on subscriptionid. |
274 |
|
275 |
|
|
|
276 |
create an alert and return the alertid (primary key) |
275 |
create an alert and return the alertid (primary key) |
277 |
|
276 |
|
278 |
=cut |
277 |
=cut |
279 |
|
278 |
|
280 |
sub addalert { |
279 |
sub addalert { |
281 |
my ( $borrowernumber, $type, $externalid ) = @_; |
280 |
my ( $borrowernumber, $subscriptionid) = @_; |
282 |
my $dbh = C4::Context->dbh; |
281 |
my $dbh = C4::Context->dbh; |
283 |
my $sth = |
282 |
my $sth = |
284 |
$dbh->prepare( |
283 |
$dbh->prepare( |
285 |
"insert into alert (borrowernumber, type, externalid) values (?,?,?)"); |
284 |
"insert into alert (borrowernumber, externalid) values (?,?)"); |
286 |
$sth->execute( $borrowernumber, $type, $externalid ); |
285 |
$sth->execute( $borrowernumber, $subscriptionid ); |
287 |
|
286 |
|
288 |
# get the alert number newly created and return it |
287 |
# get the alert number newly created and return it |
289 |
my $alertid = $dbh->{'mysql_insertid'}; |
288 |
my $alertid = $dbh->{'mysql_insertid'}; |
Lines 305-322
sub delalert {
Link Here
|
305 |
$sth->execute($alertid); |
304 |
$sth->execute($alertid); |
306 |
} |
305 |
} |
307 |
|
306 |
|
308 |
=head2 getalert ([$borrowernumber], [$type], [$externalid]) |
307 |
=head2 getalert ([$borrowernumber], [$subscriptionid]) |
309 |
|
308 |
|
310 |
parameters : |
309 |
parameters : |
311 |
- $borrowernumber : the number of the borrower subscribing to the alert |
310 |
- $borrowernumber : the number of the borrower subscribing to the alert |
312 |
- $type : the type of alert. |
311 |
- $subscriptionid |
313 |
- $externalid : the primary key of the object to put alert on. For issues, the alert is made on subscriptionid. |
312 |
all parameters NON mandatory. If a parameter is omitted, the query is done without the corresponding parameter. For example, without $subscriptionid, returns all alerts for a borrower on a topic. |
314 |
all parameters NON mandatory. If a parameter is omitted, the query is done without the corresponding parameter. For example, without $externalid, returns all alerts for a borrower on a topic. |
|
|
315 |
|
313 |
|
316 |
=cut |
314 |
=cut |
317 |
|
315 |
|
318 |
sub getalert { |
316 |
sub getalert { |
319 |
my ( $borrowernumber, $type, $externalid ) = @_; |
317 |
my ( $borrowernumber, $subscriptionid ) = @_; |
320 |
my $dbh = C4::Context->dbh; |
318 |
my $dbh = C4::Context->dbh; |
321 |
my $query = "SELECT a.*, b.branchcode FROM alert a JOIN borrowers b USING(borrowernumber) WHERE 1"; |
319 |
my $query = "SELECT a.*, b.branchcode FROM alert a JOIN borrowers b USING(borrowernumber) WHERE 1"; |
322 |
my @bind; |
320 |
my @bind; |
Lines 324-336
sub getalert {
Link Here
|
324 |
$query .= " AND borrowernumber=?"; |
322 |
$query .= " AND borrowernumber=?"; |
325 |
push @bind, $borrowernumber; |
323 |
push @bind, $borrowernumber; |
326 |
} |
324 |
} |
327 |
if ($type) { |
325 |
if ($subscriptionid) { |
328 |
$query .= " AND type=?"; |
|
|
329 |
push @bind, $type; |
330 |
} |
331 |
if ($externalid) { |
332 |
$query .= " AND externalid=?"; |
326 |
$query .= " AND externalid=?"; |
333 |
push @bind, $externalid; |
327 |
push @bind, $subscriptionid; |
334 |
} |
328 |
} |
335 |
my $sth = $dbh->prepare($query); |
329 |
my $sth = $dbh->prepare($query); |
336 |
$sth->execute(@bind); |
330 |
$sth->execute(@bind); |
Lines 386-392
sub SendAlerts {
Link Here
|
386 |
|
380 |
|
387 |
my %letter; |
381 |
my %letter; |
388 |
# find the list of borrowers to alert |
382 |
# find the list of borrowers to alert |
389 |
my $alerts = getalert( '', 'issue', $subscriptionid ); |
383 |
my $alerts = getalert( '', $subscriptionid ); |
390 |
foreach (@$alerts) { |
384 |
foreach (@$alerts) { |
391 |
my $patron = Koha::Patrons->find( $_->{borrowernumber} ); |
385 |
my $patron = Koha::Patrons->find( $_->{borrowernumber} ); |
392 |
next unless $patron; # Just in case |
386 |
next unless $patron; # Just in case |