XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
notification.php
1<?php
13
14if (!defined('XOOPS_ROOT_PATH')) {
15 exit();
16}
17// RMV-NOTIFY
18include_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
19include_once XOOPS_ROOT_PATH . '/include/notification_functions.php';
20
28class XoopsNotification extends XoopsObject
29{
30
31 public function __construct()
32 {
33 parent::__construct();
34 $this->initVar('not_id', XOBJ_DTYPE_INT, null, false);
35 $this->initVar('not_modid', XOBJ_DTYPE_INT, null, false);
36 $this->initVar('not_category', XOBJ_DTYPE_TXTBOX, null, false, 30);
37 $this->initVar('not_itemid', XOBJ_DTYPE_INT, 0, false);
38 $this->initVar('not_event', XOBJ_DTYPE_TXTBOX, null, false, 30);
39 $this->initVar('not_uid', XOBJ_DTYPE_INT, 0, true);
40 $this->initVar('not_mode', XOBJ_DTYPE_INT, 0, false);
41 }
42 public function XoopsNotification()
43 {
44 return self::__construct();
45 }
46
47// FIXME:???
48// To send email to multiple users simultaneously, we would need to move
49// the notify functionality to the handler class. BUT, some of the tags
50// are user-dependent, so every email msg will be unique. (Unless maybe use
51// smarty for email templates in the future.) Also we would have to keep
52// track if each user wanted email or PM.
53
65 public function notifyUser($template_dir, $template, $subject, $tags, $onshutdown = false)
66 {
67 if (! $onshutdown) {
68 // regist as shutdown function
69 ignore_user_abort(true);
70 register_shutdown_function([$this, 'notifyUser'], $template_dir, $template, $subject, $tags, true);
71 return true;
72 }
73
74 // execution at onshutdown
75
76 // push current output all the way to the browser
77 header('Connection: close', true);
78 while (ob_get_level()) {
79 $len = ob_get_length();
80 if (false !== $len) {
81 header('Content-Length: '.$len, true);
82 }
83 @ob_end_flush();
84 }
85 flush();
86
87 // Check the user's notification preference.
88
89 $member_handler = xoops_gethandler('member');
90 $user =& $member_handler->getUser($this->getVar('not_uid'));
91 if (!is_object($user)) {
92 return true;
93 }
94 $method = $user->getVar('notify_method');
95
96 $xoopsMailer =& getMailer();
97 include_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
98 switch ($method) {
99 case XOOPS_NOTIFICATION_METHOD_PM:
100 $xoopsMailer->usePM();
101 $config_handler = xoops_gethandler('config');
102 $xoopsMailerConfig =& $config_handler->getConfigsByCat(XOOPS_CONF_MAILER);
103 $xoopsMailer->setFromUser($member_handler->getUser($xoopsMailerConfig['fromuid']));
104 foreach ($tags as $k=>$v) {
105 $xoopsMailer->assign($k, $v);
106 }
107 break;
108 case XOOPS_NOTIFICATION_METHOD_EMAIL:
109 $xoopsMailer->useMail();
110 foreach ($tags as $k=>$v) {
111 $xoopsMailer->assign($k, preg_replace('/&amp;/i', '&', $v));
112 }
113 break;
114 default:
115 return true; // report error in user's profile??
116 break;
117 }
118
119 // Set up the mailer
120 $xoopsMailer->setTemplateDir($template_dir);
121 $xoopsMailer->setTemplate($template);
122 $xoopsMailer->setToUsers($user);
123 //global $xoopsConfig;
124 //$xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
125 //$xoopsMailer->setFromName($xoopsConfig['sitename']);
126 if (defined('XOOPS_NOTIFY_FROM_EMAIL')) {
127 $xoopsMailer->setFromEmail(XOOPS_NOTIFY_FROM_EMAIL);
128 }
129 if (defined('XOOPS_NOTIFY_FROM_NAME')) {
130 $xoopsMailer->setFromName(XOOPS_NOTIFY_FROM_NAME);
131 }
132 $xoopsMailer->setSubject($subject);
133 $success = $xoopsMailer->send();
134
135 // If send-once-then-delete, delete notification
136 // If send-once-then-wait, disable notification
137
138 include_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
139 $notification_handler = xoops_gethandler('notification');
140
141 if (XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE == $this->getVar('not_mode')) {
142 $notification_handler->delete($this);
143 return $success;
144 }
145
146 if (XOOPS_NOTIFICATION_MODE_SENDONCETHENWAIT == $this->getVar('not_mode')) {
147 $this->setVar('not_mode', XOOPS_NOTIFICATION_MODE_WAITFORLOGIN);
148 $notification_handler->insert($this);
149 }
150 return $success;
151 }
152}
153
167class XoopsNotificationHandler extends XoopsObjectHandler
168{
172 public $mTrigger = null;
173
177 public $mTriggerPreAction = null;
178
179 public function __construct(&$db)
180 {
181 parent::__construct($db);
182
183 $this->mTrigger =new XCube_Delegate();
184 $this->mTrigger->register('XoopsNotificationHandler.Trigger');
185
186 $this->mTriggerPreAction =new XCube_Delegate();
187 $this->mTriggerPreAction->register('XoopsNotificationHandler.TriggerPreAction');
188 }
189 public function XoopsNotificationHandler(&$db)
190 {
191 return self::__construct($db);
192 }
193
194 protected function _escapeValue($value, $type=XOBJ_DTYPE_STRING)
195 {
196 switch ($type) {
197 case XOBJ_DTYPE_BOOL:
198 $value = $value ? '1' : '0';
199 break;
200 case XOBJ_DTYPE_INT:
201 $value = (int)$value;
202 break;
203 case XOBJ_DTYPE_FLOAT:
204 $value = (float)$value;
205 break;
206 case XOBJ_DTYPE_STRING:
207 case XOBJ_DTYPE_TEXT:
208 default:
209 $value = $this->db->quoteString($value);
210 $value = substr($value, 1, strlen($value)-2);
211 }
212 return $value;
213 }
214
222 public function &create($isNew = true)
223 {
224 $notification =new XoopsNotification();
225 if ($isNew) {
226 $notification->setNew();
227 }
228 return $notification;
229 }
230
231
239 public function &get($id)
240 {
241 $id = (int)$id;
242 $ret = false;
243 if ($id > 0) {
244 $sql = 'SELECT * FROM '.$this->db->prefix('xoopsnotifications').' WHERE not_id='.$id;
245 if ($result = $this->db->query($sql)) {
246 $numrows = $this->db->getRowsNum($result);
247 if (1 == $numrows) {
248 $notification =new XoopsNotification();
249 $notification->assignVars($this->db->fetchArray($result));
250 $ret =& $notification;
251 }
252 }
253 }
254 return $ret;
255 }
256
264 public function insert(&$notification)
265 {
266 $not_modid = null;
267 $not_itemid = null;
268 $not_category = null;
269 $not_uid = null;
270 $not_event = null;
271 $not_mode = null;
272 $not_id = null;
273 if ('xoopsnotification' != strtolower(get_class($notification))) {
274 return false;
275 }
276 if (!$notification->isDirty()) {
277 return true;
278 }
279 if (!$notification->cleanVars()) {
280 return false;
281 }
282 foreach ($notification->cleanVars as $k => $v) {
283 ${$k} = $v;
284 }
285 if ($notification->isNew()) {
286 $not_id = $this->db->genId('xoopsnotifications_not_id_seq');
287 $sql = sprintf('INSERT INTO %s (not_id, not_modid, not_itemid, not_category, not_uid, not_event, not_mode) VALUES (%u, %u, %u, %s, %u, %s, %u)', $this->db->prefix('xoopsnotifications'), $not_id, $not_modid, $not_itemid, $this->db->quoteString($not_category), $not_uid, $this->db->quoteString($not_event), $not_mode);
288 } else {
289 $sql = sprintf('UPDATE %s SET not_modid = %u, not_itemid = %u, not_category = %s, not_uid = %u, not_event = %s, not_mode = %u WHERE not_id = %u', $this->db->prefix('xoopsnotifications'), $not_modid, $not_itemid, $this->db->quoteString($not_category), $not_uid, $this->db->quoteString($not_event), $not_mode, $not_id);
290 }
291 if (!$result = $this->db->query($sql)) {
292 return false;
293 }
294 if (empty($not_id)) {
295 $not_id = $this->db->getInsertId();
296 }
297 $notification->assignVar('not_id', $not_id);
298 return true;
299 }
300
308 public function delete(&$notification)
309 {
310 if ('xoopsnotification' != strtolower(get_class($notification))) {
311 return false;
312 }
313 $sql = sprintf('DELETE FROM %s WHERE not_id = %u', $this->db->prefix('xoopsnotifications'), $notification->getVar('not_id'));
314 if (!$result = $this->db->query($sql)) {
315 return false;
316 }
317 return true;
318 }
319
328 public function &getObjects($criteria = null, $id_as_key = false)
329 {
330 $ret = [];
331 $limit = $start = 0;
332 $sql = 'SELECT * FROM '.$this->db->prefix('xoopsnotifications');
333 if (isset($criteria) && $criteria instanceof \criteriaelement) {
334 $sql .= ' '.$criteria->renderWhere();
335 $sort = ('' != $criteria->getSort()) ? $criteria->getSort() : 'not_id';
336 $sql .= ' ORDER BY '.$sort.' '.$criteria->getOrder();
337 $limit = $criteria->getLimit();
338 $start = $criteria->getStart();
339 }
340 $result = $this->db->query($sql, $limit, $start);
341 if (!$result) {
342 return $ret;
343 }
344 while ($myrow = $this->db->fetchArray($result)) {
345 $notification =new XoopsNotification();
346 $notification->assignVars($myrow);
347 if (!$id_as_key) {
348 $ret[] =& $notification;
349 } else {
350 $ret[$myrow['not_id']] =& $notification;
351 }
352 unset($notification);
353 }
354 return $ret;
355 }
356
357// TODO: Need this??
365 public function getCount($criteria = null)
366 {
367 $sql = 'SELECT COUNT(*) FROM '.$this->db->prefix('xoopsnotifications');
368 if (isset($criteria) && $criteria instanceof \criteriaelement) {
369 $sql .= ' '.$criteria->renderWhere();
370 }
371 if (!$result =& $this->db->query($sql)) {
372 return 0;
373 }
374 [$count] = $this->db->fetchRow($result);
375 return $count;
376 }
377
385 public function deleteAll($criteria = null)
386 {
387 $sql = 'DELETE FROM '.$this->db->prefix('xoopsnotifications');
388 if (isset($criteria) && $criteria instanceof \criteriaelement) {
389 $sql .= ' '.$criteria->renderWhere();
390 }
391 if (!$result = $this->db->query($sql)) {
392 return false;
393 }
394 return true;
395 }
396
397// Need this??
408/*
409 function updateAll($fieldname, $fieldvalue, $criteria = null)
410 {
411 $set_clause = is_numeric($fieldvalue) ? $filedname.' = '.$fieldvalue : $filedname." = '".$fieldvalue."'";
412 $sql = 'UPDATE '.$this->db->prefix('xoopsnotifications').' SET '.$set_clause;
413 if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
414 $sql .= ' '.$criteria->renderWhere();
415 }
416 if (!$result = $this->db->query($sql)) {
417 return false;
418 }
419 return true;
420 }
421*/
422
423 // TODO: rename this...
424 // Also, should we have get by module, get by category, etc...??
425
426 public function &getNotification($module_id, $category, $item_id, $event, $user_id)
427 {
428 $ret = false;
429 $criteria = new CriteriaCompo();
430 $criteria->add(new Criteria('not_modid', (int)$module_id));
431 $criteria->add(new Criteria('not_category', $this->_escapeValue($category)));
432 $criteria->add(new Criteria('not_itemid', (int)$item_id));
433 $criteria->add(new Criteria('not_event', $this->_escapeValue($event)));
434 $criteria->add(new Criteria('not_uid', (int)$user_id));
435 $objects = $this->getObjects($criteria);
436 if (1 == count($objects)) {
437 $ret =& $objects[0];
438 }
439 return $ret;
440 }
441
454
455 public function isSubscribed($category, $item_id, $event, $module_id, $user_id)
456 {
457 $criteria = new CriteriaCompo();
458 $criteria->add(new Criteria('not_modid', (int)$module_id));
459 $criteria->add(new Criteria('not_category', $this->_escapeValue($category)));
460 $criteria->add(new Criteria('not_itemid', (int)$item_id));
461 $criteria->add(new Criteria('not_event', $this->_escapeValue($event)));
462 $criteria->add(new Criteria('not_uid', (int)$user_id));
463 return $this->getCount($criteria);
464 }
465
466
467 // TODO: how about a function to subscribe a whole group of users???
468 // e.g. if we want to add all moderators to be notified of subscription
469 // of new threads...
470
484 public function subscribe($category, $item_id, $events, $mode=null, $module_id=null, $user_id=null)
485 {
486 if (!isset($user_id)) {
487 global $xoopsUser;
488 if (empty($xoopsUser)) {
489 return false; // anonymous cannot subscribe
490 } else {
491 $user_id = $xoopsUser->getVar('uid');
492 }
493 }
494
495 if (!isset($module_id)) {
496 global $xoopsModule;
497 $module_id = $xoopsModule->getVar('mid');
498 }
499
500 if (!isset($mode)) {
501 $user = new XoopsUser($user_id);
502 $mode = $user->getVar('notify_mode');
503 }
504
505 if (!is_array($events)) {
506 $events = [$events];
507 }
508 foreach ($events as $event) {
509 if ($notification =& $this->getNotification($module_id, $category, $item_id, $event, $user_id)) {
510 if ($notification->getVar('not_mode') != $mode) {
511 $this->updateByField($notification, 'not_mode', $mode);
512 }
513 } else {
514 $notification =& $this->create();
515 $notification->setVar('not_modid', $module_id);
516 $notification->setVar('not_category', $this->_escapeValue($category));
517 $notification->setVar('not_itemid', $item_id);
518 $notification->setVar('not_uid', $user_id);
519 $notification->setVar('not_event', $this->_escapeValue($event));
520 $notification->setVar('not_mode', $mode);
521 $this->insert($notification);
522 }
523 }
524 }
525
526
527// TODO: this will be to provide a list of everything a particular
528// user has subscribed to... e.g. for on the 'Profile' page, similar
529// to how we see the various posts etc. that the user has made.
530// We may also want to have a function where we can specify module id
538 public function &getByUser($user_id)
539 {
540 $criteria = new Criteria('not_uid', $user_id);
541 return $this->getObjects($criteria, true);
542 }
543
544 // TODO: rename this??
545
555 public function &getSubscribedEvents($category, $item_id, $module_id, $user_id)
556 {
557 $criteria = new CriteriaCompo();
558 $criteria->add(new Criteria('not_modid', $module_id));
559 $criteria->add(new Criteria('not_category', $this->_escapeValue($category)));
560 if ($item_id) {
561 $criteria->add(new Criteria('not_itemid', $item_id));
562 }
563 $criteria->add(new Criteria('not_uid', $user_id));
564 $results = $this->getObjects($criteria, true);
565 $ret = [];
566 foreach (array_keys($results) as $i) {
567 $ret[] = $results[$i]->getVar('not_event');
568 }
569 return $ret;
570 }
571
572// TODO: is this a useful function?? (Copied from comment_handler)
573
584 public function &getByItemId($module_id, $item_id, $order = null, $status = null)
585 {
586 $criteria = new CriteriaCompo(new Criteria('com_modid', (int)$module_id));
587 $criteria->add(new Criteria('com_itemid', (int)$item_id));
588 if (isset($status)) {
589 $criteria->add(new Criteria('com_status', (int)$status));
590 }
591 if (isset($order)) {
592 $criteria->setOrder($order);
593 }
594 $ret =& $this->getObjects($criteria);
595 return $ret;
596 }
597
598
611 // TODO:(?) - pass in an event LIST. This will help to avoid
612 // problem of sending people multiple emails for similar events.
613 // BUT, then we need an array of mail templates, etc... Unless
614 // mail templates can include logic in the future, then we can
615 // tailor the mail so it makes sense for any of the possible
616 // (or combination of) events.
617
618 public function triggerEvents($category, $item_id, $events, $extra_tags= [], $user_list= [], $module_id=null, $omit_user_id=null)
619 {
620 if (!is_array($events)) {
621 $events = [$events];
622 }
623 foreach ($events as $event) {
624 $this->triggerEvent($category, $item_id, $event, $extra_tags, $user_list, $module_id, $omit_user_id);
625 }
626 }
627
628 public function triggerEvent($category, $item_id, $event, $extra_tags= [], $user_list= [], $module_id=null, $omit_user_id=null)
629 {
630 $item_info = [];
631 if (!isset($module_id)) {
632 global $xoopsModule;
633 $module =& $xoopsModule;
634 $module_id = !empty($xoopsModule) ? $xoopsModule->getVar('mid') : 0;
635 } else {
636 $module_handler = xoops_gethandler('module');
637 $module =& $module_handler->get($module_id);
638 }
639 // Get Config Array form xoops_version.php
640 $not_config = $module->getInfo('notification');
641 //
642 $event_correct = false;
643 foreach ($not_config['event'] as $event_config) {
644 if (($event_config['name'] == $event)&&($event_config['category'] == $category)) {
645 $event_correct = true;
646 break;
647 }
648 }
649 // RaiseEvent 'XoopsNotificationHandler.Trigger' ('Legacy.Notify.Trigger')
650 // Delegate may hanldle notified event
651 // varArgs :
652 // 'category' [I] : Paramater $category of triggerEvent()
653 // 'event' [I] : Paramater $event of triggerEvent()
654 // 'itemId' [I] : Paramater $item_id of triggerEvent()
655 // 'extraTags' [I] : Paramater $extra_tags of triggerEvent()
656 // 'userList' [I] : Paramater $user_list of triggerEvent()
657 // 'omitUid' [I] : Paramater $omit_user_id of triggerEvent()
658 // 'module' [I] : Paramater $module_id of triggerEvent() , or currenr $xoopsModule
659 // 'eventConfig' [I] : $modversion['notification'] Array , defined in xoops_version.php
660 // 'force_return' [O] : If force return this triggerEvents method, set it True
661 //
662 if ($event_correct) {
663 /*
664 $varArgs = array('category' => $category,
665 'event' => $event,
666 'itemId' => $item_id,
667 'extraTags' => $extra_tags,
668 'module' => &$module,
669 'userList' => $user_list,
670 'omitUid' => $omit_user_id,
671 'eventConfig' => $not_config,
672 'force_return' => false,
673 );*/
674
675 $force_return = false;
676
677 $this->mTriggerPreAction->call(new XCube_Ref($category), new XCube_Ref($event), new XCube_Ref($item_id),
678 new XCube_Ref($extra_tags), new XCube_Ref($module), new XCube_Ref($user_list),
679 new XCube_Ref($omit_user_id), new XCube_Ref($not_config),
680 new XCube_Ref($force_return));
681
682 $this->mTrigger->call($category, $event, $item_id, $extra_tags, new XCube_Ref($module), $user_list, $omit_user_id, $not_config, new XCube_Ref($force_return));
683 if ($force_return) {
684 return;
685 }
686 }
687
688 // Check if event is enabled
689 $config_handler = xoops_gethandler('config');
690 $mod_config =& $config_handler->getConfigsByCat(0, $module->getVar('mid'));
691 if (empty($mod_config['notification_enabled'])) {
692 return false;
693 }
694 $category_info =& notificationCategoryInfo($category, $module_id);
695 $event_info =& notificationEventInfo($category, $event, $module_id);
696 if (!in_array(notificationGenerateConfig($category_info, $event_info, 'option_name'), $mod_config['notification_events']) && empty($event_info['invisible'])) {
697 return false;
698 }
699
700 if (!isset($omit_user_id)) {
701 global $xoopsUser;
702 if (!empty($xoopsUser)) {
703 $omit_user_id = $xoopsUser->getVar('uid');
704 } else {
705 $omit_user_id = 0;
706 }
707 }
708 $criteria = new CriteriaCompo();
709 $criteria->add(new Criteria('not_modid', (int)$module_id));
710 $criteria->add(new Criteria('not_category', $this->_escapeValue($category)));
711 $criteria->add(new Criteria('not_itemid', (int)$item_id));
712 $criteria->add(new Criteria('not_event', $this->_escapeValue($event)));
713 $mode_criteria = new CriteriaCompo();
714 $mode_criteria->add(new Criteria('not_mode', XOOPS_NOTIFICATION_MODE_SENDALWAYS), 'OR');
715 $mode_criteria->add(new Criteria('not_mode', XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE), 'OR');
716 $mode_criteria->add(new Criteria('not_mode', XOOPS_NOTIFICATION_MODE_SENDONCETHENWAIT), 'OR');
717 $criteria->add($mode_criteria);
718 if (!empty($user_list)) {
719 $user_criteria = new CriteriaCompo();
720 foreach ($user_list as $user) {
721 $user_criteria->add(new Criteria('not_uid', $user), 'OR');
722 }
723 $criteria->add($user_criteria);
724 }
725 $notifications =& $this->getObjects($criteria);
726 if (empty($notifications)) {
727 return;
728 }
729
730 // Add some tag substitutions here
731
732 $tags = [];
733 if (!empty($not_config)) {
734 if (!empty($not_config['tags_file'])) {
735 $tags_file = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname') . '/' . $not_config['tags_file'];
736 if (file_exists($tags_file)) {
737 include_once $tags_file;
738 if (!empty($not_config['tags_func'])) {
739 $tags_func = $not_config['tags_func'];
740 if (function_exists($tags_func)) {
741 $tags = $tags_func($category, (int)$item_id, $event);
742 }
743 }
744 }
745 }
746 // RMV-NEW
747 if (!empty($not_config['lookup_file'])) {
748 $lookup_file = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname') . '/' . $not_config['lookup_file'];
749 if (file_exists($lookup_file)) {
750 include_once $lookup_file;
751 if (!empty($not_config['lookup_func'])) {
752 $lookup_func = $not_config['lookup_func'];
753 if (function_exists($lookup_func)) {
754 $item_info = $lookup_func($category, (int)$item_id);
755 }
756 }
757 }
758 }
759 }
760 $tags['X_ITEM_NAME'] = !empty($item_info['name']) ? $item_info['name'] : '[' . _NOT_ITEMNAMENOTAVAILABLE . ']';
761 $tags['X_ITEM_URL'] = !empty($item_info['url']) ? $item_info['url'] : '[' . _NOT_ITEMURLNOTAVAILABLE . ']';
762 $tags['X_ITEM_TYPE'] = !empty($category_info['item_name']) ? $category_info['title'] : '[' . _NOT_ITEMTYPENOTAVAILABLE . ']';
763 $tags['X_MODULE'] = $module->getVar('name', 'n');
764 $tags['X_MODULE_URL'] = XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/';
765 $tags['X_NOTIFY_CATEGORY'] = $category;
766 $tags['X_NOTIFY_EVENT'] = $event;
767
768 $template_dir = $event_info['mail_template_dir'];
769 $template = $event_info['mail_template'] . '.tpl';
770 $subject = $event_info['mail_subject'];
771
772 foreach ($notifications as $notification) {
773 if (empty($omit_user_id) || $notification->getVar('not_uid') != $omit_user_id) {
774 // user-specific tags
775 //$tags['X_UNSUBSCRIBE_URL'] = 'TODO';
776 // TODO: don't show unsubscribe link if it is 'one-time' ??
777 $tags['X_UNSUBSCRIBE_URL'] = XOOPS_URL . '/notifications.php';
778 $tags = array_merge($tags, $extra_tags);
779
780 $notification->notifyUser($template_dir, $template, $subject, $tags);
781 }
782 }
783 }
784
785
792 public function unsubscribeByUser($user_id)
793 {
794 $criteria = new Criteria('not_uid', (int)$user_id);
795 return $this->deleteAll($criteria);
796 }
797
798
799// TODO: allow these to use current module, etc...
800
812
813 public function unsubscribe($category, $item_id, $events, $module_id=null, $user_id=null)
814 {
815 if (!isset($user_id)) {
816 global $xoopsUser;
817 if (empty($xoopsUser)) {
818 return false; // anonymous cannot subscribe
819 } else {
820 $user_id = $xoopsUser->getVar('uid');
821 }
822 }
823
824 if (!isset($module_id)) {
825 global $xoopsModule;
826 $module_id = $xoopsModule->getVar('mid');
827 }
828
829 $criteria = new CriteriaCompo();
830 $criteria->add(new Criteria('not_modid', (int)$module_id));
831 $criteria->add(new Criteria('not_category', $this->_escapeValue($category)));
832 $criteria->add(new Criteria('not_itemid', (int)$item_id));
833 $criteria->add(new Criteria('not_uid', (int)$user_id));
834 if (!is_array($events)) {
835 $events = [$events];
836 }
837 $event_criteria = new CriteriaCompo();
838 foreach ($events as $event) {
839 $event_criteria->add(new Criteria('not_event', $this->_escapeValue($event)), 'OR');
840 }
841 $criteria->add($event_criteria);
842 return $this->deleteAll($criteria);
843 }
844
845
846 // TODO: When 'update' a module, may need to switch around some
847 // notification classes/IDs... or delete the ones that no longer
848 // exist.
849
856 public function unsubscribeByModule($module_id)
857 {
858 $criteria = new Criteria('not_modid', (int)$module_id);
859 return $this->deleteAll($criteria);
860 }
861
862
872 public function unsubscribeByItem($module_id, $category, $item_id)
873 {
874 $criteria = new CriteriaCompo();
875 $criteria->add(new Criteria('not_modid', (int)$module_id));
876 $criteria->add(new Criteria('not_category', $this->_escapeValue($category)));
877 $criteria->add(new Criteria('not_itemid', (int)$item_id));
878 return $this->deleteAll($criteria);
879 }
880
881
890 public function doLoginMaintenance($user_id)
891 {
892 $criteria = new CriteriaCompo();
893 $criteria->add(new Criteria('not_uid', (int)$user_id));
894 $criteria->add(new Criteria('not_mode', XOOPS_NOTIFICATION_MODE_WAITFORLOGIN));
895
896 $notifications = $this->getObjects($criteria, true);
897 foreach ($notifications as $n) {
898 $n->setVar('not_mode', XOOPS_NOTIFICATION_MODE_SENDONCETHENWAIT);
899 $this->insert($n);
900 }
901 }
902
903
913 public function updateByField(&$notification, $field_name, $field_value)
914 {
915 $notification->unsetNew();
916 $notification->setVar($field_name, $field_value);
917 return $this->insert($notification);
918 }
919}
[Final] Used for the simple mechanism for common delegation in XCube.
& getObjects($criteria=null, $id_as_key=false)
& getSubscribedEvents($category, $item_id, $module_id, $user_id)
deleteAll($criteria=null)
& getNotification($module_id, $category, $item_id, $event, $user_id)
subscribe($category, $item_id, $events, $mode=null, $module_id=null, $user_id=null)
updateByField(&$notification, $field_name, $field_value)
isSubscribed($category, $item_id, $event, $module_id, $user_id)
triggerEvents($category, $item_id, $events, $extra_tags=[], $user_list=[], $module_id=null, $omit_user_id=null)
unsubscribe($category, $item_id, $events, $module_id=null, $user_id=null)
& getByItemId($module_id, $item_id, $order=null, $status=null)
unsubscribeByItem($module_id, $category, $item_id)
notifyUser($template_dir, $template, $subject, $tags, $onshutdown=false)
setVar($key, $value, $not_gpc=false)
Definition object.php:250
initVar($key, $data_type, $value=null, $required=false, $maxlength=null, $options='')
Definition object.php:206
& getVar($key, $format='s')
Definition object.php:317