Documentation/Index/EventEmitterForTodoMod: TodoModSaveNewCardCreatorAfterSave.inc

Plik TodoModSaveNewCardCreatorAfterSave.inc, 2.1 KB (dodany przez TS, 4 years temu)
xx
Line 
1<?php
2
3/**
4 * TodoModSaveNewCardCreatorAfterSave
5 *
6 * @author Tomasz Świenty
7 * @version 0.1
8 * @copyright Copyright (c) eDokumenty
9 */
10final class TodoModSaveNewCardCreatorAfterSave {
11
12
13    public static function init($args) {
14
15        $message = 'Dodano nowe zadanie';
16
17        if ($contid = SystemRegistry::get('UserSettings.ContactID')) {
18            require_once('./classes/Notifications/NotificationSettings.inc');
19
20            $metaData = array(
21                'ny_cat' => NotifierCategories::EVENT_ADD_TODO,
22                'n__msg' => $message,
23                'nscls_' => 'TODO',
24                'nskey_' => $args['event']->get('evntid'),
25                'nstxt_' => $args['event']->get('sumary'),
26            );
27
28            // tablica kogo chcesz powiadomić
29            $receivers = $args['event']->get('emp_id');
30
31            // wybór kanału powiadomień na podstawie typu powiadomienia i odbiorców
32            $notifyChannels = NotificationSettings::prepareNotifyChannelsForReceivers(NotifierCategories::EVENT_ADD_TODO, $receivers);
33
34            // pobranie szablonu jeśli powiadomienie pójdzie na maila
35            $template = NotificationSettings::getEmailNotifyTemplateByCode(NotifierCategories::EVENT_ADD_TODO);
36
37            if (is_array($notifyChannels) AND $notifyChannels) {
38                foreach ($notifyChannels as $notifyChannel => $notifyChannelReceivers) {
39                    if ($notifyChannelReceivers) {
40                        $notifier = new Notifier();
41                        $notifier->setContextBean($args['event']);
42                        $notifier->setTemplate($template);
43                        $notifier->setMetaData($metaData);
44                        $notifier->setReceivers($notifyChannelReceivers);
45                        $notifier->setNotifiersType($notifyChannel);
46                        $notifier->setMessage($message);
47
48                        $notifier->send();
49                    }
50                }
51            }
52        }
53
54    }
55
56}
57
58if (isset($args)) {
59    TodoModSaveNewCardCreatorAfterSave::init($args);
60}