| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
#[AllowDynamicProperties] |
| 3 |
class SH4_Calendars_Html_Admin_View_Managers |
| 4 |
{ |
| 5 |
public function __construct( |
| 6 |
HC3_Hooks $hooks, |
| 7 |
HC3_Ui $ui, |
| 8 |
HC3_Ui_Layout1 $layout, |
| 9 |
|
| 10 |
SH4_App_Query $appQuery, |
| 11 |
HC3_IPermission $permission, |
| 12 |
|
| 13 |
SH4_Calendars_Query $calendarsQuery, |
| 14 |
SH4_Calendars_Presenter $calendarsPresenter, |
| 15 |
|
| 16 |
HC3_Users_Presenter $usersPresenter, |
| 17 |
HC3_Users_Query $users |
| 18 |
) |
| 19 |
{ |
| 20 |
$this->self = $hooks->wrap($this); |
| 21 |
$this->ui = $ui; |
| 22 |
$this->layout = $layout; |
| 23 |
|
| 24 |
$this->permission = $hooks->wrap($permission); |
| 25 |
$this->appQuery = $hooks->wrap($appQuery); |
| 26 |
$this->calendarsQuery = $hooks->wrap($calendarsQuery); |
| 27 |
$this->calendarsPresenter = $hooks->wrap( $calendarsPresenter ); |
| 28 |
|
| 29 |
$this->usersPresenter = $hooks->wrap($usersPresenter); |
| 30 |
$this->users = $hooks->wrap($users); |
| 31 |
} |
| 32 |
|
| 33 |
public function render( $id ) |
| 34 |
{ |
| 35 |
$model = $this->calendarsQuery->findById($id); |
| 36 |
|
| 37 |
$currentManagers = $this->appQuery->findManagersForCalendar( $model ); |
| 38 |
$currentManagersIds = array_keys( $currentManagers ); |
| 39 |
|
| 40 |
$currentViewers = $this->appQuery->findViewersForCalendar( $model ); |
| 41 |
$currentViewersIds = array_keys( $currentViewers ); |
| 42 |
|
| 43 |
$users = array(); |
| 44 |
// $users = $this->users->findAll(); |
| 45 |
$users = $currentViewers + $users; |
| 46 |
$users = $currentManagers + $users; |
| 47 |
|
| 48 |
$header = array( |
| 49 |
'title' => '__User__', |
| 50 |
'role' => ' ', |
| 51 |
'actions' => ' ', |
| 52 |
); |
| 53 |
|
| 54 |
$keys = array_keys( $header ); |
| 55 |
$firstKey = array_shift( $keys ); |
| 56 |
|
| 57 |
$rows = array(); |
| 58 |
foreach( $users as $e ){ |
| 59 |
$userId = $e->getId(); |
| 60 |
$row = array(); |
| 61 |
|
| 62 |
$userView = $this->usersPresenter->presentTitle( $e ); |
| 63 |
$row['title'] = $userView; |
| 64 |
|
| 65 |
$roleView = NULL; |
| 66 |
if( in_array($userId, $currentManagersIds) ){ |
| 67 |
$roleView = '__Manager__'; |
| 68 |
$roleView = $this->ui->makeSpan($roleView) |
| 69 |
->tag('padding', 'x1') |
| 70 |
->tag('color', 'white') |
| 71 |
->tag('bgcolor', 'olive') |
| 72 |
; |
| 73 |
} |
| 74 |
elseif( in_array($userId, $currentViewersIds) ){ |
| 75 |
$roleView = '__Viewer__'; |
| 76 |
$roleView = $this->ui->makeSpan($roleView) |
| 77 |
->tag('padding', 'x1') |
| 78 |
->tag('color', 'white') |
| 79 |
->tag('bgcolor', 'blue') |
| 80 |
; |
| 81 |
} |
| 82 |
|
| 83 |
$row['role'] = $roleView; |
| 84 |
|
| 85 |
$actions = array(); |
| 86 |
if( in_array($userId, $currentManagersIds) ){ |
| 87 |
if( ! $this->permission->isAdmin($e) ){ |
| 88 |
$actions[] = array( 'admin/calendars/' . $id . '/managers/' . $userId . '/remove', NULL, '__Remove From Managers__' ); |
| 89 |
} |
| 90 |
} |
| 91 |
else { |
| 92 |
$actions[] = array( 'admin/calendars/' . $id . '/managers/' . $userId . '/add', NULL, '__Add To Managers__' ); |
| 93 |
|
| 94 |
if( in_array($userId, $currentViewersIds) ){ |
| 95 |
if( ! $this->permission->isAdmin($e) ){ |
| 96 |
$actions[] = array( 'admin/calendars/' . $id . '/viewers/' . $userId . '/remove', NULL, '__Remove From Viewers__' ); |
| 97 |
} |
| 98 |
} |
| 99 |
else { |
| 100 |
$actions[] = array( 'admin/calendars/' . $id . '/viewers/' . $userId . '/add', NULL, '__Add To Viewers__' ); |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
if( $actions ){ |
| 105 |
$actions = $this->ui->helperActionsFromArray( $actions ); |
| 106 |
if( $actions ){ |
| 107 |
$actions = $this->ui->makeListInline( $actions )->separated()->gutter(1); |
| 108 |
$row['actions'] = $actions; |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
$rows[] = $row; |
| 113 |
} |
| 114 |
|
| 115 |
$out = $this->ui->makeTable( $header, $rows ); |
| 116 |
|
| 117 |
$this->layout |
| 118 |
->setContent( $out ) |
| 119 |
->setBreadcrumb( $this->self->breadcrumb($model) ) |
| 120 |
->setHeader( $this->self->header($model) ) |
| 121 |
->setMenu( $this->self->menu($model) ) |
| 122 |
; |
| 123 |
|
| 124 |
$out = $this->layout->render(); |
| 125 |
return $out; |
| 126 |
} |
| 127 |
|
| 128 |
public function menu( $model ) |
| 129 |
{ |
| 130 |
$ret = array(); |
| 131 |
$ret['new'] = array( 'admin/calendars/' . $model->getId() . '/managers-new', '__Add New__' ); |
| 132 |
return $ret; |
| 133 |
} |
| 134 |
|
| 135 |
public function header( $model ) |
| 136 |
{ |
| 137 |
$out = '__Managers__'; |
| 138 |
return $out; |
| 139 |
} |
| 140 |
|
| 141 |
public function breadcrumb( $model ) |
| 142 |
{ |
| 143 |
$calendarId = $model->getId(); |
| 144 |
$calendarTitle = $this->calendarsPresenter->presentTitle( $model ); |
| 145 |
|
| 146 |
$return = array(); |
| 147 |
$return['admin'] = array( 'admin', '__Administration__' ); |
| 148 |
$return['calendars'] = array( 'admin/calendars', '__Calendars__' ); |
| 149 |
$return['calendars/edit'] = $calendarTitle; |
| 150 |
return $return; |
| 151 |
} |
| 152 |
} |
| 153 |
|