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