| Conditions | 31 |
| Paths | 1648 |
| Total Lines | 166 |
| Code Lines | 77 |
| 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 |
||
| 47 | public function open($store, $entryid, $action) { |
||
| 48 | if ($store && $entryid) { |
||
| 49 | $data = []; |
||
| 50 | |||
| 51 | $message = $GLOBALS['operations']->openMessage($store, $entryid); |
||
| 52 | |||
| 53 | if (empty($message)) { |
||
| 54 | return; |
||
| 55 | } |
||
| 56 | |||
| 57 | // Open embedded message if requested |
||
| 58 | $attachNum = !empty($action['attach_num']) ? $action['attach_num'] : false; |
||
| 59 | if ($attachNum) { |
||
| 60 | // get message props of sub message |
||
| 61 | $parentMessage = $message; |
||
| 62 | $message = $GLOBALS['operations']->openMessage($store, $entryid, $attachNum); |
||
| 63 | |||
| 64 | if (empty($message)) { |
||
| 65 | return; |
||
| 66 | } |
||
| 67 | |||
| 68 | $data['item'] = $GLOBALS['operations']->getEmbeddedMessageProps($store, $message, $this->properties, $parentMessage, $attachNum); |
||
| 69 | } |
||
| 70 | else { |
||
| 71 | // add all standard properties from the series/normal message |
||
| 72 | $data['item'] = $GLOBALS['operations']->getMessageProps($store, $message, $this->properties, $this->plaintext); |
||
| 73 | } |
||
| 74 | |||
| 75 | if (!empty($action["timezone_iana"])) { |
||
| 76 | try { |
||
| 77 | $this->tzdef = mapi_ianatz_to_tzdef($action['timezone_iana']); |
||
| 78 | } |
||
| 79 | catch (Exception $e) { |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 83 | // if appointment is recurring then only we should get properties of occurrence if basedate is supplied |
||
| 84 | if ($data['item']['props']['recurring'] === true) { |
||
| 85 | if (!empty($action['basedate'])) { |
||
| 86 | // check for occurrence/exception |
||
| 87 | $basedate = $action['basedate']; |
||
| 88 | |||
| 89 | $recur = new Recurrence($store, $message); |
||
| 90 | |||
| 91 | $exceptionatt = $recur->getExceptionAttachment($basedate); |
||
| 92 | |||
| 93 | // Single occurrences are never recurring |
||
| 94 | $data['item']['props']['recurring'] = false; |
||
| 95 | |||
| 96 | if ($exceptionatt) { |
||
| 97 | // Existing exception (open existing item, which includes basedate) |
||
| 98 | $exceptionattProps = mapi_getprops($exceptionatt, [PR_ATTACH_NUM]); |
||
| 99 | $exception = mapi_attach_openobj($exceptionatt, 0); |
||
| 100 | |||
| 101 | // overwrite properties with the ones from the exception |
||
| 102 | $exceptionProps = $GLOBALS['operations']->getMessageProps($store, $exception, $this->properties, $this->plaintext); |
||
| 103 | |||
| 104 | /* |
||
| 105 | * If recurring item has set reminder to true then |
||
| 106 | * all occurrences before the 'flagdueby' value(of recurring item) |
||
| 107 | * should not show that reminder is set. |
||
| 108 | */ |
||
| 109 | if (isset($exceptionProps['props']['reminder']) && $data['item']['props']['reminder'] == true) { |
||
| 110 | $flagDueByDay = $recur->dayStartOf($data['item']['props']['flagdueby']); |
||
| 111 | |||
| 112 | if ($flagDueByDay > $basedate) { |
||
| 113 | $exceptionProps['props']['reminder'] = false; |
||
| 114 | } |
||
| 115 | } |
||
| 116 | |||
| 117 | // The properties must be merged, if the recipients or attachments are present in the exception |
||
| 118 | // then that list should be used. Otherwise the list from the series must be applied (this |
||
| 119 | // corresponds with OL2007). |
||
| 120 | // @FIXME getMessageProps should not return empty string if exception doesn't contain body |
||
| 121 | // by this change we can handle a situation where user has set empty string in the body explicitly |
||
| 122 | if (!empty($exceptionProps['props']['body']) || !empty($exceptionProps['props']['html_body'])) { |
||
| 123 | if (!empty($exceptionProps['props']['body'])) { |
||
| 124 | $data['item']['props']['body'] = $exceptionProps['props']['body']; |
||
| 125 | } |
||
| 126 | |||
| 127 | if (!empty($exceptionProps['props']['html_body'])) { |
||
| 128 | $data['item']['props']['html_body'] = $exceptionProps['props']['html_body']; |
||
| 129 | } |
||
| 130 | |||
| 131 | $data['item']['props']['isHTML'] = $exceptionProps['props']['isHTML']; |
||
| 132 | } |
||
| 133 | // remove properties from $exceptionProps so array_merge will not overwrite it |
||
| 134 | unset($exceptionProps['props']['html_body'], $exceptionProps['props']['body'], $exceptionProps['props']['isHTML']); |
||
| 135 | |||
| 136 | $data['item']['props'] = array_merge($data['item']['props'], $exceptionProps['props']); |
||
| 137 | if (isset($exceptionProps['recipients'])) { |
||
| 138 | $data['item']['recipients'] = $exceptionProps['recipients']; |
||
| 139 | } |
||
| 140 | |||
| 141 | if (isset($exceptionProps['attachments'])) { |
||
| 142 | $data['item']['attachments'] = $exceptionProps['attachments']; |
||
| 143 | } |
||
| 144 | |||
| 145 | // Make sure we are using the passed basedate and not something wrong in the opened item |
||
| 146 | $data['item']['props']['basedate'] = $basedate; |
||
| 147 | $data['item']['attach_num'] = [$exceptionattProps[PR_ATTACH_NUM]]; |
||
| 148 | } |
||
| 149 | elseif ($recur->isDeleteException($basedate)) { |
||
| 150 | // Exception is deleted, should not happen, but if it the case then give error |
||
| 151 | $this->sendFeedback( |
||
| 152 | false, |
||
| 153 | [ |
||
| 154 | 'type' => ERROR_ZARAFA, |
||
| 155 | 'info' => [ |
||
| 156 | 'original_message' => _('Could not open occurrence.'), |
||
| 157 | 'display_message' => _('Could not open occurrence, specific occurrence is probably deleted.'), |
||
| 158 | ], |
||
| 159 | ] |
||
| 160 | ); |
||
| 161 | |||
| 162 | return; |
||
| 163 | } |
||
| 164 | else { |
||
| 165 | // opening an occurrence of a recurring series (same as normal open, but add basedate, startdate and enddate) |
||
| 166 | $data['item']['props']['basedate'] = $basedate; |
||
| 167 | $data['item']['props']['startdate'] = $recur->getOccurrenceStart($basedate); |
||
| 168 | $data['item']['props']['duedate'] = $recur->getOccurrenceEnd($basedate); |
||
| 169 | $data['item']['props']['commonstart'] = $data['item']['props']['startdate']; |
||
| 170 | $data['item']['props']['commonend'] = $data['item']['props']['duedate']; |
||
| 171 | unset($data['item']['props']['reminder_time']); |
||
| 172 | |||
| 173 | /* |
||
| 174 | * If recurring item has set reminder to true then |
||
| 175 | * all occurrences before the 'flagdueby' value(of recurring item) |
||
| 176 | * should not show that reminder is set. |
||
| 177 | */ |
||
| 178 | if (isset($exceptionProps['props']['reminder']) && $data['item']['props']['reminder'] == true) { |
||
| 179 | $flagDueByDay = $recur->dayStartOf($data['item']['props']['flagdueby']); |
||
| 180 | |||
| 181 | if ($flagDueByDay > $basedate) { |
||
| 182 | $exceptionProps['props']['reminder'] = false; |
||
| 183 | } |
||
| 184 | } |
||
| 185 | } |
||
| 186 | } |
||
| 187 | else { |
||
| 188 | // Opening a recurring series, get the recurrence information |
||
| 189 | $recur = new Recurrence($store, $message); |
||
| 190 | $recurpattern = $recur->getRecurrence(); |
||
| 191 | $tz = $recur->tz; // no function to do this at the moment |
||
| 192 | |||
| 193 | // Add the recurrence pattern to the data |
||
| 194 | if (isset($recurpattern) && is_array($recurpattern)) { |
||
| 195 | $data['item']['props'] += $recurpattern; |
||
| 196 | } |
||
| 197 | |||
| 198 | // Add the timezone information to the data |
||
| 199 | if (isset($tz) && is_array($tz)) { |
||
| 200 | $data['item']['props'] += $tz; |
||
| 201 | } |
||
| 202 | } |
||
| 203 | } |
||
| 204 | |||
| 205 | // Fix for all-day events which have a different timezone than the user's browser |
||
| 206 | if ($data['item']['props']['alldayevent'] == 1 && $this->tzdef !== false) { |
||
| 207 | $this->processAllDayItem($store, $data['item'], $message); |
||
| 208 | } |
||
| 209 | |||
| 210 | // Send the data |
||
| 211 | $this->addActionData('item', $data); |
||
| 212 | $GLOBALS['bus']->addData($this->getResponseData()); |
||
| 213 | } |
||
| 406 |