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