|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Notifier |
|
4
|
|
|
* |
|
5
|
|
|
* Superclass for every notifier. |
|
6
|
|
|
*/ |
|
7
|
|
|
class Notifier { |
|
8
|
|
|
/** |
|
9
|
|
|
* @var array list of the notifications, which is send to the client. |
|
10
|
|
|
*/ |
|
11
|
|
|
private $responseNotificationData; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @var int notification counter of the class |
|
15
|
|
|
*/ |
|
16
|
|
|
private $notifyCount; |
|
17
|
|
|
|
|
18
|
|
|
public function __construct() |
|
19
|
|
|
{ |
|
20
|
|
|
$this->notifyCount = 0; |
|
21
|
|
|
$this->responseNotificationData = array(); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @return Number Return the bitmask of events which are handled |
|
26
|
|
|
* by this notifier. The bitmask can consist of the |
|
27
|
|
|
* OBJECT_SAVE, OBJECT_DELETE, TABLE_SAVE, TABLE_DELETE, REQUEST_START and REQUEST_END flags |
|
28
|
|
|
*/ |
|
29
|
|
|
public function getEvents() |
|
30
|
|
|
{ |
|
31
|
|
|
return 0; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Function which resets the data and the response data class variable. |
|
36
|
|
|
*/ |
|
37
|
|
|
public function reset() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->notifyCount = 0; |
|
40
|
|
|
$this->responseNotificationData = array(); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Function which returns name of the notifier class. |
|
45
|
|
|
* @return string notifier name. |
|
46
|
|
|
*/ |
|
47
|
|
|
public function getNotifierName() |
|
48
|
|
|
{ |
|
49
|
|
|
return strtolower(get_class($this)); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Function which adds notification data to module, so later it can be retrieved to send. |
|
54
|
|
|
* @param string $actionType type of action that response data corresponds. |
|
55
|
|
|
* @return array data object. |
|
56
|
|
|
*/ |
|
57
|
|
|
protected function addNotificationActionData($actionType, $data) |
|
58
|
|
|
{ |
|
59
|
|
|
if (!isset($this->responseNotificationData[$actionType])) { |
|
60
|
|
|
$this->responseNotificationData[$actionType] = $data; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Function which returns notification data that will be sent to client. If there isn't any data added |
|
66
|
|
|
* to response data then it will return a blank array. |
|
67
|
|
|
* @return object response data. |
|
68
|
|
|
*/ |
|
69
|
|
|
protected function createNotificationResponseData() |
|
70
|
|
|
{ |
|
71
|
|
|
if (!empty($this->responseNotificationData)) { |
|
72
|
|
|
$moduleName = $this->getNotifierName(); |
|
73
|
|
|
$idName = $moduleName . (++$this->notifyCount); |
|
74
|
|
|
|
|
75
|
|
|
$response = array( |
|
76
|
|
|
$moduleName => array( |
|
77
|
|
|
$idName => $this->responseNotificationData |
|
78
|
|
|
) |
|
79
|
|
|
); |
|
80
|
|
|
|
|
81
|
|
|
// Clear notification data, the response which is being returned |
|
82
|
|
|
// should be sent to the client. |
|
83
|
|
|
$this->responseNotificationData = array(); |
|
84
|
|
|
|
|
85
|
|
|
return $response; |
|
|
|
|
|
|
86
|
|
|
} else { |
|
87
|
|
|
return array(); |
|
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* If an event elsewhere has occurred, it enters in this method. This method |
|
93
|
|
|
* executes one ore more actions, depends on the event. |
|
94
|
|
|
* @param int $event Event. |
|
95
|
|
|
* @param string $entryid Entryid. |
|
96
|
|
|
* @param array $data array of data. |
|
97
|
|
|
*/ |
|
98
|
|
|
public function update($event, $entryid, $data) |
|
|
|
|
|
|
99
|
|
|
{ |
|
100
|
|
|
// you must implement this function for each notifier |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
?> |
|
|
|
|
|
|
104
|
|
|
|