mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-03-11 16:35:38 +00:00
add type of receiver, do not call toList and toGroup anymore
This commit is contained in:
parent
e6790f6b2f
commit
8e2682dcf0
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user