| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
interface SH4_Schedule_Html_View_IControlOptions |
| 3 |
{ |
| 4 |
public function render(); |
| 5 |
public function renderMore(); |
| 6 |
public function renderFilterEmployees(); |
| 7 |
public function renderFilterCalendars(); |
| 8 |
public function renderFilter(); |
| 9 |
public function renderGroupBy(); |
| 10 |
public function filterViewTypes( $return ); |
| 11 |
public function renderType(); |
| 12 |
} |
| 13 |
|
| 14 |
#[AllowDynamicProperties] |
| 15 |
class SH4_Schedule_Html_View_ControlOptions implements SH4_Schedule_Html_View_IControlOptions |
| 16 |
{ |
| 17 |
public function __construct( |
| 18 |
HC3_Hooks $hooks, |
| 19 |
HC3_Ui $ui, |
| 20 |
HC3_Request $request, |
| 21 |
HC3_UriAction $uriAction, |
| 22 |
HC3_Time $t, |
| 23 |
HC3_Auth $auth, |
| 24 |
HC3_Settings $settings, |
| 25 |
|
| 26 |
SH4_Calendars_Presenter $calendarPresenter, |
| 27 |
SH4_Employees_Presenter $employeePresenter, |
| 28 |
|
| 29 |
SH4_Employees_Query $employeesQuery, |
| 30 |
SH4_Schedule_Html_View_Common $viewCommon |
| 31 |
) |
| 32 |
{ |
| 33 |
$this->self = $hooks->wrap( $this ); |
| 34 |
$this->ui = $ui; |
| 35 |
$this->request = $request; |
| 36 |
$this->uriAction = $uriAction; |
| 37 |
$this->t = $t; |
| 38 |
$this->auth = $hooks->wrap( $auth ); |
| 39 |
$this->settings = $hooks->wrap( $settings ); |
| 40 |
|
| 41 |
$this->viewCommon = $hooks->wrap( $viewCommon ); |
| 42 |
$this->employeesQuery = $hooks->wrap( $employeesQuery ); |
| 43 |
$this->calendarPresenter = $hooks->wrap( $calendarPresenter ); |
| 44 |
$this->employeePresenter = $hooks->wrap( $employeePresenter ); |
| 45 |
} |
| 46 |
|
| 47 |
public function render() |
| 48 |
{ |
| 49 |
// view options |
| 50 |
$out = array(); |
| 51 |
|
| 52 |
$type = $this->self->renderType(); |
| 53 |
if( NULL !== $type ){ |
| 54 |
$out[] = $type; |
| 55 |
} |
| 56 |
|
| 57 |
$groupBy = $this->self->renderGroupBy(); |
| 58 |
if( NULL !== $groupBy ){ |
| 59 |
$out[] = $groupBy; |
| 60 |
} |
| 61 |
|
| 62 |
$filter = $this->self->renderFilter(); |
| 63 |
if( NULL !== $filter ){ |
| 64 |
$out[] = $filter; |
| 65 |
} |
| 66 |
|
| 67 |
$more = $this->self->renderMore(); |
| 68 |
if( NULL !== $more ){ |
| 69 |
$out[] = $more; |
| 70 |
} |
| 71 |
|
| 72 |
$out = $this->ui->makeGrid( $out ); |
| 73 |
|
| 74 |
return $out; |
| 75 |
} |
| 76 |
|
| 77 |
public function renderMore() |
| 78 |
{ |
| 79 |
$out = null; |
| 80 |
if( $this->request->isPrintView() ){ |
| 81 |
return $out; |
| 82 |
} |
| 83 |
|
| 84 |
$slug = $this->request->getSlug(); |
| 85 |
$params = $this->request->getParams(); |
| 86 |
$toParams = $this->request->getParams('withoutdefault'); |
| 87 |
|
| 88 |
$hideui = $params['hideui']; |
| 89 |
|
| 90 |
$options = array(); |
| 91 |
|
| 92 |
if( ! array_intersect(array('download', 'all'), $hideui) ){ |
| 93 |
$thisParams = $toParams; |
| 94 |
$thisParams['download'] = 1; |
| 95 |
|
| 96 |
// $options['download'] = $this->ui->makeAhref( array($slug, $thisParams), '__Download__' ) |
| 97 |
// ->tag('tab-link') |
| 98 |
// ; |
| 99 |
|
| 100 |
$to = $this->uriAction->makeUrl( array($slug, $thisParams) ); |
| 101 |
$options['download'] = $this->ui->makeAhref( $to, '__Download__' ) |
| 102 |
->tag('tab-link') |
| 103 |
; |
| 104 |
|
| 105 |
$thisParams = $toParams; |
| 106 |
$thisParams['download'] = 1; |
| 107 |
$thisParams['report'] = 1; |
| 108 |
$to = $this->uriAction->makeUrl( array($slug, $thisParams) ); |
| 109 |
$options['downloadreport'] = $this->ui->makeAhref( $to, '__Download report__' ) |
| 110 |
->tag('tab-link') |
| 111 |
; |
| 112 |
} |
| 113 |
|
| 114 |
if( ! array_intersect(array('print', 'all'), $hideui) ){ |
| 115 |
$thisParams = $toParams; |
| 116 |
$thisParams['print'] = 1; |
| 117 |
|
| 118 |
// $options['print'] = $this->ui->makeAhref( array($slug, $thisParams), '__Print__' ) |
| 119 |
// ->tag('tab-link') |
| 120 |
// ->newWindow() |
| 121 |
// ->actionMode() |
| 122 |
// ; |
| 123 |
|
| 124 |
$to = $this->uriAction->makeUrl( array($slug, $thisParams) ); |
| 125 |
$options['print'] = $this->ui->makeAhref( $to, '__Print__' ) |
| 126 |
->newWindow() |
| 127 |
->tag('tab-link') |
| 128 |
; |
| 129 |
} |
| 130 |
|
| 131 |
if( ! $options ){ |
| 132 |
return $out; |
| 133 |
} |
| 134 |
|
| 135 |
if( count($options) == 1 ){ |
| 136 |
$out = array_shift( $options ); |
| 137 |
return $out; |
| 138 |
} |
| 139 |
|
| 140 |
$out = $this->ui->makeList( $options ) |
| 141 |
->gutter(1) |
| 142 |
; |
| 143 |
|
| 144 |
$label = '__More__'; |
| 145 |
$label = $this->ui->makeSpan($label) |
| 146 |
->tag('font-size', 2) |
| 147 |
->tag('muted') |
| 148 |
; |
| 149 |
|
| 150 |
$out = $this->ui->makeCollapse( $label, $out ) |
| 151 |
->border(FALSE) |
| 152 |
; |
| 153 |
return $out; |
| 154 |
} |
| 155 |
|
| 156 |
public function renderFilterEmployees() |
| 157 |
{ |
| 158 |
$return = NULL; |
| 159 |
|
| 160 |
$slug = $this->request->getSlug(); |
| 161 |
$params = $this->request->getParams(); |
| 162 |
$toParams = $this->request->getParams('withoutdefault'); |
| 163 |
|
| 164 |
$hideui = $params['hideui']; |
| 165 |
if( array_intersect(array('filter-employee', 'all'), $hideui) ){ |
| 166 |
return $return; |
| 167 |
} |
| 168 |
|
| 169 |
if( ! array_key_exists('employee', $toParams) ){ |
| 170 |
$toParams['employee'] = array(); |
| 171 |
} |
| 172 |
|
| 173 |
$all = $this->viewCommon->findAllEmployees(); |
| 174 |
// remove archived |
| 175 |
$ids = array_keys( $all ); |
| 176 |
foreach( $ids as $id ){ |
| 177 |
if( $all[$id]->isArchived() ){ |
| 178 |
unset( $all[$id] ); |
| 179 |
} |
| 180 |
} |
| 181 |
|
| 182 |
$assignedShiftEmployee = $this->employeesQuery->findById( -1 ); |
| 183 |
if( isset($all[0]) ){ |
| 184 |
$openShiftEmployee = $all[0]; |
| 185 |
$all[ $assignedShiftEmployee->getId() ] = $assignedShiftEmployee; |
| 186 |
unset( $all[0] ); |
| 187 |
$all = array( |
| 188 |
$openShiftEmployee->getId() => $openShiftEmployee, |
| 189 |
$assignedShiftEmployee->getId() => $assignedShiftEmployee |
| 190 |
) + $all; |
| 191 |
} |
| 192 |
|
| 193 |
if( count($all) < 2 && (! $toParams['employee']) ){ |
| 194 |
return $return; |
| 195 |
} |
| 196 |
|
| 197 |
$allIds = array_keys($all); |
| 198 |
$selectedEmployees = array(); |
| 199 |
foreach( $allIds as $id ){ |
| 200 |
if( in_array($id, $toParams['employee']) ){ |
| 201 |
$selectedEmployees[$id] = $all[$id]; |
| 202 |
unset($all[$id]); |
| 203 |
} |
| 204 |
} |
| 205 |
|
| 206 |
if( $this->request->isPrintView() ){ |
| 207 |
$ret = null; |
| 208 |
|
| 209 |
if( $selectedEmployees ){ |
| 210 |
$ret = array(); |
| 211 |
foreach( $selectedEmployees as $e ){ |
| 212 |
$eView = $e->getTitle(); |
| 213 |
$ret[] = $eView; |
| 214 |
} |
| 215 |
$ret = $this->ui->makeList( $ret )->gutter(0); |
| 216 |
$ret = $this->ui->makeLabelled( '__Employee__', $ret ); |
| 217 |
} |
| 218 |
|
| 219 |
return $ret; |
| 220 |
} |
| 221 |
|
| 222 |
if( $selectedEmployees ){ |
| 223 |
$selectedView = array(); |
| 224 |
foreach( $selectedEmployees as $e ){ |
| 225 |
$thisParams = $toParams; |
| 226 |
|
| 227 |
$eView = $this->employeePresenter->presentTitle( $e ); |
| 228 |
$eView = $this->ui->makeListInline( array('×', $eView) ) |
| 229 |
->gutter(1) |
| 230 |
->tag('nowrap') |
| 231 |
; |
| 232 |
|
| 233 |
$thisParams['employee'] = HC3_Functions::removeFromArray( $thisParams['employee'], $e->getId() ); |
| 234 |
if( ! $thisParams['employee'] ){ |
| 235 |
$thisParams['employee'] = array('x'); |
| 236 |
} |
| 237 |
|
| 238 |
$eView = $this->ui->makeAhref( array($slug, $thisParams), $eView ) |
| 239 |
->tag('tab-link') |
| 240 |
; |
| 241 |
|
| 242 |
$selectedView[] = $eView; |
| 243 |
} |
| 244 |
$selectedView = $this->ui->makeList( $selectedView )->gutter(0); |
| 245 |
} |
| 246 |
|
| 247 |
$toSelectView = array(); |
| 248 |
foreach( $all as $e ){ |
| 249 |
$thisParams = $toParams; |
| 250 |
|
| 251 |
$thisParams['employee'][] = $e->getId(); |
| 252 |
$label = $this->employeePresenter->presentTitle( $e ); |
| 253 |
$eView = $this->ui->makeAhref( array($slug, $thisParams), $label ) |
| 254 |
->tag('tab-link') |
| 255 |
; |
| 256 |
$toSelectView[] = $eView; |
| 257 |
} |
| 258 |
|
| 259 |
if( ! ($selectedEmployees OR $toSelectView) ){ |
| 260 |
return $return; |
| 261 |
} |
| 262 |
|
| 263 |
$view = array(); |
| 264 |
|
| 265 |
if( $selectedEmployees ){ |
| 266 |
$view[] = $selectedView; |
| 267 |
} |
| 268 |
|
| 269 |
if( $toSelectView ){ |
| 270 |
$toSelectView = $this->ui->makeList( $toSelectView ) |
| 271 |
->gutter(0) |
| 272 |
; |
| 273 |
|
| 274 |
if( $selectedEmployees ){ |
| 275 |
$label = '+ ' . '__More Employees__'; |
| 276 |
$label = $this->ui->makeBlock($label) |
| 277 |
->tag('font-size', 2) |
| 278 |
; |
| 279 |
} |
| 280 |
else { |
| 281 |
$label = '__All Employees__'; |
| 282 |
} |
| 283 |
|
| 284 |
$toSelectView = $this->ui->makeCollapse( $label, $toSelectView ); |
| 285 |
$view[] = $toSelectView; |
| 286 |
} |
| 287 |
|
| 288 |
$view = $this->ui->makeList( $view )->gutter(1); |
| 289 |
$return = $this->ui->makeLabelled( '__Employee__', $view ); |
| 290 |
|
| 291 |
return $return; |
| 292 |
} |
| 293 |
|
| 294 |
public function renderFilterCalendars() |
| 295 |
{ |
| 296 |
$return = NULL; |
| 297 |
|
| 298 |
$slug = $this->request->getSlug(); |
| 299 |
$params = $this->request->getParams(); |
| 300 |
$toParams = $this->request->getParams('withoutdefault'); |
| 301 |
|
| 302 |
$hideui = $params['hideui']; |
| 303 |
if( array_intersect(array('filter-calendar', 'all'), $hideui) ){ |
| 304 |
return $return; |
| 305 |
} |
| 306 |
|
| 307 |
if( ! array_key_exists('calendar', $toParams) ){ |
| 308 |
$toParams['calendar'] = array(); |
| 309 |
} |
| 310 |
|
| 311 |
$all = $this->viewCommon->findAllCalendars(); |
| 312 |
// remove archived |
| 313 |
$ids = array_keys( $all ); |
| 314 |
foreach( $ids as $id ){ |
| 315 |
if( $all[$id]->isArchived() ){ |
| 316 |
unset( $all[$id] ); |
| 317 |
} |
| 318 |
} |
| 319 |
|
| 320 |
if( count($all) < 2 && (! $toParams['calendar']) ){ |
| 321 |
return $return; |
| 322 |
} |
| 323 |
|
| 324 |
$allIds = array_keys($all); |
| 325 |
$selectedCalendars = array(); |
| 326 |
|
| 327 |
foreach( $allIds as $id ){ |
| 328 |
if( in_array($id, $toParams['calendar']) ){ |
| 329 |
$selectedCalendars[$id] = $all[$id]; |
| 330 |
unset($all[$id]); |
| 331 |
} |
| 332 |
} |
| 333 |
|
| 334 |
if( $this->request->isPrintView() ){ |
| 335 |
$ret = null; |
| 336 |
|
| 337 |
if( $selectedCalendars ){ |
| 338 |
$ret = array(); |
| 339 |
foreach( $selectedCalendars as $e ){ |
| 340 |
$eView = $e->getTitle(); |
| 341 |
$ret[] = $eView; |
| 342 |
} |
| 343 |
$ret = $this->ui->makeList( $ret )->gutter(0); |
| 344 |
$ret = $this->ui->makeLabelled( '__Calendar__', $ret ); |
| 345 |
} |
| 346 |
|
| 347 |
return $ret; |
| 348 |
} |
| 349 |
|
| 350 |
$selectedView = array(); |
| 351 |
if( $selectedCalendars ){ |
| 352 |
foreach( $selectedCalendars as $e ){ |
| 353 |
$thisParams = $toParams; |
| 354 |
|
| 355 |
$eView = $this->calendarPresenter->presentTitle( $e ); |
| 356 |
$eView = $this->ui->makeListInline( array('×', $eView) ) |
| 357 |
->gutter(1) |
| 358 |
->tag('nowrap') |
| 359 |
; |
| 360 |
|
| 361 |
$thisParams['calendar'] = HC3_Functions::removeFromArray( $thisParams['calendar'], $e->getId() ); |
| 362 |
if( ! $thisParams['calendar'] ){ |
| 363 |
$thisParams['calendar'] = array('x'); |
| 364 |
} |
| 365 |
|
| 366 |
$eView = $this->ui->makeAhref( array($slug, $thisParams), $eView ) |
| 367 |
->tag('tab-link') |
| 368 |
; |
| 369 |
|
| 370 |
$selectedView[] = $eView; |
| 371 |
} |
| 372 |
$selectedView = $this->ui->makeList( $selectedView )->gutter(0); |
| 373 |
} |
| 374 |
|
| 375 |
$toSelectView = array(); |
| 376 |
foreach( $all as $e ){ |
| 377 |
$thisParams = $toParams; |
| 378 |
$thisParams['calendar'][] = $e->getId(); |
| 379 |
|
| 380 |
$label = $this->calendarPresenter->presentTitle( $e ); |
| 381 |
$eView = $this->ui->makeAhref( array($slug, $thisParams), $label ) |
| 382 |
->tag('tab-link') |
| 383 |
; |
| 384 |
|
| 385 |
$toSelectView[] = $eView; |
| 386 |
} |
| 387 |
|
| 388 |
if( ! ($selectedCalendars OR $toSelectView) ){ |
| 389 |
return $return; |
| 390 |
} |
| 391 |
|
| 392 |
$view = array(); |
| 393 |
|
| 394 |
if( $selectedView ){ |
| 395 |
$view[] = $selectedView; |
| 396 |
} |
| 397 |
|
| 398 |
if( $toSelectView ){ |
| 399 |
$toSelectView = $this->ui->makeList( $toSelectView ) |
| 400 |
->gutter(0) |
| 401 |
; |
| 402 |
|
| 403 |
if( $selectedCalendars ){ |
| 404 |
$label = '+ ' . '__More Calendars__'; |
| 405 |
$label = $this->ui->makeBlock($label) |
| 406 |
->tag('font-size', 2) |
| 407 |
; |
| 408 |
} |
| 409 |
else { |
| 410 |
$label = '__All Calendars__'; |
| 411 |
} |
| 412 |
|
| 413 |
$toSelectView = $this->ui->makeCollapse( $label, $toSelectView ); |
| 414 |
$view[] = $toSelectView; |
| 415 |
} |
| 416 |
|
| 417 |
$view = $this->ui->makeList( $view )->gutter(1); |
| 418 |
$return = $this->ui->makeLabelled( '__Calendar__', $view ); |
| 419 |
|
| 420 |
return $return; |
| 421 |
} |
| 422 |
|
| 423 |
public function renderFilterConflicts() |
| 424 |
{ |
| 425 |
$ret = null; |
| 426 |
|
| 427 |
$currentUser = $this->auth->getCurrentUser(); |
| 428 |
$currentUserId = $currentUser->getId(); |
| 429 |
if( ! $currentUserId ){ |
| 430 |
return $ret; |
| 431 |
} |
| 432 |
|
| 433 |
$slug = $this->request->getSlug(); |
| 434 |
$params = $this->request->getParams(); |
| 435 |
$toParams = $this->request->getParams('withoutdefault'); |
| 436 |
|
| 437 |
$hideui = $params['hideui']; |
| 438 |
if( array_intersect(array('filter-conflict', 'all'), $hideui) ){ |
| 439 |
return $ret; |
| 440 |
} |
| 441 |
|
| 442 |
if( ! array_key_exists('conflict', $toParams) ){ |
| 443 |
$toParams['conflict'] = null; |
| 444 |
} |
| 445 |
|
| 446 |
$thisParams['conflict'] = 1; |
| 447 |
$label = '__Shifts With Conflicts__'; |
| 448 |
|
| 449 |
if( $toParams['conflict'] ){ |
| 450 |
$thisParams['conflict'] = null; |
| 451 |
$label = $this->ui->makeListInline( array('×', $label) )->gutter(1); |
| 452 |
$view = $this->ui->makeAhref( array($slug, $thisParams), $label ) |
| 453 |
->tag('tab-link') |
| 454 |
; |
| 455 |
} |
| 456 |
else { |
| 457 |
$thisParams['conflict'] = 1; |
| 458 |
$view = $this->ui->makeAhref( array($slug, $thisParams), $label ) |
| 459 |
->tag('tab-link') |
| 460 |
; |
| 461 |
} |
| 462 |
|
| 463 |
return $view; |
| 464 |
} |
| 465 |
|
| 466 |
public function renderFilter() |
| 467 |
{ |
| 468 |
$return = NULL; |
| 469 |
|
| 470 |
$params = $this->request->getParams(); |
| 471 |
$hideui = $params['hideui']; |
| 472 |
if( array_intersect(array('filter', 'all'), $hideui) ){ |
| 473 |
return $return; |
| 474 |
} |
| 475 |
|
| 476 |
$params = $this->request->getParams('withoutdefault'); |
| 477 |
|
| 478 |
if( ! array_key_exists('conflict', $params) ){ |
| 479 |
$params['conflict'] = null; |
| 480 |
} |
| 481 |
if( ! array_key_exists('employee', $params) ){ |
| 482 |
$params['employee'] = array(); |
| 483 |
} |
| 484 |
if( ! array_key_exists('calendar', $params) ){ |
| 485 |
$params['calendar'] = array(); |
| 486 |
} |
| 487 |
|
| 488 |
$filterView = array(); |
| 489 |
|
| 490 |
// filter - employees |
| 491 |
$filterViewEmployees = $this->self->renderFilterEmployees(); |
| 492 |
if( $filterViewEmployees ){ |
| 493 |
$filterView[] = $filterViewEmployees; |
| 494 |
} |
| 495 |
|
| 496 |
// calendars |
| 497 |
$filterViewCalendars = $this->self->renderFilterCalendars(); |
| 498 |
if( $filterViewCalendars ){ |
| 499 |
$filterView[] = $filterViewCalendars; |
| 500 |
} |
| 501 |
|
| 502 |
// filter - conflicts |
| 503 |
$filterViewConflicts = $this->renderFilterConflicts(); |
| 504 |
if( $filterViewConflicts ){ |
| 505 |
$filterView[] = $filterViewConflicts; |
| 506 |
} |
| 507 |
|
| 508 |
if( ! $filterView ){ |
| 509 |
return $return; |
| 510 |
} |
| 511 |
|
| 512 |
$filter = $this->ui->makeList( $filterView ); |
| 513 |
|
| 514 |
$label = '__Filter__'; |
| 515 |
|
| 516 |
if( $this->request->isPrintView() ){ |
| 517 |
$out = $filter; |
| 518 |
// $out = $this->ui->makeLabelled( $label, $filter ); |
| 519 |
} |
| 520 |
else { |
| 521 |
$currentView = ''; |
| 522 |
$totalSelectedCount = count($params['calendar']) + count($params['employee']); |
| 523 |
if( $params['conflict'] ) $totalSelectedCount += 1; |
| 524 |
$currentView = $totalSelectedCount ? '(' . $totalSelectedCount . ')' : '__None__'; |
| 525 |
|
| 526 |
$label = '__Filter__'; |
| 527 |
$label = $this->ui->makeSpan($label) |
| 528 |
->tag('font-size', 2) |
| 529 |
->tag('muted') |
| 530 |
; |
| 531 |
$currentView = $this->ui->makeSpan($currentView) |
| 532 |
->tag('font-style', 'bold') |
| 533 |
; |
| 534 |
$label = $this->ui->makeListInline( array($label, $currentView) )->gutter(1); |
| 535 |
|
| 536 |
$out = $this->ui->makeCollapse( $label, $filter ) |
| 537 |
->border(false) |
| 538 |
; |
| 539 |
} |
| 540 |
|
| 541 |
return $out; |
| 542 |
} |
| 543 |
|
| 544 |
public function renderGroupBy() |
| 545 |
{ |
| 546 |
$return = null; |
| 547 |
if( $this->request->isPrintView() ){ |
| 548 |
return $return; |
| 549 |
} |
| 550 |
|
| 551 |
$slug = $this->request->getSlug(); |
| 552 |
$params = $this->request->getParams(); |
| 553 |
|
| 554 |
$hideui = $params['hideui']; |
| 555 |
if( array_intersect(array('groupby', 'all'), $hideui) ){ |
| 556 |
return $return; |
| 557 |
} |
| 558 |
|
| 559 |
$current = $params['groupby']; |
| 560 |
$currentView = $current; |
| 561 |
|
| 562 |
$employees = $this->viewCommon->getEmployees(); |
| 563 |
$calendars = $this->viewCommon->getCalendars(); |
| 564 |
|
| 565 |
$options = array(); |
| 566 |
|
| 567 |
if( (count($employees) > 1) OR ('employee' == $current) ){ |
| 568 |
if( ! in_array('groupby-employee', $hideui) ){ |
| 569 |
$options[] = array( '__Employee__', 'employee' ); |
| 570 |
} |
| 571 |
} |
| 572 |
if( (count($calendars) > 1) OR ('calendar' == $current) ){ |
| 573 |
if( ! in_array('groupby-calendar', $hideui) ){ |
| 574 |
$options[] = array( '__Calendar__', 'calendar' ); |
| 575 |
} |
| 576 |
} |
| 577 |
|
| 578 |
if( ! $options ){ |
| 579 |
return $return; |
| 580 |
} |
| 581 |
|
| 582 |
array_unshift( $options, array( '__None__', 'none' ) ); |
| 583 |
|
| 584 |
$view = array(); |
| 585 |
foreach( $options as $option ){ |
| 586 |
list( $label, $k ) = $option; |
| 587 |
|
| 588 |
if( $k == $current ){ |
| 589 |
$currentView = $label; |
| 590 |
continue; |
| 591 |
} |
| 592 |
|
| 593 |
$params = $k ? array('groupby' => $k) : array('groupby' => NULL); |
| 594 |
$this_option = $this->ui->makeAhref( array($slug, $params), $label ) |
| 595 |
->tag('tab-link') |
| 596 |
; |
| 597 |
$view[] = $this_option; |
| 598 |
} |
| 599 |
|
| 600 |
$out = $this->ui->makeList( $view ) |
| 601 |
->gutter(1) |
| 602 |
; |
| 603 |
|
| 604 |
$label = '__Group By__'; |
| 605 |
$label = $this->ui->makeSpan($label) |
| 606 |
->tag('font-size', 2) |
| 607 |
->tag('muted') |
| 608 |
; |
| 609 |
$currentView = $this->ui->makeSpan($currentView) |
| 610 |
->tag('font-style', 'bold') |
| 611 |
; |
| 612 |
$label = $this->ui->makeListInline( array($label, $currentView) )->gutter(1); |
| 613 |
|
| 614 |
$out = $this->ui->makeCollapse( $label, $out ) |
| 615 |
->border(FALSE) |
| 616 |
; |
| 617 |
return $out; |
| 618 |
} |
| 619 |
|
| 620 |
public function filterViewTypes( $return ) |
| 621 |
{ |
| 622 |
return $return; |
| 623 |
} |
| 624 |
|
| 625 |
public function renderType() |
| 626 |
{ |
| 627 |
$out = NULL; |
| 628 |
|
| 629 |
$slug = $this->request->getSlug(); |
| 630 |
$params = $this->request->getParams(); |
| 631 |
$toParams = $this->request->getParams('withoutdefault'); |
| 632 |
|
| 633 |
$hideui = $params['hideui']; |
| 634 |
if( array_intersect(array('type', 'all'), $hideui) ){ |
| 635 |
return $out; |
| 636 |
} |
| 637 |
|
| 638 |
$current = $params['type']; |
| 639 |
$currentView = $current; |
| 640 |
|
| 641 |
$nWeeks = $this->settings->get( 'datetime_n_weeks' ); |
| 642 |
|
| 643 |
$options = array( |
| 644 |
'day' => '__Day__', |
| 645 |
'week' => '__Week__', |
| 646 |
'2weeks' => '__2 Weeks__', |
| 647 |
'4weeks' => $nWeeks . ' ' . '__Weeks__', |
| 648 |
'month' => '__Month__', |
| 649 |
'list' => '__List__', |
| 650 |
'report' => '__Report__' |
| 651 |
); |
| 652 |
|
| 653 |
$keys = array_keys( $options ); |
| 654 |
foreach( $keys as $key ){ |
| 655 |
$testKey = 'type-' . $key; |
| 656 |
if( in_array($testKey, $hideui) ){ |
| 657 |
unset( $options[$key] ); |
| 658 |
} |
| 659 |
} |
| 660 |
|
| 661 |
if( count($options) < 2 ){ |
| 662 |
return $out; |
| 663 |
} |
| 664 |
|
| 665 |
$options = $this->viewCommon->filterViewTypes( $options ); |
| 666 |
|
| 667 |
$view = array(); |
| 668 |
foreach( $options as $k => $label ){ |
| 669 |
$thisParams = $toParams; |
| 670 |
$thisParams['type'] = $k; |
| 671 |
if( in_array($k, array('week', 'month', 'day', '2weeks', '4weeks')) ){ |
| 672 |
$thisParams['end'] = NULL; |
| 673 |
$thisParams['time'] = NULL; |
| 674 |
} |
| 675 |
|
| 676 |
if( 'day' == $k ){ |
| 677 |
// if in current week/month then jump to today rather than the first day of week/month |
| 678 |
$today = $this->t->setNow()->setStartDay()->formatDateDb(); |
| 679 |
if( isset($params['start']) && isset($params['end']) ){ |
| 680 |
if( ($today >= $params['start']) && ($today <= $params['end']) ){ |
| 681 |
$thisParams['start'] = $today; |
| 682 |
} |
| 683 |
} |
| 684 |
} |
| 685 |
|
| 686 |
if( $current == $k ){ |
| 687 |
$currentView = $label; |
| 688 |
continue; |
| 689 |
} |
| 690 |
|
| 691 |
$thisOption = $this->ui->makeAhref( array($slug, $thisParams), $label ) |
| 692 |
->tag('tab-link') |
| 693 |
; |
| 694 |
$view[] = $thisOption; |
| 695 |
} |
| 696 |
|
| 697 |
$out = $this->ui->makeList( $view ) |
| 698 |
->gutter(1) |
| 699 |
; |
| 700 |
|
| 701 |
$label = '__View__'; |
| 702 |
$label = $this->ui->makeSpan($label) |
| 703 |
->tag('font-size', 2) |
| 704 |
->tag('muted') |
| 705 |
; |
| 706 |
$currentView = $this->ui->makeSpan($currentView) |
| 707 |
->tag('font-style', 'bold') |
| 708 |
; |
| 709 |
$label = $this->ui->makeListInline( array($label, $currentView) )->gutter(1); |
| 710 |
|
| 711 |
$out = $this->ui->makeCollapse( $label, $out ) |
| 712 |
->border(FALSE) |
| 713 |
; |
| 714 |
return $out; |
| 715 |
} |
| 716 |
} |