|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
You may not change or alter any portion of this comment or credits |
|
4
|
|
|
of supporting developers from this source code or any supporting source code |
|
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
6
|
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
|
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
use Xoops\Core\Kernel\CriteriaElement; |
|
|
|
|
|
|
13
|
|
|
use Xoops\Core\Service\AbstractContract; |
|
14
|
|
|
use Xoops\Core\Service\Response; |
|
15
|
|
|
use Xoops\Core\Service\Contract\NotificationsInterface; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Notifications provider for service manager |
|
19
|
|
|
* |
|
20
|
|
|
* @category Module |
|
21
|
|
|
* @package Notifications |
|
22
|
|
|
* @author Alain91 <[email protected]> |
|
23
|
|
|
* @copyright XOOPS Project (http://xoops.org) |
|
24
|
|
|
* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
|
25
|
|
|
* @link http://xoops.org |
|
26
|
|
|
* @since 2.6.0 |
|
27
|
|
|
*/ |
|
28
|
|
|
class NotificationsProvider extends AbstractContract implements NotificationsInterface |
|
29
|
|
|
{ |
|
30
|
|
|
protected $xoops_url; |
|
31
|
|
|
protected $xoops_upload_url; |
|
32
|
|
|
|
|
33
|
|
|
public function __construct() |
|
34
|
|
|
{ |
|
35
|
|
|
$this->xoops_url = \XoopsBaseConfig::get('url'); |
|
36
|
|
|
$this->xoops_upload_url = \XoopsBaseConfig::get('uploads-url'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* getName - get a short name for this service provider. This should be unique within the |
|
41
|
|
|
* scope of the named service, so using module dirname is suggested. |
|
42
|
|
|
* |
|
43
|
|
|
* @return string - a unique name for the service provider |
|
44
|
|
|
*/ |
|
45
|
|
|
public function getName() |
|
46
|
|
|
{ |
|
47
|
|
|
return 'notifications'; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* getDescription - get human readable description of the service provider |
|
52
|
|
|
* |
|
53
|
|
|
* @return string |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getDescription() |
|
56
|
|
|
{ |
|
57
|
|
|
return 'Traditional XOOPS notifications.'; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function notifyUser(Response $response, $template_dir, $template, $subject, $tags) |
|
61
|
|
|
{ |
|
62
|
|
|
$notification = new NotificationsNotification(); |
|
63
|
|
|
$ret = $notification->notifyUser($template_dir, $template, $subject, $tags); |
|
64
|
|
|
if (!$ret) |
|
65
|
|
|
$response->setSuccess(false)->addErrorMessage('Unable to notify user'); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function getObjectsArray(Response $response, CriteriaElement $criteria = null, $id_as_key = false) |
|
69
|
|
|
{ |
|
70
|
|
|
$handler = Notifications::getInstance()->getHandlerNotification(); |
|
|
|
|
|
|
71
|
|
|
$ret = $handler->getObjectsArray($criteria, $id_as_key); |
|
72
|
|
|
if ($ret) |
|
73
|
|
|
$response->setValue($ret); |
|
74
|
|
|
else |
|
75
|
|
|
$response->setSuccess(false)->addErrorMessage('Unable to getObjectsArray'); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function getNotification(Response $response, $module_id, $category, $item_id, $event, $user_id) |
|
79
|
|
|
{ |
|
80
|
|
|
$handler = Notifications::getInstance()->getHandlerNotification(); |
|
|
|
|
|
|
81
|
|
|
$ret = $handler->getNotification($module_id, $category, $item_id, $event, $user_id); |
|
82
|
|
|
if ($ret) |
|
83
|
|
|
$response->setValue($ret); |
|
84
|
|
|
else |
|
85
|
|
|
$response->setSuccess(false)->addErrorMessage('Unable to getNotification'); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function isSubscribed(Response $response, $category, $item_id, $event, $module_id, $user_id) |
|
89
|
|
|
{ |
|
90
|
|
|
$handler = Notifications::getInstance()->getHandlerNotification(); |
|
|
|
|
|
|
91
|
|
|
$ret = $handler->isSubscribed($module_id, $category, $item_id, $event, $user_id); |
|
92
|
|
|
$response->setValue((int)$ret); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
View Code Duplication |
public function subscribe(Response $response, $category, $item_id, $events, $mode = null, $module_id = null, $user_id = null) |
|
96
|
|
|
{ |
|
97
|
|
|
$handler = Notifications::getInstance()->getHandlerNotification(); |
|
|
|
|
|
|
98
|
|
|
$ret = $handler->suscribe($category, $item_id, $events, $mode, $module_id, $user_id); |
|
99
|
|
|
if (!$ret) |
|
100
|
|
|
$response->setSuccess(false)->addErrorMessage('Unable to suscribe'); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function getByUser(Response $response, $user_id) |
|
104
|
|
|
{ |
|
105
|
|
|
$handler = Notifications::getInstance()->getHandlerNotification(); |
|
|
|
|
|
|
106
|
|
|
$ret = $handler->getByUser($user_id); |
|
107
|
|
|
$response->setValue($ret); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function getSubscribedEvents(Response $response, $category, $item_id, $module_id, $user_id) |
|
111
|
|
|
{ |
|
112
|
|
|
$handler = Notifications::getInstance()->getHandlerNotification(); |
|
|
|
|
|
|
113
|
|
|
$ret = $handler->getSubscribedEvents($category, $item_id, $module_id, $user_id); |
|
114
|
|
|
$response->setValue($ret); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
public function getByItemId(Response $response, $module_id, $item_id, $order = null, $status = null) |
|
118
|
|
|
{ |
|
119
|
|
|
$handler = Notifications::getInstance()->getHandlerNotification(); |
|
|
|
|
|
|
120
|
|
|
$ret = $handler->getByItemId($module_id, $item_id, $order, $status); |
|
121
|
|
|
$response->setValue($ret); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
View Code Duplication |
public function triggerEvents( |
|
125
|
|
|
Response $response, |
|
126
|
|
|
$category, |
|
127
|
|
|
$item_id, |
|
128
|
|
|
$events, |
|
129
|
|
|
$extra_tags = array(), |
|
130
|
|
|
$user_list = array(), |
|
131
|
|
|
$module_id = null, |
|
132
|
|
|
$omit_user_id = null |
|
133
|
|
|
) { |
|
134
|
|
|
$handler = Notifications::getInstance()->getHandlerNotification(); |
|
|
|
|
|
|
135
|
|
|
$ret = $handler->triggerEvents($category, $item_id, $events, $extra_tags, $user_list, $module_id, $omit_user_id); |
|
|
|
|
|
|
136
|
|
|
if (!ret) |
|
137
|
|
|
$response->setSuccess(false)->addErrorMessage('Unable to triggerEvents'); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
public function triggerEvent( |
|
141
|
|
|
Response $response, |
|
142
|
|
|
$category, |
|
143
|
|
|
$item_id, |
|
144
|
|
|
$event, |
|
145
|
|
|
$extra_tags = array(), |
|
146
|
|
|
$user_list = array(), |
|
147
|
|
|
$module_id = null, |
|
148
|
|
|
$omit_user_id = null |
|
149
|
|
|
) { |
|
150
|
|
|
$helper = Notifications::getInstance(); |
|
151
|
|
|
$handler = $helper->getHandlerNotification(); |
|
|
|
|
|
|
152
|
|
|
if (empty($category) AND empty($module_id)) { |
|
|
|
|
|
|
153
|
|
|
$response->setSuccess(false)->addErrorMessage('Unable to triggerEvent'); |
|
154
|
|
|
return; |
|
155
|
|
|
} |
|
156
|
|
|
if (empty($category)) { |
|
157
|
|
|
$xoops = \Xoops::getInstance(); |
|
158
|
|
|
$module = $xoops->getModuleById($module_id); |
|
159
|
|
|
$catinfo = $helper->getCommentsCategory($module->getVar('dirname')); |
|
160
|
|
|
$category = $catinfo['name']; |
|
161
|
|
|
} |
|
162
|
|
|
$ret = $handler->triggerEvent($category, $item_id, $event, $extra_tags, $user_list, $module_id, $omit_user_id); |
|
|
|
|
|
|
163
|
|
|
if (!ret) |
|
164
|
|
|
$response->setSuccess(false)->addErrorMessage('Unable to triggerEvent'); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
View Code Duplication |
public function unsubscribeByUser(Response $response, $user_id) |
|
168
|
|
|
{ |
|
169
|
|
|
$handler = Notifications::getInstance()->getHandlerNotification(); |
|
|
|
|
|
|
170
|
|
|
$ret = $handler->unsubscribeByUser($user_id); |
|
|
|
|
|
|
171
|
|
|
if (!ret) |
|
172
|
|
|
$response->setSuccess(false)->addErrorMessage('Unable to unsubscribeByUser'); |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
public function unsubscribe(Response $response, $category, $item_id, $events, $module_id = null, $user_id = null) |
|
176
|
|
|
{ |
|
177
|
|
|
$handler = Notifications::getInstance()->getHandlerNotification(); |
|
|
|
|
|
|
178
|
|
|
$ret = $handler->unsubscribe($category, $item_id, $events, $module_id, $user_id); |
|
|
|
|
|
|
179
|
|
|
if (!ret) |
|
180
|
|
|
$response->setSuccess(false)->addErrorMessage('Unable to unsubscribe'); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
View Code Duplication |
public function unsubscribeByModule(Response $response, $module_id) |
|
184
|
|
|
{ |
|
185
|
|
|
$handler = Notifications::getInstance()->getHandlerNotification(); |
|
|
|
|
|
|
186
|
|
|
$ret = $handler->unsubscribeByModule($module_id); |
|
|
|
|
|
|
187
|
|
|
if (!ret) |
|
188
|
|
|
$response->setSuccess(false)->addErrorMessage('Unable to unsubscribeByModule'); |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
View Code Duplication |
public function unsubscribeByItem(Response $response, $module_id, $category, $item_id) |
|
192
|
|
|
{ |
|
193
|
|
|
$handler = Notifications::getInstance()->getHandlerNotification(); |
|
|
|
|
|
|
194
|
|
|
$ret = $handler->unsubscribeByItem($module_id, $category, $item_id); |
|
|
|
|
|
|
195
|
|
|
if (!ret) |
|
196
|
|
|
$response->setSuccess(false)->addErrorMessage('Unable to unsubscribeByItem'); |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
public function doLoginMaintenance(Response $response, $user_id) |
|
200
|
|
|
{ |
|
201
|
|
|
$handler = Notifications::getInstance()->getHandlerNotification(); |
|
|
|
|
|
|
202
|
|
|
$handler->doLoginMaintenance($user_id); |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
} |
|
206
|
|
|
|
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: