add type of receiver, do not call toList and toGroup anymore

This commit is contained in:
Uwe Steinmann 2021-01-29 08:57:37 +01:00
parent e6790f6b2f
commit 8e2682dcf0

View File

@ -41,8 +41,10 @@ class SeedDMS_NotificationService {
*/ */
const RECV_ANY = 0; const RECV_ANY = 0;
const RECV_NOTIFICATION = 1; const RECV_NOTIFICATION = 1;
const RECV_REVIEWER = 2; const RECV_OWNER = 2;
const RECV_APPROVER = 3; const RECV_REVIEWER = 3;
const RECV_APPROVER = 4;
const RECV_WORKFLOW = 5;
public function __construct($logger = null) { public function __construct($logger = null) {
$this->services = array(); $this->services = array();
@ -74,7 +76,7 @@ class SeedDMS_NotificationService {
} elseif(is_string($recipient) && trim($recipient) != "") { } elseif(is_string($recipient) && trim($recipient) != "") {
$to = $recipient; $to = $recipient;
} }
if(!$service->toIndividual($sender, $recipient, $subject, $message, $params, $recvtype)) { if(!$service->toIndividual($sender, $recipient, $subject, $message, $params)) {
$error = false; $error = false;
$this->errors[$name] = false; $this->errors[$name] = false;
$this->logger->log('Notification service: '.$name.'. Sending mail \''.$subject.'\' to user \''.$to.'\' failed.', PEAR_LOG_ERR); $this->logger->log('Notification service: '.$name.'. Sending mail \''.$subject.'\' to user \''.$to.'\' failed.', PEAR_LOG_ERR);
@ -87,47 +89,48 @@ class SeedDMS_NotificationService {
return $error; return $error;
} }
/**
* Send a notification to each user of a group
*
*/
public function toGroup($sender, $groupRecipient, $subject, $message, $params=array(), $recvtype=0) { public function toGroup($sender, $groupRecipient, $subject, $message, $params=array(), $recvtype=0) {
$error = true; $error = true;
foreach($this->services as $name => $service) { foreach($this->services as $name => $service) {
if(!is_callable([$service, 'filter']) || $service->filter($sender, $groupRecipient, $subject, $message, $params, $recvtype)) { $ret = true;
if(is_object($groupRecipient) && ($dms = $recipient->getDMS()) && strcasecmp(get_class($groupRecipient), $dms->getClassname('group'))) { foreach ($groupRecipient->getUsers() as $recipient) {
$to = $groupRecipient->getName(); $ret &= $this->toIndividual($sender, $recipient, $subject, $message, $params, $recvtype);
} }
if(!$service->toGroup($sender, $groupRecipient, $subject, $message, $params, $recvtype)) { $this->errors[$name] = $ret;
$error = false; if(!$ret) {
$this->errors[$name] = false; $error = false;
$this->logger->log('Notification service: '.$name.'. Sending mail \''.$subject.'\' to group \''.$to.'\' failed.', PEAR_LOG_ERR);
} else {
$this->errors[$name] = true;
$this->logger->log('Notification service: '.$name.'. Sending mail \''.$subject.'\' to group \''.$to.'\' successful.', PEAR_LOG_INFO);
}
} }
} }
return $error; return $error;
} }
/**
* Send a notification to a list of recipients
*
* The list of recipients may contain both email addresses and users
*
* @param string|object $sender either an email address or a user
* @param array $recipients list of recipients
* @param string $subject key of translatable phrase for the subject
* @param string $message key of translatable phrase for the message body
* @param array $params list of parameters filled into the subject and body
* @param int $recvtype type of receiver
* @return boolean true on success, otherwise false
*/
public function toList($sender, $recipients, $subject, $message, $params=array(), $recvtype=0) { public function toList($sender, $recipients, $subject, $message, $params=array(), $recvtype=0) {
$error = true; $error = true;
foreach($this->services as $name => $service) { foreach($this->services as $name => $service) {
if(!is_callable([$service, 'filter']) || $service->filter($sender, $recipients, $subject, $message, $params, $recvtype)) { $ret = true;
$to = []; foreach ($recipients as $recipient) {
foreach ($recipients as $recipient) { $ret &= $this->toIndividual($sender, $recipients, $subject, $message, $params, $recvtype);
if(is_object($recipient) && ($dms = $recipient->getDMS()) && !strcasecmp(get_class($recipient), $dms->getClassname('user')) && !$recipient->isDisabled() && $recipient->getEmail()!="") { }
$to[] = $recipient->getEmail(); $this->errors[$name] = $ret;
} elseif(is_string($recipient) && trim($recipient) != "") { if(!$ret) {
$to[] = $recipient; $error = false;
}
}
$to = implode($to, ', ');
if(!$service->toList($sender, $recipients, $subject, $message, $params, $recvtype)) {
$error = false;
$this->errors[$name] = false;
$this->logger->log('Notification service: '.$name.'. Sending mail \''.$subject.'\' to users \''.$to.'\' failed.', PEAR_LOG_ERR);
} else {
$this->errors[$name] = true;
$this->logger->log('Notification service: '.$name.'. Sending mail \''.$subject.'\' to users \''.$to.'\' successful.', PEAR_LOG_INFO);
}
} }
} }
return $error; return $error;