3 * FusionForge MonitorElement Object
5 * Copyright 2014,2017, Franck Villaume - TrivialDev
7 * This file is part of FusionForge. FusionForge is free software;
8 * you can redistribute it and/or modify it under the terms of the
9 * GNU General Public License as published by the Free Software
10 * Foundation; either version 2 of the Licence, or (at your option)
13 * FusionForge is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 class MonitorElement extends FFError {
25 var $_clearMonitorQuery = null;
26 var $_clearMonitorForUserIdQuery = null;
27 var $_disableMonitoringByUserIdQuery = null;
28 var $_disableMonitoringForGroupIdByUserIdQuery = null;
29 var $_enableMonitoringByUserIdQuery = null;
30 var $_getAllEmailsInArrayQuery = null;
31 var $_getMonitorCounterIntegerQuery = null;
32 var $_getMonitorUsersIdsInArrayQuery = null;
33 var $_getMonitoredByUserIdInArrayQuery = null;
34 var $_getMonitoredDistinctGroupIdsByUserIdInArrayQuery = null;
35 var $_getMonitoredIdsByGroupIdByUserIdInArrayQuery = null;
36 var $_isMonitoredByAnyQuery = null;
37 var $_isMonitoredByUserIdQuery = null;
39 function __construct($what) {
42 $this->_clearMonitorQuery = 'delete from docdata_monitored_docman where doc_id = $1';
43 $this->_clearMonitorForUserIdQuery = 'delete from docdata_monitored_docman where user_id = $1';
44 $this->_disableMonitoringByUserIdQuery = 'delete from docdata_monitored_docman where doc_id = $1 and user_id = $2';
45 $this->_disableMonitoringForGroupIdByUserIdQuery = 'delete from docdata_monitored_docman where exists (select docdata_monitored_docman.doc_id from docdata_monitored_docman, doc_data where docdata_monitored_docman.doc_id = doc_data.docid and doc_data.group_id = $1 and docdata_monitored_docman.user_id = $2)';
46 $this->_enableMonitoringByUserIdQuery = 'insert into docdata_monitored_docman (doc_id, user_id) values ($1, $2)';
47 $this->_getAllEmailsInArrayQuery = 'select users.email from users, docdata_monitored_docman where users.user_id = docdata_monitored_docman.user_id and docdata_monitored_docman.doc_id = $1 and users.status = $2';
48 $this->_getMonitorCounterIntegerQuery = 'select count(docgroup_monitored_docman.user_id) as count from docdata_monitored_docman, users where users.user_id = docdata_monitored_docman.user_id and doc_id = $1 and users.status = $2';
49 $this->_getMonitorUsersIdsInArrayQuery = 'select docdata_monitored_docman.user_id from docdata_monitored_docman, users where users.user_id = docdata_monitored_docman.user_id and doc_id = $1 and users.status = $2';;
50 $this->_getMonitoredByUserIdInArrayQuery = 'select doc_id from docdata_monitored_docman where user_id = $1';
51 $this->_getMonitoredDistinctGroupIdsByUserIdInArrayQuery = 'select distinct doc_data.group_id from groups, doc_data, docdata_monitored_docman where docdata_monitored_docman.doc_id = doc_data.docid and groups.group_id = doc_data.group_id and docdata_monitored_docman.user_id = $1 and groups.status = $2';
52 $this->_getMonitoredIdsByGroupIdByUserIdInArrayQuery = 'select doc_data.docid from doc_data, docdata_monitored_docman where doc_data.docid = docdata_monitored_docman.doc_id and doc_data.group_id = $1 and docdata_monitored_docman.user_id = $2';
53 $this->_isMonitoredByAnyQuery = 'select doc_id, docdata_monitored_docman.user_id from docdata_monitored_docman, users where users.user_id = docdata_monitored_docman.user_id and doc_id = $1 and users.status = $2';
54 $this->_isMonitoredByUserIdQuery = 'select doc_id from docdata_monitored_docman where doc_id = $1 and user_id = $2';
58 $this->_clearMonitorQuery = 'delete from docgroup_monitored_docman where docgroup_id = $1';
59 $this->_clearMonitorForUserIdQuery = 'delete from docgroup_monitored_docman where user_id = $1';
60 $this->_disableMonitoringByUserIdQuery = 'delete from docgroup_monitored_docman where docgroup_id = $1 and user_id = $2';
61 $this->_disableMonitoringForGroupIdByUserIdQuery = null; // not used by docgroup.
62 $this->_enableMonitoringByUserIdQuery = 'insert into docgroup_monitored_docman (docgroup_id, user_id) values ($1, $2)';
63 $this->_getAllEmailsInArrayQuery = 'select users.email from users, docgroup_monitored_docman where users.user_id = docgroup_monitored_docman.user_id and docgroup_monitored_docman.docgroup_id = $1 and users.status = $2';
64 $this->_getMonitorCounterIntegerQuery = 'select count(docgroup_monitored_docman.user_id) as count from docgroup_monitored_docman, users where users.user_id = docgroup_monitored_docman.user_id and docgroup_id = $1 and users.status = $2';
65 $this->_getMonitorUsersIdsInArrayQuery = 'select docgroup_monitored_docman.user_id from docgroup_monitored_docman, users where users.user_id = docgroup_monitored_docman.user_id and docgroup_id = $1 and users.status = $2';
66 $this->_getMonitoredByUserIdInArrayQuery = 'select docgroup_id from docgroup_monitored_docman where user_id = $1';
67 $this->_getMonitoredDistinctGroupIdsByUserIdInArrayQuery = 'select distinct doc_groups.group_id from groups, doc_groups, docgroup_monitored_docman where docgroup_monitored_docman.docgroup_id = doc_groups.doc_group and groups.group_id = doc_groups.group_id and docgroup_monitored_docman.user_id = $1 and groups.status = $2';
68 $this->_getMonitoredIdsByGroupIdByUserIdInArrayQuery = 'select doc_groups.doc_group from doc_groups, docgroup_monitored_docman where doc_groups.doc_group = docgroup_monitored_docman.docgroup_id and doc_groups.group_id = $1 and docgroup_monitored_docman.user_id = $2';
69 $this->_isMonitoredByAnyQuery = 'select docgroup_id, docgroup_monitored_docman.user_id from docgroup_monitored_docman, users where users.user_id = docgroup_monitored_docman.user_id and docgroup_id = $1 and users.status = $2';
70 $this->_isMonitoredByUserIdQuery = 'select docgroup_id from docgroup_monitored_docman where docgroup_id = $1 and user_id = $2';
74 $this->_clearMonitorQuery = 'delete from forum_monitored_forums where forum_id = $1';
75 $this->_clearMonitorForUserIdQuery = 'delete from forum_monitored_forums where user_id = $1';
76 $this->_disableMonitoringByUserIdQuery = 'delete from forum_monitored_forums where forum_id = $1 and user_id = $2';
77 $this->_disableMonitoringForGroupIdByUserIdQuery = 'delete from forum_monitored_forums where exists (select forum_monitored_forums.forum_id from forum_monitored_forums, forum_group_list where forum_monitored_forums.forum_id = forum_group_list.group_forum_id and forum_group_list.group_id = $1 and forum_monitored_forums.user_id = $2)';
78 $this->_enableMonitoringByUserIdQuery = 'insert into forum_monitored_forums (forum_id, user_id) values ($1, $2)';
79 $this->_getAllEmailsInArrayQuery = 'select users.email from users, forum_monitored_forums where users.user_id = forum_monitored_forums.user_id and forum_monitored_forums.forum_id = $1 and users.status = $2';
80 $this->_getMonitorCounterIntegerQuery = 'select count(forum_monitored_forums.user_id) as count from forum_monitored_forums, users where users.user_id = forum_monitored_forums.user_id and forum_monitored_forums.forum_id = $1 and users.status = $2';
81 $this->_getMonitorUsersIdsInArrayQuery = 'select forum_monitored_forums.user_id from forum_monitored_forums, users where users.user_id = forum_monitored_forums.user_id and forum_id = $1 and users.status = $2';
82 $this->_getMonitoredByUserIdInArrayQuery = 'select forum_id from forum_monitored_forums where user_id = $1';
83 $this->_getMonitoredDistinctGroupIdsByUserIdInArrayQuery = 'select distinct forum_group_list.group_id from groups, forum_group_list, forum_monitored_forums where groups.group_id = forum_group_list.group_id and forum_group_list.group_forum_id = forum_monitored_forums.forum_id and forum_monitored_forums.user_id = $1 and groups.status = $2';
84 $this->_getMonitoredIdsByGroupIdByUserIdInArrayQuery = 'select forum_group_list.group_forum_id from groups, forum_group_list,forum_monitored_forums where groups.group_id = forum_group_list.group_id and forum_group_list.group_forum_id = forum_monitored_forums.forum_id and groups.group_id = $1 and forum_monitored_forums.user_id= $2';
85 $this->_isMonitoredByAnyQuery = 'select forum_id, forum_monitored_forums.user_id from forum_monitored_forums, users where users.user_id = forum_monitored_forums.user_id and forum_monitored_forums.forum_id = $1 and users.status = $2';
86 $this->_isMonitoredByUserIdQuery = 'select forum_id from forum_monitored_forums where forum_id = $1 and user_id = $2';
89 case 'artifact_type': {
90 $this->_clearMonitorQuery = 'delete from artifact_type_monitor where group_artifact_id = $1';
91 $this->_clearMonitorForUserIdQuery = 'delete from artifact_type_monitor where user_id = $1';
92 $this->_enableMonitoringByUserIdQuery = 'insert into artifact_type_monitor (group_artifact_id, user_id) values ($1, $2)';
93 $this->_disableMonitoringByUserIdQuery = 'delete from artifact_type_monitor where group_artifact_id = $1 and user_id = $2';
94 $this->_getMonitorUsersIdsInArrayQuery = 'select artifact_type_monitor.user_id from artifact_type_monitor, users where users.user_id = artifact_type_monitor.user_id and artifact_type_monitor.group_artifact_id = $1 and users.status = $2';
95 $this->_isMonitoredByUserIdQuery = 'select group_artifact_id from artifact_type_monitor where group_artifact_id = $1 and user_id = $2';
99 $this->_clearMonitorQuery = 'delete from artifact_monitor where artifact_id = $1';
100 $this->_clearMonitorForUserIdQuery = 'delete from artifact_monitor where user_id = $1';
101 $this->_enableMonitoringByUserIdQuery = 'insert into artifact_monitor (artifact_id, user_id) values ($1, $2)';
102 $this->_disableMonitoringByUserIdQuery = 'delete from artifact_monitor where artifact_id = $1 and user_id = $2';
103 $this->_getMonitorUsersIdsInArrayQuery = 'select artifact_monitor.user_id from artifact_monitor, users where users.user_id = artifact_monitor.user_id and artifact_monitor.artifact_id = $1 and users.status = $2';
104 $this->_isMonitoredByUserIdQuery = 'select artifact_id from artifact_monitor where artifact_id = $1 and user_id = $2';
108 $this->_clearMonitorQuery = 'delete from filemodule_monitor where filemodule_id = $1';
109 $this->_clearMonitorForUserIdQuery = 'delete from filemodule_monitor where user_id = $1';
110 $this->_disableMonitoringByUserIdQuery = 'delete from filemodule_monitor where filemodule_id = $1 and user_id = $2';
111 $this->_disableMonitoringForGroupIdByUserIdQuery = 'delete from filemodule_monitor where exists (select filemodule_monitor.filemodule_id from filemodule_monitor, frs_package where filemodule_monitor.filemodule_id = frs_package.package_id and frs_package.group_id = $1 and filemodule_monitor.user_id = $2)';
112 $this->_enableMonitoringByUserIdQuery = 'insert into filemodule_monitor (filemodule_id, user_id) values ($1, $2)';
113 $this->_getAllEmailsInArrayQuery = 'select users.email from users, filemodule_monitor where users.user_id = filemodule_monitor.user_id and filemodule_monitor.filemodule_id = $1 and users.status = $2';
114 $this->_getMonitorCounterIntegerQuery = 'select count(filemodule_monitor.user_id) as count from filemodule_monitor, users where users.user_id = filemodule_monitor.user_id and filemodule_monitor.filemodule_id = $1 and users.status = $2';
115 $this->_getMonitorUsersIdsInArrayQuery = 'select filemodule_monitor.user_id from filemodule_monitor, users where users.user_id = filemodule_monitor.user_id and filemodule_monitor.filemodule_id = $1 and users.status = $2';
116 $this->_getMonitoredByUserIdInArrayQuery = 'select filemodule_id from filemodule_monitor where user_id = $1';
117 $this->_getMonitoredDistinctGroupIdsByUserIdInArrayQuery = 'select distinct frs_package.group_id from groups, frs_package, filemodule_monitor where filemodule_monitor.filemodule_id = frs_package.package_id and groups.group_id = frs_package.group_id and filemodule_monitor.user_id = $1 and groups.status = $2';
118 $this->_getMonitoredIdsByGroupIdByUserIdInArrayQuery = 'select filemodule_monitor.filemodule_id from groups,filemodule_monitor,frs_package where groups.group_id = frs_package.group_id and frs_package.package_id = filemodule_monitor.filemodule_id and groups.group_id=$1 and filemodule_monitor.user_id=$2';
119 $this->_isMonitoredByAnyQuery = 'select filemodule_id, filemodule_monitor.user_id from filemodule_monitor, users where users.user_id = filemodule_monitor.user_id and filemodule_monitor.filemodule_id = $1 and users.status = $2';
120 $this->_isMonitoredByUserIdQuery = 'select filemodule_id from filemodule_monitor where filemodule_id = $1 and user_id = $2';
133 function clearMonitor($which = 0) {
134 if ($which && isset($this->_clearMonitorQuery)) {
135 $result = db_query_params($this->_clearMonitorQuery, array($which));
137 $this->setError(_('Unable to clear monitoring')._(': ').db_error());
142 $this->setError('clearMonitor:: '._('Missing parameters values.'));
146 function clearMonitorForUserId($who = 0) {
147 if ($who && isset($this->_clearMonitorForUserIdQuery)) {
148 $result = db_query_params($this->_clearMonitorForUserIdQuery, array($who));
150 $this->setError(_('Unable to clear monitoring for user')._(': ').db_error());
155 $this->setError('clearMonitor:: '._('Missing parameters values.'));
159 function disableMonitoringByUserId($which = 0, $who = 0) {
160 if ($which && $who && isset($this->_disableMonitoringByUserIdQuery)) {
161 if ($this->isMonitoredByUserId($which, $who)) {
162 $result = db_query_params($this->_disableMonitoringByUserIdQuery, array($which, $who));
164 $this->setError(_('Unable to remove monitor from db')._(': ').db_error());
170 $this->setError('disableMonitoringByUserId:: '._('Missing parameters values.'));
174 function disableMonitoringForGroupIdByUserId($where = 0, $who = 0) {
175 if ($where && $who && isset($this->_disableMonitoringForGroupIdByUserIdQuery)) {
176 $result = db_query_params($this->_disableMonitoringForGroupIdByUserIdQuery, array($where, $who));
178 $this->setError(_('Unable to remove monitor from db')._(': ').db_error());
183 $this->setError('disableMonitoringForGroupIdByUserId:: '._('Missing parameters values.'));
187 function enableMonitoringByUserId($which, $who) {
188 if ($which && $who && isset($this->_enableMonitoringByUserIdQuery)) {
189 if (!$this->isMonitoredByUserId($which, $who)) {
190 $result = db_query_params($this->_enableMonitoringByUserIdQuery, array($which, $who));
192 $this->setError(_('Unable to add monitor')._(': ').db_error());
198 $this->setError('enableMonitoringByUserId:: '._('Missing parameters values.'));
202 function getAllEmailsInArray($which = 0) {
203 if ($which && isset($this->_getAllEmailsInArrayQuery)) {
204 $result = db_query_params($this->_getAllEmailsInArrayQuery, array($which, 'A'));
205 if ($result || db_numrows($result) >= 0) {
206 return util_result_column_to_array($result);
208 $this->setError(_('Unable to get emails from db')._(': ').db_error());
211 $this->setError('getAllEmailsInArray:: '._('Missing parameters values.'));
215 function getAllEmailsInCommatSeparated($which = 0) {
217 $getAllEmailsInCommatSeparatedArray = $this->getAllEmailsInArray($which);
218 if ($getAllEmailsInCommatSeparatedArray && is_array($getAllEmailsInCommatSeparatedArray)) {
219 $getAllEmailsInCommatSeparatedString = '';
221 for ($i = 0; $i < count($getAllEmailsInCommatSeparatedArray); $i++) {
225 $getAllEmailsInCommatSeparatedString .= $comma.$getAllEmailsInCommatSeparatedArray[$i];
227 return $getAllEmailsInCommatSeparatedString;
231 $this->setError('getAllEmailsInCommatSeparated:: '._('Missing parameters values.'));
235 function getMonitorUsersIdsInArray($which = 0) {
236 if ($which && isset($this->_getMonitorUsersIdsInArrayQuery)) {
237 $result = db_query_params($this->_getMonitorUsersIdsInArrayQuery, array($which, 'A'));
238 if ($result || db_numrows($result) >= 0) {
239 return util_result_column_to_array($result);
241 $this->setError(_('Unable to get ids from db')._(': ').db_error());
245 $this->setError('getMonitorUsersIdsInArray:: '._('Missing parameters values.'));
249 function getMonitorCounterInteger($which = 0) {
250 if ($which && isset($this->_getMonitorCounterIntegerQuery)) {
251 $result = db_query_params($this->_getMonitorCounterIntegerQuery, array($which, 'A'));
253 return db_numrows($result);
255 $this->setError(_('Unable to get counter from db')._(': ').db_error());
259 $this->setError('getMonitorCounterInteger:: '._('Missing parameters values.'));
263 function getMonitedByUserIdInArray($who = 0) {
264 if ($who && isset($this->_getMonitoredByUserIdInArrayQuery)) {
265 $result = db_query_params($this->_getMonitoredByUserIdInArrayQuery, array($who));
266 if ($result || db_numrows($result) >= 0) {
267 return util_result_column_to_array($result);
269 $this->setError(_('Unable to get ids from db')._(': ').db_error());
273 $this->setError('getMonitedByUserId:: '._('Missing parameters values.'));
277 function getMonitoredDistinctGroupIdsByUserIdInArray($who = 0) {
278 if ($who && isset($this->_getMonitoredDistinctGroupIdsByUserIdInArrayQuery)) {
279 $result = db_query_params($this->_getMonitoredDistinctGroupIdsByUserIdInArrayQuery, array($who, 'A'));
280 if ($result || db_numrows($result) >= 0) {
281 return util_result_column_to_array($result);
283 $this->setError(_('Unable to get ids from db')._(': ').db_error());
287 $this->setError('getMonitoredDistinctGroupIdsByUserIdInArray:: '._('Missing parameters values.'));
291 function getMonitoredIdsByGroupIdByUserIdInArray($where = 0, $who = 0) {
292 if ($who && isset($this->_getMonitoredIdsByGroupIdByUserIdInArrayQuery)) {
293 $result = db_query_params($this->_getMonitoredIdsByGroupIdByUserIdInArrayQuery, array($where, $who));
294 if ($result || db_numrows($result) >= 0) {
295 return util_result_column_to_array($result);
297 $this->setError(_('Unable to get ids from db')._(': ').db_error());
301 $this->setError('getMonitoredIdsByGroupIdByUserIdInArray:: '._('Missing parameters values.'));
305 function isMonitoredByUserId($which = 0, $who = 0) {
306 if ($which && $who && isset($this->_isMonitoredByUserIdQuery)) {
307 $result = db_query_params($this->_isMonitoredByUserIdQuery, array($which, $who));
308 if ($result && db_numrows($result) == 1) {
313 $this->setError('isMonitoredByUserId:: '._('Missing parameters values.'));
317 function isMonitoredByAny($which = 0) {
318 if ($which && isset($this->_isMonitoredByAnyQuery)) {
319 $result = db_query_params($this->_isMonitoredByAnyQuery, array($which, 'A'));
320 if ($result && db_numrows($result) >= 1) {
325 $this->setError('isMonitoredByAny:: '._('Missing parameters values.'));