From 8e2682dcf0ebc883150fef198ff115192ddf57ee Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Fri, 29 Jan 2021 08:57:37 +0100 Subject: [PATCH] add type of receiver, do not call toList and toGroup anymore --- inc/inc.ClassNotificationService.php | 69 +++++++++++++++------------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/inc/inc.ClassNotificationService.php b/inc/inc.ClassNotificationService.php index 67e92ef53..e4d04b4e4 100644 --- a/inc/inc.ClassNotificationService.php +++ b/inc/inc.ClassNotificationService.php @@ -41,8 +41,10 @@ class SeedDMS_NotificationService { */ const RECV_ANY = 0; const RECV_NOTIFICATION = 1; - const RECV_REVIEWER = 2; - const RECV_APPROVER = 3; + const RECV_OWNER = 2; + const RECV_REVIEWER = 3; + const RECV_APPROVER = 4; + const RECV_WORKFLOW = 5; public function __construct($logger = null) { $this->services = array(); @@ -74,7 +76,7 @@ class SeedDMS_NotificationService { } elseif(is_string($recipient) && trim($recipient) != "") { $to = $recipient; } - if(!$service->toIndividual($sender, $recipient, $subject, $message, $params, $recvtype)) { + if(!$service->toIndividual($sender, $recipient, $subject, $message, $params)) { $error = false; $this->errors[$name] = false; $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; } + /** + * Send a notification to each user of a group + * + */ public function toGroup($sender, $groupRecipient, $subject, $message, $params=array(), $recvtype=0) { $error = true; foreach($this->services as $name => $service) { - if(!is_callable([$service, 'filter']) || $service->filter($sender, $groupRecipient, $subject, $message, $params, $recvtype)) { - if(is_object($groupRecipient) && ($dms = $recipient->getDMS()) && strcasecmp(get_class($groupRecipient), $dms->getClassname('group'))) { - $to = $groupRecipient->getName(); - } - if(!$service->toGroup($sender, $groupRecipient, $subject, $message, $params, $recvtype)) { - $error = false; - $this->errors[$name] = 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); - } + $ret = true; + foreach ($groupRecipient->getUsers() as $recipient) { + $ret &= $this->toIndividual($sender, $recipient, $subject, $message, $params, $recvtype); + } + $this->errors[$name] = $ret; + if(!$ret) { + $error = false; } } 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) { $error = true; foreach($this->services as $name => $service) { - if(!is_callable([$service, 'filter']) || $service->filter($sender, $recipients, $subject, $message, $params, $recvtype)) { - $to = []; - foreach ($recipients as $recipient) { - if(is_object($recipient) && ($dms = $recipient->getDMS()) && !strcasecmp(get_class($recipient), $dms->getClassname('user')) && !$recipient->isDisabled() && $recipient->getEmail()!="") { - $to[] = $recipient->getEmail(); - } elseif(is_string($recipient) && trim($recipient) != "") { - $to[] = $recipient; - } - } - $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); - } + $ret = true; + foreach ($recipients as $recipient) { + $ret &= $this->toIndividual($sender, $recipients, $subject, $message, $params, $recvtype); + } + $this->errors[$name] = $ret; + if(!$ret) { + $error = false; } } return $error;