XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
NotifyListAction.class.php
1<?php
11
12if (!defined('XOOPS_ROOT_PATH')) {
13 exit();
14}
15
16require_once XOOPS_ROOT_PATH . '/include/notification_functions.php';
17
18require_once XOOPS_MODULE_PATH . '/legacy/forms/NotifyDeleteForm.class.php';
19
20/***
21 * @internal
22 * List up notifications. This action is like notifications.php (when $op is
23 * 'list').
24 */
25class Legacy_NotifyListAction extends Legacy_Action
26{
27 public $mModules = [];
28 public $mActionForm = null;
29
30 public function prepare(&$controller, &$xoopsUser)
31 {
32 $root =& $controller->mRoot;
33 $root->mLanguageManager->loadPageTypeMessageCatalog('notification');
34 $root->mLanguageManager->loadModuleMessageCatalog('legacy');
35
36 $this->mActionForm =new Legacy_NotifyDeleteForm();
37 $this->mActionForm->prepare();
38 }
39
40 public function hasPermission(&$controller, &$xoopsUser)
41 {
42 return is_object($xoopsUser);
43 }
44
45 public function getDefaultView(&$contoller, &$xoopsUser)
46 {
47 $criteria =new Criteria('not_uid', $xoopsUser->get('uid'));
48 $criteria->setSort('not_modid, not_category, not_itemid');
49
50 $handler =& xoops_gethandler('notification');
51 $notificationArr =& $handler->getObjects($criteria);
52
53 $moduleHandler =& xoops_gethandler('module');
54
55 $prev_modid = -1;
56 $prev_category = -1;
57 $prev_item = -1;
58 foreach ($notificationArr as $notify) {
59 $t_modid = $notify->get('not_modid');
60
61 $module =& $moduleHandler->get($t_modid);
62 if (!is_object($module)) {
63 continue;
64 }
65
66 if ($t_modid != $prev_modid) {
67 $prev_modid = $t_modid;
68 $prev_category = -1;
69 $prev_item = -1;
70
71 $this->mModules[$t_modid] = [
72 'id' => $t_modid,
73 'name' => $module->getShow('name'),
74 'categories' => []
75 ];
76
77
78 //
79 // [ToDo] (Original)
80 // note, we could auto-generate the url from the id
81 // and category info... (except when category has multiple
82 // subscription scripts defined...)
83 // OR, add one more option to xoops_version 'view_from'
84 // which tells us where to redirect... BUT, e.g. forums, it
85 // still wouldn't give us all the required info... e.g. the
86 // topic ID doesn't give us the ID of the forum which is
87 // a required argument...
88
89 //
90 // Get the lookup function, if exists
91 //
92 $notifyConfig = $module->getInfo('notification');
93 $lookupFunc = '';
94 if (!empty($notifyConfig['lookup_file'])) {
95 $t_filepath = XOOPS_ROOT_PATH . '/modules/' . $module->get('dirname') . '/' . $notifyConfig['lookup_file'];
96 if (file_exists($t_filepath)) {
97 require_once $t_filepath;
98 if (!empty($notifyConfig['lookup_func']) && function_exists($notifyConfig['lookup_func'])) {
99 $lookupFunc = $notifyConfig['lookup_func'];
100 }
101 }
102 }
103 }
104
105 $t_category = $notify->get('not_category');
106 if ($t_category != $prev_category) {
107 $prev_category = $t_category;
108 $prev_item = -1;
109 $categoryInfo =& notificationCategoryInfo($t_category, $t_modid);
110 }
111
112 $t_item = $notify->get('not_itemid');
113 if ($t_item != $prev_item) {
114 $prev_item = $t_item;
115 if (!empty($lookupFunc)) {
116 $itemInfo = $lookupFunc($t_category, $t_item);
117 } else {
118 $itemInfo = ['name' => '[' . _NOT_NAMENOTAVAILABLE . ']', 'url' => ''];
119 }
120 $this->mModules[$t_modid]['categories'][$t_category]['items'][$t_item] = [
121 'id' => $t_item,
122 'name' => $itemInfo['name'],
123 'url' => $itemInfo['url'],
124 'notifications' => []
125 ];
126 }
127
128 $eventInfo =& notificationEventInfo($t_category, $notify->get('not_event'), $notify->get('not_modid'));
129 $this->mModules[$t_modid]['categories'][$t_category]['items'][$t_item]['notifications'][] = [
130 'id' => $notify->get('not_id'),
131 'module_id' => $notify->get('not_modid'),
132 'category' => $notify->get('not_category'),
133 'category_title' => $categoryInfo['title'],
134 'item_id' => $notify->get('not_itemid'),
135 'event' => $notify->get('not_event'),
136 'event_title' => $eventInfo['title'],
137 'user_id' => $notify->get('not_uid')
138 ];
139 }
140
141 return LEGACY_FRAME_VIEW_INDEX;
142 }
143
144 public function executeViewIndex(&$controller, &$xoopsUser, &$render)
145 {
146 $render->setTemplateName('legacy_notification_list.html');
147
148 $render->setAttribute('modules', $this->mModules);
149 $render->setAttribute('currentUser', $xoopsUser);
150 $render->setAttribute('actionForm', $this->mActionForm);
151 }
152
153 public function executeViewError(&$controller, &$xoopsUser, &$render)
154 {
155 $controller->executeForward('./index.php?action=NotifyList');
156 }
157}