| Total Complexity | 41 |
| Total Lines | 249 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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) { |
||
| 16 | parent::__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 | * @return bool true on success or false on failure |
||
| 28 | */ |
||
| 29 | public function save($store, $parententryid, $entryid, $action) { |
||
| 53 | } |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Function which is use to dismiss or snooze the reminder item. |
||
| 58 | * |
||
| 59 | * @param object $store MAPI Message Store Object |
||
| 60 | * @param string $parententryid parent entryid of the message |
||
| 61 | * @param string $entryid entryid of the message |
||
| 62 | * @param array $action the action data, sent by the client |
||
| 63 | * |
||
| 64 | * @return bool true on success or false on failure |
||
| 65 | */ |
||
| 66 | public function delete($store, $parententryid, $entryid, $action) { |
||
| 91 | } |
||
| 92 | } |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Function which is use to snooze the reminder for given time. |
||
| 96 | * |
||
| 97 | * @param object $store MAPI Message Store Object |
||
| 98 | * @param string $entryid entryid of the message |
||
| 99 | * @param array $action the action data, sent by the client |
||
| 100 | */ |
||
| 101 | public function snoozeItem($store, $entryid, $action) { |
||
| 102 | $result = false; |
||
| 103 | $message = mapi_msgstore_openentry($store, $entryid); |
||
| 104 | if ($message) { |
||
| 105 | $newProps = [PR_ENTRYID => $entryid]; |
||
| 106 | $props = mapi_getprops($message, $this->properties); |
||
| 107 | |||
| 108 | $snoozeTime = $GLOBALS["settings"]->get('zarafa/v1/main/reminder/default_snooze_time', 5); |
||
| 109 | if (isset($action["message_action"]["snoozeTime"]) && is_numeric($action["message_action"]["snoozeTime"])) { |
||
| 110 | $snoozeTime = $action["message_action"]["snoozeTime"]; |
||
| 111 | } |
||
| 112 | |||
| 113 | $reminderTime = time() + ($snoozeTime * 60); |
||
| 114 | if (stripos($props[$this->properties["message_class"]], "IPM.Appointment") === 0) { |
||
| 115 | if (isset($props[$this->properties["appointment_recurring"]]) && $props[$this->properties["appointment_recurring"]]) { |
||
| 116 | $recurrence = new Recurrence($store, $message); |
||
| 117 | $nextReminder = $recurrence->getNextReminderTime(time()); |
||
| 118 | |||
| 119 | // flagdueby must be the snooze time or the time of the next instance, whichever is earlier |
||
| 120 | if ($reminderTime < $nextReminder) { |
||
| 121 | $newProps[$this->properties["flagdueby"]] = $reminderTime; |
||
| 122 | } |
||
| 123 | else { |
||
| 124 | $newProps[$this->properties["flagdueby"]] = $nextReminder; |
||
| 125 | } |
||
| 126 | } |
||
| 127 | else { |
||
| 128 | $newProps[$this->properties["flagdueby"]] = $reminderTime; |
||
| 129 | } |
||
| 130 | } |
||
| 131 | else { |
||
| 132 | $newProps[$this->properties["flagdueby"]] = $reminderTime; |
||
| 133 | } |
||
| 134 | |||
| 135 | // save props |
||
| 136 | mapi_setprops($message, $newProps); |
||
| 137 | mapi_savechanges($message); |
||
| 138 | |||
| 139 | $result = true; |
||
| 140 | } |
||
| 141 | |||
| 142 | if ($result) { |
||
| 143 | /* |
||
| 144 | * @FIXME: Fix notifications for reminders. |
||
| 145 | * Notifications are currently disabled, because deleting multiple items will notify |
||
| 146 | * hierarchy multiple time but no data is changed with folder item in hierarchy. |
||
| 147 | * so it will push same data again which will lead to an error. |
||
| 148 | */ |
||
| 149 | // $props = mapi_getprops($message, array(PR_ENTRYID, PR_PARENT_ENTRYID, PR_STORE_ENTRYID)); |
||
| 150 | // $GLOBALS["bus"]->notify(bin2hex($props[PR_PARENT_ENTRYID]), TABLE_SAVE, $props); |
||
| 151 | } |
||
| 152 | $this->sendFeedback($result); |
||
| 153 | } |
||
| 154 | |||
| 155 | /** |
||
| 156 | * Function which is use to dismiss the reminder. |
||
| 157 | * |
||
| 158 | * @param object $store MAPI Message Store Object |
||
| 159 | * @param string $entryid entryid of the message |
||
| 160 | */ |
||
| 161 | public function dismissItem($store, $entryid) { |
||
| 162 | $result = false; |
||
| 163 | $message = mapi_msgstore_openentry($store, $entryid); |
||
| 164 | if ($message) { |
||
| 165 | $newProps = []; |
||
| 166 | $props = mapi_getprops($message, $this->properties); |
||
| 167 | |||
| 168 | if (stripos($props[$this->properties["message_class"]], "IPM.Appointment") === 0) { |
||
| 169 | if (isset($props[$this->properties["appointment_recurring"]]) && $props[$this->properties["appointment_recurring"]]) { |
||
| 170 | $recurrence = new Recurrence($store, $message); |
||
| 171 | // check for next reminder after "now" for the next instance |
||
| 172 | $nextReminder = $recurrence->getNextReminderTime(time()); |
||
| 173 | if ($nextReminder) { |
||
| 174 | $newProps[$this->properties["flagdueby"]] = $nextReminder; |
||
| 175 | } |
||
| 176 | else { |
||
| 177 | $newProps[$this->properties["reminder"]] = false; |
||
| 178 | } |
||
| 179 | } |
||
| 180 | else { |
||
| 181 | $newProps[$this->properties["reminder"]] = false; |
||
| 182 | } |
||
| 183 | } |
||
| 184 | elseif (stripos($props[$this->properties["message_class"]], "IPM.Task") === 0) { |
||
| 185 | $newProps[$this->properties["reminder"]] = false; |
||
| 186 | |||
| 187 | if (isset($props[$this->properties['task_recurring']]) && $props[$this->properties['task_recurring']] == 1) { |
||
| 188 | $newProps[$this->properties['task_resetreminder']] = true; |
||
| 189 | } |
||
| 190 | } |
||
| 191 | else { |
||
| 192 | $newProps[$this->properties["reminder"]] = false; |
||
| 193 | } |
||
| 194 | |||
| 195 | // save props |
||
| 196 | mapi_setprops($message, $newProps); |
||
| 197 | mapi_savechanges($message); |
||
| 198 | |||
| 199 | $result = true; |
||
| 200 | } |
||
| 201 | |||
| 202 | if ($result) { |
||
| 203 | /* |
||
| 204 | * @FIXME: Fix notifications for reminders. |
||
| 205 | * Notifications are currently disabled, because deleting multiple items will notify |
||
| 206 | * hierarchy multiple time but no data is changed with folder item in hierarchy. |
||
| 207 | * so it will push same data again which will lead to an error. |
||
| 208 | */ |
||
| 209 | // $props = mapi_getprops($message, array(PR_ENTRYID, PR_PARENT_ENTRYID, PR_STORE_ENTRYID)); |
||
| 210 | // $GLOBALS["bus"]->notify(bin2hex($props[PR_PARENT_ENTRYID]), TABLE_SAVE, $props); |
||
| 211 | } |
||
| 212 | $this->sendFeedback($result); |
||
| 213 | } |
||
| 214 | |||
| 215 | /** |
||
| 216 | * Function does customization of exception based on module data. |
||
| 217 | * like, here it will generate display message based on actionType |
||
| 218 | * for particular exception. |
||
| 219 | * |
||
| 220 | * @param object $e Exception object |
||
| 221 | * @param string $actionType the action type, sent by the client |
||
| 222 | * @param MAPIobject $store store object of message |
||
| 223 | * @param string $parententryid parent entryid of the message |
||
| 224 | * @param string $entryid entryid of the message |
||
| 225 | * @param array $action the action data, sent by the client |
||
| 226 | */ |
||
| 227 | public function handleException(&$e, $actionType = null, $store = null, $parententryid = null, $entryid = null, $action = null) { |
||
| 257 | } |
||
| 258 | } |
||
| 259 |