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