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