mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-05-14 05:31:42 +00:00
pass logger to constructor, introduce type of receiver
This commit is contained in:
parent
4ad9638e33
commit
d0c1b16332
|
@ -31,9 +31,23 @@ class SeedDMS_NotificationService {
|
||||||
*/
|
*/
|
||||||
protected $errors;
|
protected $errors;
|
||||||
|
|
||||||
public function __construct() {
|
/*
|
||||||
|
* Service for logging
|
||||||
|
*/
|
||||||
|
protected $logger;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Possible types of receivers
|
||||||
|
*/
|
||||||
|
const RECV_ANY = 0;
|
||||||
|
const RECV_NOTIFICATION = 1;
|
||||||
|
const RECV_REVIEWER = 2;
|
||||||
|
const RECV_APPROVER = 3;
|
||||||
|
|
||||||
|
public function __construct($logger = null) {
|
||||||
$this->services = array();
|
$this->services = array();
|
||||||
$this->errors = array();
|
$this->errors = array();
|
||||||
|
$this->logger = $logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addService($service, $name='') {
|
public function addService($service, $name='') {
|
||||||
|
@ -51,14 +65,21 @@ class SeedDMS_NotificationService {
|
||||||
return $this->errors;
|
return $this->errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toIndividual($sender, $recipient, $subject, $message, $params=array()) {
|
public function toIndividual($sender, $recipient, $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, $recipient, $subject, $message, $params)) {
|
if(!is_callable([$service, 'filter']) || $service->filter($sender, $recipient, $subject, $message, $params, $recvtype)) {
|
||||||
if(!$service->toIndividual($sender, $recipient, $subject, $message, $params)) {
|
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;
|
||||||
|
}
|
||||||
|
if(!$service->toIndividual($sender, $recipient, $subject, $message, $params, $recvtype)) {
|
||||||
$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);
|
||||||
} else {
|
} else {
|
||||||
|
$this->logger->log('Notification service: '.$name.'. Sending mail \''.$subject.'\' to user \''.$to.'\' successful.', PEAR_LOG_INFO);
|
||||||
$this->errors[$name] = true;
|
$this->errors[$name] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,30 +87,46 @@ class SeedDMS_NotificationService {
|
||||||
return $error;
|
return $error;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toGroup($sender, $groupRecipient, $subject, $message, $params=array()) {
|
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)) {
|
if(!is_callable([$service, 'filter']) || $service->filter($sender, $groupRecipient, $subject, $message, $params, $recvtype)) {
|
||||||
if(!$service->toGroup($sender, $groupRecipient, $subject, $message, $params)) {
|
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;
|
$error = false;
|
||||||
$this->errors[$name] = false;
|
$this->errors[$name] = false;
|
||||||
|
$this->logger->log('Notification service: '.$name.'. Sending mail \''.$subject.'\' to group \''.$to.'\' failed.', PEAR_LOG_ERR);
|
||||||
} else {
|
} else {
|
||||||
$this->errors[$name] = true;
|
$this->errors[$name] = true;
|
||||||
|
$this->logger->log('Notification service: '.$name.'. Sending mail \''.$subject.'\' to group \''.$to.'\' successful.', PEAR_LOG_INFO);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $error;
|
return $error;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toList($sender, $recipients, $subject, $message, $params=array()) {
|
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)) {
|
if(!is_callable([$service, 'filter']) || $service->filter($sender, $recipients, $subject, $message, $params, $recvtype)) {
|
||||||
if(!$service->toList($sender, $recipients, $subject, $message, $params)) {
|
$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;
|
$error = false;
|
||||||
$this->errors[$name] = false;
|
$this->errors[$name] = false;
|
||||||
|
$this->logger->log('Notification service: '.$name.'. Sending mail \''.$subject.'\' to users \''.$to.'\' failed.', PEAR_LOG_ERR);
|
||||||
} else {
|
} else {
|
||||||
$this->errors[$name] = true;
|
$this->errors[$name] = true;
|
||||||
|
$this->logger->log('Notification service: '.$name.'. Sending mail \''.$subject.'\' to users \''.$to.'\' successful.', PEAR_LOG_INFO);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user