. * --------------------------------------------------------------------- */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } abstract class NotificationEventAbstract { /** * Raise an ajax notification event * * @param string $event Event * @param CommonGLPI $item Notification data * @param array $options Options * @param string $label Label * @param array $data Notification data * @param NotificationTarget $notificationtarget Target * @param NotificationTemplate $template Template * @param boolean $notify_me Whether to notify current user * * @return void */ static public function raise( $event, CommonGLPI $item, array $options, $label, array $data, NotificationTarget $notificationtarget, NotificationTemplate $template, $notify_me, $emitter = null ) { global $CFG_GLPI; if ($CFG_GLPI['notifications_' . $options['mode']]) { $entity = $notificationtarget->getEntity(); if (isset($options['processed'])) { $processed = &$options['processed']; unset($options['processed']); } else { // Compat with GLPI < 9.4.2 TODO: remove in 9.5 $processed = []; } $notprocessed = []; $targets = getAllDataFromTable( 'glpi_notificationtargets', ['notifications_id' => $data['id']] ); static::extraRaise([ 'event' => $event, 'item' => $item, 'options' => $options, 'data' => $data, 'notificationtarget' => $notificationtarget, 'template' => $template, 'notify_me' => $notify_me ]); //Foreach notification targets foreach ($targets as $target) { //Get all users affected by this notification $notificationtarget->addForTarget($target, $options); foreach ($notificationtarget->getTargets() as $users_infos) { $key = $users_infos[static::getTargetFieldName()]; if ($label || $notificationtarget->validateSendTo($event, $users_infos, $notify_me, $emitter)) { //If the user have not yet been notified if (!isset($processed[$users_infos['language']][$key])) { //If ther user's language is the same as the template's one if (isset($notprocessed[$users_infos['language']] [$key])) { unset($notprocessed[$users_infos['language']] [$key]); } $options['item'] = $item; if ($tid = $template->getTemplateByLanguage($notificationtarget, $users_infos, $event, $options)) { //Send notification to the user if ($label == '') { $send_data = $template->getDataToSend( $notificationtarget, $tid, $key, $users_infos, $options ); $send_data['_notificationtemplates_id'] = $data['notificationtemplates_id']; $send_data['_itemtype'] = $item->getType(); $send_data['_items_id'] = method_exists($item, "getID") ? $item->getID() : 0; $send_data['_entities_id'] = $entity; $send_data['mode'] = $data['mode']; Notification::send($send_data); } else { $notificationtarget->getFromDB($target['id']); echo "