| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
#[AllowDynamicProperties] |
| 3 |
class SH4_Users_Html_Admin_View_Employee |
| 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 |
|
| 12 |
SH4_Employees_Query $employeesQuery, |
| 13 |
HC3_Users_Query $usersQuery, |
| 14 |
|
| 15 |
SH4_Employees_Presenter $employeesPresenter |
| 16 |
) |
| 17 |
{ |
| 18 |
$this->self = $hooks->wrap($this); |
| 19 |
$this->ui = $ui; |
| 20 |
$this->layout = $layout; |
| 21 |
|
| 22 |
$this->appQuery = $hooks->wrap($appQuery); |
| 23 |
|
| 24 |
$this->employeesQuery = $hooks->wrap($employeesQuery); |
| 25 |
$this->usersQuery = $hooks->wrap($usersQuery); |
| 26 |
|
| 27 |
$this->employeesPresenter = $hooks->wrap($employeesPresenter); |
| 28 |
} |
| 29 |
|
| 30 |
public function render( $id ) |
| 31 |
{ |
| 32 |
$model = $this->usersQuery->findById($id); |
| 33 |
|
| 34 |
$employees = $this->employeesQuery->findActive(); |
| 35 |
// remove open shift |
| 36 |
unset( $employees[0] ); |
| 37 |
|
| 38 |
$header = array( 'title' => '__Employee__', 'action' => NULL ); |
| 39 |
$rows = array(); |
| 40 |
|
| 41 |
foreach( $employees as $e ){ |
| 42 |
$employeeId = $e->getId(); |
| 43 |
$row = array(); |
| 44 |
|
| 45 |
$employeeView = $this->employeesPresenter->presentTitle( $e ); |
| 46 |
$row['title'] = $employeeView; |
| 47 |
|
| 48 |
$thisUser = $this->appQuery->findUserByEmployee( $e ); |
| 49 |
if( $thisUser ){ |
| 50 |
$row['action'] = '__Already Linked To Another User Account__'; |
| 51 |
} |
| 52 |
else { |
| 53 |
$form = $this->ui->makeForm( |
| 54 |
'admin/users/' . $id . '/employee/' . $employeeId, |
| 55 |
$this->ui->makeInputSubmit( '__Link To This Employee__' ) |
| 56 |
->tag('primary') |
| 57 |
// ->tag('block') |
| 58 |
); |
| 59 |
$row['action'] = $form; |
| 60 |
} |
| 61 |
|
| 62 |
$rows[] = $row; |
| 63 |
} |
| 64 |
|
| 65 |
$out = $this->ui->makeTable( $header, $rows ); |
| 66 |
|
| 67 |
$this->layout |
| 68 |
->setContent( $out ) |
| 69 |
->setBreadcrumb( $this->self->breadcrumb($model) ) |
| 70 |
->setHeader( $this->self->header($model) ) |
| 71 |
; |
| 72 |
|
| 73 |
$out = $this->layout->render(); |
| 74 |
return $out; |
| 75 |
} |
| 76 |
|
| 77 |
public function header( $model ) |
| 78 |
{ |
| 79 |
$out = '__Link Employee To User Account__'; |
| 80 |
return $out; |
| 81 |
} |
| 82 |
|
| 83 |
public function breadcrumb( $model ) |
| 84 |
{ |
| 85 |
$return = array(); |
| 86 |
$return['admin'] = array( 'admin', '__Administration__' ); |
| 87 |
$return['users'] = array( 'admin/users', '__Users__' ); |
| 88 |
$return['users/edit'] = $model->getDisplayName(); |
| 89 |
return $return; |
| 90 |
} |
| 91 |
} |
| 92 |
|