| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
#[AllowDynamicProperties] |
| 3 |
class SH4_Calendars_Html_Admin_View_Permissions |
| 4 |
{ |
| 5 |
public function __construct( |
| 6 |
HC3_Hooks $hooks, |
| 7 |
HC3_Ui $ui, |
| 8 |
HC3_Ui_Layout1 $layout, |
| 9 |
|
| 10 |
SH4_Calendars_Permissions $calendarsPermissions, |
| 11 |
SH4_Calendars_Query $calendarsQuery, |
| 12 |
SH4_Calendars_Presenter $calendarsPresenter |
| 13 |
) |
| 14 |
{ |
| 15 |
$this->self = $hooks->wrap($this); |
| 16 |
$this->ui = $ui; |
| 17 |
$this->layout = $layout; |
| 18 |
|
| 19 |
$this->cp = $hooks->wrap( $calendarsPermissions ); |
| 20 |
$this->calendarsQuery = $hooks->wrap( $calendarsQuery ); |
| 21 |
$this->calendarsPresenter = $hooks->wrap( $calendarsPresenter ); |
| 22 |
$this->calendarsPermissions = $hooks->wrap( $calendarsPermissions ); |
| 23 |
} |
| 24 |
|
| 25 |
public function render( $id ) |
| 26 |
{ |
| 27 |
$calendar = $this->calendarsQuery->findById($id); |
| 28 |
$permissionsOptions = $this->calendarsPermissions->options(); |
| 29 |
|
| 30 |
$options = array(); |
| 31 |
foreach( $permissionsOptions as $o ){ |
| 32 |
$label = array_shift( $o ); |
| 33 |
$employeeOption = array_shift( $o ); |
| 34 |
$visitorOption = array_shift( $o ); |
| 35 |
$employee2Option = array_shift( $o ); |
| 36 |
// list( $label, $employeeOption, $visitorOption ) = $o; |
| 37 |
|
| 38 |
$option = array(); |
| 39 |
$option[] = $label; |
| 40 |
$option[] = $employeeOption ? $employeeOption[0] : NULL; |
| 41 |
$option[] = $visitorOption ? $visitorOption[0] : NULL; |
| 42 |
$option[] = $employee2Option ? $employee2Option[0] : NULL; |
| 43 |
|
| 44 |
$options[] = $option; |
| 45 |
} |
| 46 |
|
| 47 |
$header = array( |
| 48 |
'action' => NULL, |
| 49 |
'employee' => '<div class="hc-align-center">' . '__Calendar Employees__' . '</div>', |
| 50 |
'employee2' => '<div class="hc-align-center">' . '__Other Employees__' . '</div>', |
| 51 |
'visitor' => '<div class="hc-align-center">' . '__Visitor__' . '</div>', |
| 52 |
); |
| 53 |
|
| 54 |
$rows = array(); |
| 55 |
foreach( $options as $k => $conf ){ |
| 56 |
list( $label, $kEmployee, $kVisitor, $kEmployee2 ) = $conf; |
| 57 |
|
| 58 |
$row = array( |
| 59 |
'action' => $label, |
| 60 |
'employee' => $kEmployee ? $this->ui->makeInputCheckbox( $kEmployee, NULL, 1, $this->cp->get($calendar, $kEmployee) ) : NULL, |
| 61 |
'visitor' => $kVisitor ? $this->ui->makeInputCheckbox( $kVisitor, NULL, 1, $this->cp->get($calendar, $kVisitor) ) : NULL, |
| 62 |
'employee2' => $kEmployee2 ? $this->ui->makeInputCheckbox( $kEmployee2, NULL, 1, $this->cp->get($calendar, $kEmployee2) ) : NULL, |
| 63 |
); |
| 64 |
|
| 65 |
$keys = array_keys( $row ); |
| 66 |
foreach( $keys as $kk ){ |
| 67 |
if( 'action' === $kk ) continue; |
| 68 |
if( isset($row[$kk]) ){ |
| 69 |
$row[$kk] = '<label class="hc-block hc-align-center">' . $row[$kk] . '</label>'; |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
$rows[] = $row; |
| 74 |
} |
| 75 |
|
| 76 |
$out = $this->ui->makeTable( $header, $rows ); |
| 77 |
|
| 78 |
$buttons = $this->ui->makeInputSubmit( '__Save__') |
| 79 |
->tag('primary') |
| 80 |
; |
| 81 |
$out = $this->ui->makeList( array($out, $buttons) ); |
| 82 |
|
| 83 |
$out = $this->ui->makeForm( |
| 84 |
'admin/calendars/' . $id . '/prm', |
| 85 |
$out |
| 86 |
); |
| 87 |
|
| 88 |
$this->layout |
| 89 |
->setContent( $out ) |
| 90 |
->setBreadcrumb( $this->self->breadcrumb($calendar) ) |
| 91 |
->setHeader( $this->self->header($calendar) ) |
| 92 |
; |
| 93 |
|
| 94 |
$out = $this->layout->render(); |
| 95 |
return $out; |
| 96 |
} |
| 97 |
|
| 98 |
public function header( SH4_Calendars_Model $model ) |
| 99 |
{ |
| 100 |
$out = '__Permissions__'; |
| 101 |
return $out; |
| 102 |
} |
| 103 |
|
| 104 |
public function breadcrumb( SH4_Calendars_Model $model ) |
| 105 |
{ |
| 106 |
$calendarId = $model->getId(); |
| 107 |
$calendarTitle = $this->calendarsPresenter->presentTitle( $model ); |
| 108 |
|
| 109 |
$return = array(); |
| 110 |
$return['admin'] = array( 'admin', '__Administration__' ); |
| 111 |
$return['calendars'] = array( 'admin/calendars', '__Calendars__' ); |
| 112 |
$return['calendars/edit'] = $calendarTitle; |
| 113 |
return $return; |
| 114 |
} |
| 115 |
} |
| 116 |
|