mirror of
https://git.code.sf.net/p/seeddms/code
synced 2024-11-26 23:42:11 +00:00
101 lines
2.5 KiB
PHP
101 lines
2.5 KiB
PHP
<?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;
|
|
|
|
/*
|
|
* List of servives with errors
|
|
*/
|
|
protected $errors;
|
|
|
|
public function __construct() {
|
|
$this->services = array();
|
|
$this->errors = array();
|
|
}
|
|
|
|
public function addService($service, $name='') {
|
|
if(!$name)
|
|
$name = md5(uniqid());
|
|
$this->services[$name] = $service;
|
|
$this->errors[$name] = true;
|
|
}
|
|
|
|
public function getServices() {
|
|
return $this->services;
|
|
}
|
|
|
|
public function getErrors() {
|
|
return $this->errors;
|
|
}
|
|
|
|
public function toIndividual($sender, $recipient, $subject, $message, $params=array()) {
|
|
$error = true;
|
|
foreach($this->services as $name => $service) {
|
|
if(!is_callable([$service, 'filter']) || $service->filter($sender, $recipient, $subject, $message, $params)) {
|
|
if(!$service->toIndividual($sender, $recipient, $subject, $message, $params)) {
|
|
$error = false;
|
|
$this->errors[$name] = false;
|
|
} else {
|
|
$this->errors[$name] = true;
|
|
}
|
|
}
|
|
}
|
|
return $error;
|
|
}
|
|
|
|
public function toGroup($sender, $groupRecipient, $subject, $message, $params=array()) {
|
|
$error = true;
|
|
foreach($this->services as $name => $service) {
|
|
if(!is_callable([$service, 'filter']) || $service->filter($sender, $groupRecipient, $subject, $message, $params)) {
|
|
if(!$service->toGroup($sender, $groupRecipient, $subject, $message, $params)) {
|
|
$error = false;
|
|
$this->errors[$name] = false;
|
|
} else {
|
|
$this->errors[$name] = true;
|
|
}
|
|
}
|
|
}
|
|
return $error;
|
|
}
|
|
|
|
public function toList($sender, $recipients, $subject, $message, $params=array()) {
|
|
$error = true;
|
|
foreach($this->services as $name => $service) {
|
|
if(!is_callable([$service, 'filter']) || $service->filter($sender, $recipients, $subject, $message, $params)) {
|
|
if(!$service->toList($sender, $recipients, $subject, $message, $params)) {
|
|
$error = false;
|
|
$this->errors[$name] = false;
|
|
} else {
|
|
$this->errors[$name] = true;
|
|
}
|
|
}
|
|
}
|
|
return $error;
|
|
}
|
|
|
|
}
|
|
|