2016-03-09 16:57:38 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Implementation of notification service
|
|
|
|
*
|
|
|
|
* @category DMS
|
|
|
|
* @package SeedDMS
|
|
|
|
* @license GPL 2
|
|
|
|
* @version @version@
|
|
|
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
|
|
|
* @copyright Copyright (C) 2016 Uwe Steinmann
|
|
|
|
* @version Release: @package_version@
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of notification service
|
|
|
|
*
|
|
|
|
* @category DMS
|
|
|
|
* @package SeedDMS
|
|
|
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
|
|
|
* @copyright Copyright (C) 2016 Uwe Steinmann
|
|
|
|
* @version Release: @package_version@
|
|
|
|
*/
|
|
|
|
class SeedDMS_NotificationService {
|
|
|
|
/**
|
|
|
|
* List of services for sending notification
|
|
|
|
*/
|
|
|
|
protected $services;
|
|
|
|
|
2020-12-18 13:36:51 +00:00
|
|
|
/*
|
|
|
|
* List of servives with errors
|
|
|
|
*/
|
|
|
|
protected $errors;
|
|
|
|
|
2016-03-09 16:57:38 +00:00
|
|
|
public function __construct() {
|
|
|
|
$this->services = array();
|
2020-12-18 13:36:51 +00:00
|
|
|
$this->errors = array();
|
2016-03-09 16:57:38 +00:00
|
|
|
}
|
|
|
|
|
2020-12-01 17:21:18 +00:00
|
|
|
public function addService($service, $name='') {
|
2020-12-18 13:36:51 +00:00
|
|
|
if(!$name)
|
|
|
|
$name = md5(uniqid());
|
|
|
|
$this->services[$name] = $service;
|
|
|
|
$this->errors[$name] = true;
|
2020-12-01 17:21:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getServices() {
|
|
|
|
return $this->services;
|
2016-03-09 16:57:38 +00:00
|
|
|
}
|
|
|
|
|
2020-12-18 13:36:51 +00:00
|
|
|
public function getErrors() {
|
|
|
|
return $this->errors;
|
|
|
|
}
|
|
|
|
|
2016-03-09 16:57:38 +00:00
|
|
|
public function toIndividual($sender, $recipient, $subject, $message, $params=array()) {
|
2020-12-18 13:36:51 +00:00
|
|
|
$error = true;
|
2020-12-01 17:21:18 +00:00
|
|
|
foreach($this->services as $name => $service) {
|
|
|
|
if(!is_callable([$service, 'filter']) || $service->filter($sender, $recipient, $subject, $message, $params)) {
|
2020-12-18 13:36:51 +00:00
|
|
|
if(!$service->toIndividual($sender, $recipient, $subject, $message, $params)) {
|
|
|
|
$error = false;
|
|
|
|
$this->errors[$name] = false;
|
|
|
|
} else {
|
|
|
|
$this->errors[$name] = true;
|
|
|
|
}
|
2020-12-01 17:21:18 +00:00
|
|
|
}
|
2016-03-09 16:57:38 +00:00
|
|
|
}
|
2020-12-18 13:36:51 +00:00
|
|
|
return $error;
|
2016-03-09 16:57:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function toGroup($sender, $groupRecipient, $subject, $message, $params=array()) {
|
2020-12-18 13:36:51 +00:00
|
|
|
$error = true;
|
2020-12-01 17:21:18 +00:00
|
|
|
foreach($this->services as $name => $service) {
|
|
|
|
if(!is_callable([$service, 'filter']) || $service->filter($sender, $groupRecipient, $subject, $message, $params)) {
|
2020-12-18 13:36:51 +00:00
|
|
|
if(!$service->toGroup($sender, $groupRecipient, $subject, $message, $params)) {
|
|
|
|
$error = false;
|
|
|
|
$this->errors[$name] = false;
|
|
|
|
} else {
|
|
|
|
$this->errors[$name] = true;
|
|
|
|
}
|
2020-12-01 17:21:18 +00:00
|
|
|
}
|
2016-03-09 16:57:38 +00:00
|
|
|
}
|
2020-12-18 13:36:51 +00:00
|
|
|
return $error;
|
2016-03-09 16:57:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function toList($sender, $recipients, $subject, $message, $params=array()) {
|
2020-12-18 13:36:51 +00:00
|
|
|
$error = true;
|
2020-12-01 17:21:18 +00:00
|
|
|
foreach($this->services as $name => $service) {
|
|
|
|
if(!is_callable([$service, 'filter']) || $service->filter($sender, $recipients, $subject, $message, $params)) {
|
2020-12-18 13:36:51 +00:00
|
|
|
if(!$service->toList($sender, $recipients, $subject, $message, $params)) {
|
|
|
|
$error = false;
|
|
|
|
$this->errors[$name] = false;
|
|
|
|
} else {
|
|
|
|
$this->errors[$name] = true;
|
|
|
|
}
|
2020-12-01 17:21:18 +00:00
|
|
|
}
|
2016-03-09 16:57:38 +00:00
|
|
|
}
|
2020-12-18 13:36:51 +00:00
|
|
|
return $error;
|
2016-03-09 16:57:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|