| Conditions | 20 |
| Paths | 384 |
| Total Lines | 147 |
| Code Lines | 93 |
| 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 |
||
| 212 | function get_content(&$arguments,$properties) |
||
| 213 | { |
||
| 214 | $GLOBALS['egw_info']['flags']['currentapp'] = 'calendar'; |
||
| 215 | |||
| 216 | //error_log(array2string($arguments)); |
||
| 217 | if (empty($arguments['date'])) |
||
| 218 | { |
||
| 219 | $arguments['date'] = date('Ymd'); |
||
| 220 | } |
||
| 221 | if ($arguments['sortby'] == 'yearly') |
||
| 222 | { |
||
| 223 | $arguments['sortby'] = 'month'; |
||
| 224 | $arguments['date'] = substr($arguments['date'],0,4).'0101'; |
||
| 225 | } |
||
| 226 | if (isset($_GET['date'])) $arguments['date'] = $_GET['date']; |
||
| 227 | if (empty($arguments['cat_id'])) $arguments['cat_id'] = ''; |
||
| 228 | if(isset($arguments['resources']) && in_array('r0', $arguments['resources'])) |
||
| 229 | { |
||
| 230 | foreach($arguments['resources'] as $index => $value) |
||
| 231 | { |
||
| 232 | if($value == 'r0') |
||
| 233 | { |
||
| 234 | unset($arguments['resources'][$index]); |
||
| 235 | } |
||
| 236 | } |
||
| 237 | } |
||
| 238 | |||
| 239 | $params = $arguments; |
||
| 240 | if (isset($params['resources']) && count($params['resources'])) |
||
| 241 | { |
||
| 242 | $params['owner'] = array_merge((array)$params['owner'], (array)$params['resources']); |
||
| 243 | unset($params['resources']); |
||
| 244 | } |
||
| 245 | |||
| 246 | $html = '<style type="text/css">'."\n"; |
||
| 247 | $html .= '@import url('.$GLOBALS['egw_info']['server']['webserver_url'].self::CALENDAR_CSS.");\n"; |
||
| 248 | $html .= '@import url('.$GLOBALS['egw_info']['server']['webserver_url'].self::ETEMPLATE_CSS.");\n"; |
||
| 249 | $html .= '@import url('.$GLOBALS['egw_info']['server']['webserver_url'].Api\Categories::css(Api\Categories::GLOBAL_APPNAME).");\n"; |
||
| 250 | $html .= '@import url('.$GLOBALS['egw_info']['server']['webserver_url'].Api\Categories::css('calendar').");\n"; |
||
| 251 | $html .= '.popupMainDiv #calendar-planner { position: static;} |
||
| 252 | #calendar-planner .calendar_plannerWidget, #calendar-planner div.calendar_plannerRows { |
||
| 253 | height: auto !important; |
||
| 254 | } |
||
| 255 | </style>'."\n"; |
||
| 256 | $html .= Api\Html::image('sitemgr', 'left', lang('Previous'), 'onclick=\'app.calendar.toolbar_action({id:"previous"});\'') |
||
| 257 | . Api\Html::image('sitemgr', 'right', lang('Next'), 'style="float: right;" onclick=\'app.calendar.toolbar_action({id:"next"});\''); |
||
| 258 | |||
| 259 | if (is_array($params['owner'])) |
||
| 260 | { |
||
| 261 | // Buffer, and add anything that gets cleared to the content |
||
| 262 | ob_start(function($buffer) use(&$html) { |
||
| 263 | $html .= $buffer; |
||
| 264 | return ''; |
||
| 265 | }); |
||
| 266 | Framework::$header_done = true; |
||
| 267 | $ui = new calendar_uiviews(); |
||
| 268 | $ui->sortby = $arguments['sortby']; |
||
| 269 | $ui->owner = $params['owner']; |
||
| 270 | |||
| 271 | if (!$ui->planner_view || $ui->planner_view == 'month') // planner monthview |
||
| 272 | { |
||
| 273 | if ($ui->day < 15) // show one complete month |
||
| 274 | { |
||
| 275 | $ui->_week_align_month($ui->first,$ui->last); |
||
| 276 | } |
||
| 277 | else // show 2 half month |
||
| 278 | { |
||
| 279 | $ui->_week_align_month($ui->first,$ui->last,15); |
||
| 280 | } |
||
| 281 | } |
||
| 282 | elseif ($ui->planner_view == 'week' || $ui->planner_view == 'weekN') // weeekview |
||
| 283 | { |
||
| 284 | $start = new Api\DateTime($ui->date); |
||
| 285 | $start->setWeekstart(); |
||
| 286 | $ui->first = $start->format('ts'); |
||
| 287 | $ui->last = $ui->bo->date2array($this->first); |
||
| 288 | $ui->last['day'] += ($ui->planner_view == 'week' ? 7 : 7 * $ui->cal_prefs['multiple_weeks'])-1; |
||
| 289 | $ui->last['hour'] = 23; $ui->last['minute'] = $ui->last['sec'] = 59; |
||
| 290 | unset($ui->last['raw']); |
||
| 291 | $ui->last = $ui->bo->date2ts($ui->last); |
||
| 292 | } |
||
| 293 | else // dayview |
||
| 294 | { |
||
| 295 | $ui->first = $ui->bo->date2ts($ui->date); |
||
| 296 | $ui->last = $ui->bo->date2array($ui->first); |
||
| 297 | $ui->last['day'] += 0; |
||
| 298 | $ui->last['hour'] = 23; $ui->last['minute'] = $ui->last['sec'] = 59; |
||
| 299 | unset($ui->last['raw']); |
||
| 300 | $ui->last = $ui->bo->date2ts($ui->last); |
||
| 301 | } |
||
| 302 | |||
| 303 | $search_params = $ui->search_params; |
||
| 304 | $search_params['daywise'] = false; |
||
| 305 | $search_params['start'] = $ui->first; |
||
| 306 | $search_params['end'] = $ui->last; |
||
| 307 | $search_params['owner'] = $ui->owner; |
||
| 308 | $search_params['enum_groups'] = $ui->sortby == 'user'; |
||
| 309 | |||
| 310 | $content = array(); |
||
| 311 | $sel_options = array(); |
||
| 312 | $content['planner'] = $ui->bo->search($search_params); |
||
| 313 | foreach($content['planner'] as &$event) |
||
| 314 | { |
||
| 315 | $ui->to_client($event); |
||
| 316 | } |
||
| 317 | |||
| 318 | $tmpl = new Etemplate('calendar.planner'); |
||
| 319 | |||
| 320 | $tmpl->setElementAttribute('planner','start_date', Api\DateTime::to($ui->first, Api\DateTime::ET2)); |
||
| 321 | $tmpl->setElementAttribute('planner','end_date', Api\DateTime::to($ui->last, Api\DateTime::ET2)); |
||
| 322 | $tmpl->setElementAttribute('planner','owner', $search_params['owner']); |
||
| 323 | $tmpl->setElementAttribute('planner','group_by', $ui->sortby); |
||
| 324 | |||
| 325 | // Make sure all used owners are there, faking |
||
| 326 | // calendar_owner_etemplate_widget::beforeSendToClient() since the |
||
| 327 | // rest of the calendar app is probably missing. |
||
| 328 | foreach($search_params['owner'] as $owner) |
||
| 329 | { |
||
| 330 | $sel_options['owner'][] = Array( |
||
| 331 | 'id' => $owner, |
||
| 332 | 'value' => $owner, |
||
| 333 | 'label' => calendar_owner_etemplate_widget::get_owner_label($owner) |
||
| 334 | ); |
||
| 335 | } |
||
| 336 | $tmpl->exec(__METHOD__, $content,$sel_options, array('__ALL__' => true),array(),2); |
||
| 337 | $html .= ob_get_contents(); |
||
| 338 | $html .= '<script>' |
||
| 339 | . '(function() {jQuery("#calendar-planner").on("load",function() {' |
||
| 340 | . 'app.calendar.update_state(' . json_encode(array( |
||
| 341 | 'view' => 'planner', |
||
| 342 | 'planner_view' => 'month', |
||
| 343 | 'date' => Api\DateTime::to($ui->first, Api\DateTime::ET2), |
||
| 344 | 'owner' => $search_params['owner'], |
||
| 345 | 'sortby' => $ui->sortby, |
||
| 346 | 'filter' => $arguments['filter'] |
||
| 347 | )).');' |
||
| 348 | . '});})();' |
||
| 349 | . '</script>'; |
||
| 350 | |||
| 351 | ob_end_clean(); |
||
| 352 | } |
||
| 353 | else |
||
| 354 | { |
||
| 355 | $html .= '<div class="message" align="center">'.lang('No owner selected').'</div>'; |
||
| 356 | } |
||
| 357 | |||
| 358 | return $html; |
||
| 359 | } |
||
| 361 |