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