call each notification service

This commit is contained in:
Uwe Steinmann 2020-12-18 14:36:51 +01:00
parent 9e239a3c65
commit 405f1796e4
2 changed files with 39 additions and 4 deletions

View File

@ -25,6 +25,7 @@
- add support for indexing folders in fulltext search
- add support for start folder in fulltext search
- always call hook postAddSubFolder and postEditDocument
- call each notification service even if one of them fails
--------------------------------------------------------------------------------
Changes in version 5.1.20

View File

@ -26,40 +26,74 @@ class SeedDMS_NotificationService {
*/
protected $services;
/*
* List of servives with errors
*/
protected $errors;
public function __construct() {
$this->services = array();
$this->errors = array();
}
public function addService($service, $name='') {
$this->services[$name ? $name : md5(uniqid())] = $service;
if(!$name)
$name = md5(uniqid());
$this->services[$name] = $service;
$this->errors[$name] = true;
}
public function getServices() {
return $this->services;
}
public function getErrors() {
return $this->errors;
}
public function toIndividual($sender, $recipient, $subject, $message, $params=array()) {
$error = true;
foreach($this->services as $name => $service) {
if(!is_callable([$service, 'filter']) || $service->filter($sender, $recipient, $subject, $message, $params)) {
return $service->toIndividual($sender, $recipient, $subject, $message, $params);
if(!$service->toIndividual($sender, $recipient, $subject, $message, $params)) {
$error = false;
$this->errors[$name] = false;
} else {
$this->errors[$name] = true;
}
}
}
return $error;
}
public function toGroup($sender, $groupRecipient, $subject, $message, $params=array()) {
$error = true;
foreach($this->services as $name => $service) {
if(!is_callable([$service, 'filter']) || $service->filter($sender, $groupRecipient, $subject, $message, $params)) {
return $service->toGroup($sender, $groupRecipient, $subject, $message, $params);
if(!$service->toGroup($sender, $groupRecipient, $subject, $message, $params)) {
$error = false;
$this->errors[$name] = false;
} else {
$this->errors[$name] = true;
}
}
}
return $error;
}
public function toList($sender, $recipients, $subject, $message, $params=array()) {
$error = true;
foreach($this->services as $name => $service) {
if(!is_callable([$service, 'filter']) || $service->filter($sender, $recipients, $subject, $message, $params)) {
return $service->toList($sender, $recipients, $subject, $message, $params);
if(!$service->toList($sender, $recipients, $subject, $message, $params)) {
$error = false;
$this->errors[$name] = false;
} else {
$this->errors[$name] = true;
}
}
}
return $error;
}
}