Total Complexity | 40 |
Total Lines | 248 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like ReminderItemModule often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ReminderItemModule, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
8 | class ReminderItemModule extends ItemModule { |
||
9 | /** |
||
10 | * Constructor. |
||
11 | * |
||
12 | * @param int $id unique id |
||
13 | * @param array $data list of all actions |
||
14 | */ |
||
15 | public function __construct($id, $data) { |
||
17 | } |
||
18 | |||
19 | /** |
||
20 | * Function is use to set message flags for flagged mail item. |
||
21 | * |
||
22 | * @param object $store MAPI Message Store Object |
||
23 | * @param string $parententryid parent entryid of the message |
||
24 | * @param string $entryid entryid of the message |
||
25 | * @param array $action the action data, sent by the client |
||
26 | */ |
||
27 | #[Override] |
||
52 | } |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Function which is use to dismiss or snooze the reminder item. |
||
57 | * |
||
58 | * @param object $store MAPI Message Store Object |
||
59 | * @param string $parententryid parent entryid of the message |
||
60 | * @param string $entryid entryid of the message |
||
61 | * @param array $action the action data, sent by the client |
||
62 | */ |
||
63 | #[Override] |
||
89 | } |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * Function which is use to snooze the reminder for given time. |
||
94 | * |
||
95 | * @param object $store MAPI Message Store Object |
||
96 | * @param string $entryid entryid of the message |
||
97 | * @param array $action the action data, sent by the client |
||
98 | */ |
||
99 | public function snoozeItem($store, $entryid, $action) { |
||
100 | $result = false; |
||
101 | $message = mapi_msgstore_openentry($store, $entryid); |
||
102 | if ($message) { |
||
103 | $newProps = [PR_ENTRYID => $entryid]; |
||
104 | $props = mapi_getprops($message, $this->properties); |
||
105 | |||
106 | $snoozeTime = $GLOBALS["settings"]->get('zarafa/v1/main/reminder/default_snooze_time', 5); |
||
107 | if (isset($action["message_action"]["snoozeTime"]) && is_numeric($action["message_action"]["snoozeTime"])) { |
||
108 | $snoozeTime = $action["message_action"]["snoozeTime"]; |
||
109 | } |
||
110 | |||
111 | $reminderTime = time() + ($snoozeTime * 60); |
||
112 | if (stripos((string) $props[$this->properties["message_class"]], "IPM.Appointment") === 0) { |
||
113 | if (isset($props[$this->properties["appointment_recurring"]]) && $props[$this->properties["appointment_recurring"]]) { |
||
114 | $recurrence = new Recurrence($store, $message); |
||
115 | $nextReminder = $recurrence->getNextReminderTime(time()); |
||
116 | |||
117 | // flagdueby must be the snooze time or the time of the next instance, whichever is earlier |
||
118 | if ($reminderTime < $nextReminder) { |
||
119 | $newProps[$this->properties["flagdueby"]] = $reminderTime; |
||
120 | } |
||
121 | else { |
||
122 | $newProps[$this->properties["flagdueby"]] = $nextReminder; |
||
123 | } |
||
124 | } |
||
125 | else { |
||
126 | $newProps[$this->properties["flagdueby"]] = $reminderTime; |
||
127 | } |
||
128 | } |
||
129 | else { |
||
130 | $newProps[$this->properties["flagdueby"]] = $reminderTime; |
||
131 | } |
||
132 | |||
133 | // save props |
||
134 | mapi_setprops($message, $newProps); |
||
135 | mapi_savechanges($message); |
||
136 | |||
137 | $result = true; |
||
138 | } |
||
139 | |||
140 | if ($result) { |
||
141 | /* |
||
142 | * @FIXME: Fix notifications for reminders. |
||
143 | * Notifications are currently disabled, because deleting multiple items will notify |
||
144 | * hierarchy multiple time but no data is changed with folder item in hierarchy. |
||
145 | * so it will push same data again which will lead to an error. |
||
146 | */ |
||
147 | // $props = mapi_getprops($message, array(PR_ENTRYID, PR_PARENT_ENTRYID, PR_STORE_ENTRYID)); |
||
148 | // $GLOBALS["bus"]->notify(bin2hex($props[PR_PARENT_ENTRYID]), TABLE_SAVE, $props); |
||
149 | } |
||
150 | $this->sendFeedback($result); |
||
151 | } |
||
152 | |||
153 | /** |
||
154 | * Function which is use to dismiss the reminder. |
||
155 | * |
||
156 | * @param object $store MAPI Message Store Object |
||
157 | * @param string $entryid entryid of the message |
||
158 | */ |
||
159 | public function dismissItem($store, $entryid) { |
||
160 | $result = false; |
||
161 | $message = mapi_msgstore_openentry($store, $entryid); |
||
162 | if ($message) { |
||
163 | $newProps = []; |
||
164 | $props = mapi_getprops($message, $this->properties); |
||
165 | |||
166 | if (stripos((string) $props[$this->properties["message_class"]], "IPM.Appointment") === 0) { |
||
167 | if (isset($props[$this->properties["appointment_recurring"]]) && $props[$this->properties["appointment_recurring"]]) { |
||
168 | $recurrence = new Recurrence($store, $message); |
||
169 | // check for next reminder after "now" for the next instance |
||
170 | $nextReminder = $recurrence->getNextReminderTime(time()); |
||
171 | if ($nextReminder) { |
||
172 | $newProps[$this->properties["flagdueby"]] = $nextReminder; |
||
173 | } |
||
174 | else { |
||
175 | $newProps[$this->properties["reminder"]] = false; |
||
176 | } |
||
177 | } |
||
178 | else { |
||
179 | $newProps[$this->properties["reminder"]] = false; |
||
180 | } |
||
181 | } |
||
182 | elseif (stripos((string) $props[$this->properties["message_class"]], "IPM.Task") === 0) { |
||
183 | $newProps[$this->properties["reminder"]] = false; |
||
184 | |||
185 | if (isset($props[$this->properties['task_recurring']]) && $props[$this->properties['task_recurring']] == 1) { |
||
186 | $newProps[$this->properties['task_resetreminder']] = true; |
||
187 | } |
||
188 | } |
||
189 | else { |
||
190 | $newProps[$this->properties["reminder"]] = false; |
||
191 | } |
||
192 | |||
193 | // save props |
||
194 | mapi_setprops($message, $newProps); |
||
195 | mapi_savechanges($message); |
||
196 | |||
197 | $result = true; |
||
198 | } |
||
199 | |||
200 | if ($result) { |
||
201 | /* |
||
202 | * @FIXME: Fix notifications for reminders. |
||
203 | * Notifications are currently disabled, because deleting multiple items will notify |
||
204 | * hierarchy multiple time but no data is changed with folder item in hierarchy. |
||
205 | * so it will push same data again which will lead to an error. |
||
206 | */ |
||
207 | // $props = mapi_getprops($message, array(PR_ENTRYID, PR_PARENT_ENTRYID, PR_STORE_ENTRYID)); |
||
208 | // $GLOBALS["bus"]->notify(bin2hex($props[PR_PARENT_ENTRYID]), TABLE_SAVE, $props); |
||
209 | } |
||
210 | $this->sendFeedback($result); |
||
211 | } |
||
212 | |||
213 | /** |
||
214 | * Function does customization of exception based on module data. |
||
215 | * like, here it will generate display message based on actionType |
||
216 | * for particular exception. |
||
217 | * |
||
218 | * @param object $e Exception object |
||
219 | * @param string $actionType the action type, sent by the client |
||
220 | * @param MAPIobject $store store object of message |
||
221 | * @param string $parententryid parent entryid of the message |
||
222 | * @param string $entryid entryid of the message |
||
223 | * @param array $action the action data, sent by the client |
||
224 | */ |
||
225 | #[Override] |
||
256 | } |
||
257 | } |
||
258 |