seeddms-code/inc/inc.ClassNotificationService.php
Uwe Steinmann 532d5964d9 call filter function before notification
can be used to filter out certain notifications
2020-12-01 18:21:18 +01:00

67 lines
1.9 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;
public function __construct() {
$this->services = array();
}
public function addService($service, $name='') {
$this->services[$name ? $name : md5(uniqid())] = $service;
}
public function getServices() {
return $this->services;
}
public function toIndividual($sender, $recipient, $subject, $message, $params=array()) {
foreach($this->services as $name => $service) {
if(!is_callable([$service, 'filter']) || $service->filter($sender, $recipient, $subject, $message, $params)) {
return $service->toIndividual($sender, $recipient, $subject, $message, $params);
}
}
}
public function toGroup($sender, $groupRecipient, $subject, $message, $params=array()) {
foreach($this->services as $name => $service) {
if(!is_callable([$service, 'filter']) || $service->filter($sender, $groupRecipient, $subject, $message, $params)) {
return $service->toGroup($sender, $groupRecipient, $subject, $message, $params);
}
}
}
public function toList($sender, $recipients, $subject, $message, $params=array()) {
foreach($this->services as $name => $service) {
if(!is_callable([$service, 'filter']) || $service->filter($sender, $recipients, $subject, $message, $params)) {
return $service->toList($sender, $recipients, $subject, $message, $params);
}
}
}
}