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