| Conditions | 10 |
| Paths | 18 |
| Total Lines | 133 |
| Code Lines | 62 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 158 | public function getReminders() { |
||
| 159 | $data = []; |
||
| 160 | |||
| 161 | $store = $GLOBALS["mapisession"]->getDefaultMessageStore(); |
||
| 162 | |||
| 163 | $restriction = [RES_AND, |
||
| 164 | [ |
||
| 165 | [RES_PROPERTY, |
||
| 166 | [ |
||
| 167 | RELOP => RELOP_LT, |
||
| 168 | ULPROPTAG => $this->properties["flagdueby"], |
||
| 169 | VALUE => [$this->properties["flagdueby"] => time()], |
||
| 170 | ], |
||
| 171 | ], |
||
| 172 | [RES_PROPERTY, |
||
| 173 | [ |
||
| 174 | RELOP => RELOP_EQ, |
||
| 175 | ULPROPTAG => $this->properties["reminder"], |
||
| 176 | VALUE => true, |
||
| 177 | ], |
||
| 178 | ], |
||
| 179 | [RES_PROPERTY, |
||
| 180 | [ |
||
| 181 | RELOP => RELOP_NE, |
||
| 182 | ULPROPTAG => $this->properties["message_class"], |
||
| 183 | VALUE => "IPM.TaskRequest", |
||
| 184 | ], |
||
| 185 | ], |
||
| 186 | [RES_PROPERTY, |
||
| 187 | [ |
||
| 188 | RELOP => RELOP_NE, |
||
| 189 | ULPROPTAG => $this->properties["message_class"], |
||
| 190 | VALUE => "IPM.TaskRequest.Cancel", |
||
| 191 | ], |
||
| 192 | ], |
||
| 193 | [RES_PROPERTY, |
||
| 194 | [ |
||
| 195 | RELOP => RELOP_NE, |
||
| 196 | ULPROPTAG => $this->properties["message_class"], |
||
| 197 | VALUE => "IPM.TaskRequest.Accept", |
||
| 198 | ], |
||
| 199 | ], |
||
| 200 | [RES_PROPERTY, |
||
| 201 | [ |
||
| 202 | RELOP => RELOP_NE, |
||
| 203 | ULPROPTAG => $this->properties["message_class"], |
||
| 204 | VALUE => "IPM.TaskRequest.Update", |
||
| 205 | ], |
||
| 206 | ], |
||
| 207 | [RES_PROPERTY, |
||
| 208 | [ |
||
| 209 | RELOP => RELOP_NE, |
||
| 210 | ULPROPTAG => $this->properties["message_class"], |
||
| 211 | VALUE => "IPM.TaskRequest.Complete", |
||
| 212 | ], |
||
| 213 | ], |
||
| 214 | ], |
||
| 215 | ]; |
||
| 216 | |||
| 217 | try { |
||
| 218 | $reminderfolder = mapi_msgstore_openentry($store, $this->reminderEntryId); |
||
| 219 | } |
||
| 220 | catch (MAPIException $e) { |
||
| 221 | // if the reminder folder does not exist, try to recreate it. |
||
| 222 | if ($e->getCode() == MAPI_E_NOT_FOUND) { |
||
| 223 | $e->setHandled(); |
||
| 224 | |||
| 225 | $this->reminderEntryId = $this->createReminderFolder($store); |
||
| 226 | $reminderfolder = mapi_msgstore_openentry($store, $this->reminderEntryId); |
||
| 227 | } |
||
| 228 | } |
||
| 229 | |||
| 230 | $remindertable = mapi_folder_getcontentstable($reminderfolder, MAPI_DEFERRED_ERRORS); |
||
| 231 | if (!$remindertable) { |
||
| 232 | return false; |
||
| 233 | } |
||
| 234 | |||
| 235 | mapi_table_restrict($remindertable, $restriction, TBL_BATCH); |
||
| 236 | mapi_table_sort($remindertable, [$this->properties["flagdueby"] => TABLE_SORT_DESCEND], TBL_BATCH); |
||
| 237 | |||
| 238 | // reminder store hold only 99 records as |
||
| 239 | // we show 99 notification on client side. |
||
| 240 | $rows = mapi_table_queryrows($remindertable, $this->properties, 0, MAX_NUM_REMINDERS); |
||
| 241 | $data["item"] = []; |
||
| 242 | |||
| 243 | foreach ($rows as $row) { |
||
| 244 | if (isset($row[$this->properties["appointment_recurring"]]) && $row[$this->properties["appointment_recurring"]]) { |
||
| 245 | $recur = new Recurrence($store, $row); |
||
| 246 | |||
| 247 | /** |
||
| 248 | * FlagDueBy == PidLidReminderSignalTime. |
||
| 249 | * FlagDueBy handles whether we should be showing the item; if now() is after FlagDueBy, then we should show a reminder |
||
| 250 | * for this recurrence. However, the item we will show is either the last passed occurrence (overdue), or the next occurrence, depending |
||
| 251 | * on whether we have reached the next occurrence yet (the reminder_time of the next item is ignored). |
||
| 252 | * |
||
| 253 | * The way we handle this is to get all occurrences between the 'flagdueby' moment and the current time. This will |
||
| 254 | * yield N items (may be a lot of it was not dismissed for a long time). We can then take the last item in this list, and this is the item |
||
| 255 | * we will show to the user. The idea here is: |
||
| 256 | * |
||
| 257 | * The item we want to show is the last item in that list (new occurrences that have started uptil now should override old ones) |
||
| 258 | * |
||
| 259 | * Add the reminder_minutes (default 15 minutes for calendar, 0 for tasks) to check over the gap between FlagDueBy and the start time of the |
||
| 260 | * occurrence, if "now" would be in between these values. |
||
| 261 | */ |
||
| 262 | $remindertimeinseconds = $row[$this->properties["reminder_minutes"]] * 60; |
||
| 263 | $occurrences = $recur->getItems($row[$this->properties["flagdueby"]], time() + ($remindertimeinseconds), 0, true); |
||
| 264 | |||
| 265 | if (empty($occurrences)) { |
||
| 266 | continue; |
||
| 267 | } |
||
| 268 | |||
| 269 | // More than one occurrence, use the last one instead of the first one after flagdueby |
||
| 270 | $occ = $occurrences[count($occurrences) - 1]; |
||
| 271 | |||
| 272 | // Bydefault, on occurrence reminder is true but if reminder value is set to false then we don't send popup reminder for this occurrence |
||
| 273 | if (!(isset($occ[$this->properties['reminder']]) && $occ[$this->properties['reminder']] == 0)) { |
||
| 274 | $row[$this->properties["reminder_time"]] = $occ[$this->properties["appointment_startdate"]]; |
||
| 275 | $row[$this->properties["appointment_startdate"]] = $occ[$this->properties["appointment_startdate"]]; |
||
| 276 | $row[$this->properties["appointment_enddate"]] = $occ[$this->properties["appointment_startdate"]]; |
||
| 277 | } |
||
| 278 | } |
||
| 279 | |||
| 280 | // Add the non-bogus rows |
||
| 281 | array_push($data["item"], Conversion::mapMAPI2XML($this->properties, $row)); |
||
| 282 | } |
||
| 283 | |||
| 284 | $this->addActionData("list", $data); |
||
| 285 | $GLOBALS["bus"]->addData($this->getResponseData()); |
||
| 286 | |||
| 287 | // Trigger the newmailnotifier |
||
| 288 | $GLOBALS["bus"]->notify(REQUEST_ENTRYID, HIERARCHY_UPDATE, ['', '']); |
||
| 289 | |||
| 290 | return true; |
||
| 291 | } |
||
| 293 |