PluginProbe
ShiftController Employee Shift Scheduling / 4.9.66
ShiftController Employee Shift Scheduling v4.9.66
4.9.97 4.9.96 4.9.95 4.9.74 4.9.75 4.9.76 4.9.77 4.9.78 4.9.84 4.9.85 4.9.87 4.9.91 4.9.92 trunk 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 3.2.4 All 38 releases
shiftcontroller / sh4 / employees / html / admin / view / calendars.php

calendars.php in ShiftController Employee Shift Scheduling 4.9.66, at sh4/employees/html/admin/view/calendars.php

148 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if (! defined('ABSPATH')) exit; // Exit if accessed directly
2 #[AllowDynamicProperties]
3 class SH4_Employees_Html_Admin_View_Calendars
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 SH4_Employees_Presenter $employeesPresenter,
14
15 SH4_Calendars_Query $calendarsQuery,
16 SH4_Calendars_Presenter $calendarsPresenter
17 )
18 {
19 $this->self = $hooks->wrap($this);
20 $this->ui = $ui;
21 $this->layout = $layout;
22
23 $this->appQuery = $hooks->wrap( $appQuery );
24
25 $this->employeesQuery = $hooks->wrap( $employeesQuery );
26 $this->employeesPresenter = $hooks->wrap( $employeesPresenter );
27
28 $this->calendarsQuery = $hooks->wrap( $calendarsQuery );
29 $this->calendarsPresenter = $hooks->wrap( $calendarsPresenter );
30 }
31
32 public function render( $id )
33 {
34 $model = $this->employeesQuery->findById($id);
35
36 $current = $this->appQuery->findCalendarsForEmployee( $model );
37 $currentIds = array_keys( $current );
38
39 $calendars = $this->calendarsQuery->findActive();
40
41 $calendarsView = array();
42 foreach( $calendars as $calendar ){
43 $calendarId = $calendar->getId();
44 $checked = in_array( $calendarId, $currentIds ) ? TRUE : FALSE;
45
46 $title = $this->calendarsPresenter->presentTitle( $calendar );
47 // $thisView = $this->ui->makeInputCheckbox( 'calendar[]', $thisView, $calendarId, $checked );
48 $thisView = $this->ui->makeInputCheckbox( 'calendar[]', NULL, $calendarId, $checked );
49 $thisView = $this->ui->makeListInline( array($thisView, $title) );
50
51 $thisView = $this->ui->makeBlock( $thisView )
52 ->tag('border')
53 ->tag('padding', 2)
54 ;
55 if( $checked ){
56 $thisView
57 ->tag('border-color', 'olive')
58 ;
59 }
60
61 $calendarsView[] = $thisView;
62 }
63
64 $out = $this->ui->makeListInline( $calendarsView );
65
66 $out = $this->ui->makeBlock( $out )
67 ->addAttr( 'id', 'sh4-calendars-employees' )
68 ;
69 $toggleAll = $this->ui->makeInputCheckbox( 'toggle_all', '__Toggle All__' )
70 ->addAttr( 'class', 'sh4-calendars-employees-select-all' )
71 ;
72
73 $buttons = $this->ui->makeInputSubmit( '__Save__')
74 ->tag('primary')
75 ;
76 $out = $this->ui->makeList( array($toggleAll, $out, $buttons) );
77
78 $out = $this->ui->makeForm(
79 'admin/employees/' . $id . '/calendars',
80 $out
81 );
82
83 // add check all
84 $js = $this->renderJs();
85 $out = $this->ui->makeCollection( array($js, $out) );
86
87 $this->layout
88 ->setContent( $out )
89 ->setBreadcrumb( $this->self->breadcrumb($model) )
90 ->setHeader( $this->self->header($model) )
91 ;
92
93 $out = $this->layout->render();
94 return $out;
95 }
96
97 public function header( SH4_Employees_Model $model )
98 {
99 $out = '__Calendars__';
100 return $out;
101 }
102
103 public function breadcrumb( SH4_Employees_Model $model )
104 {
105 $id = $model->getId();
106 $title = $this->employeesPresenter->presentTitle( $model );
107
108 $return = array();
109 $return['admin'] = array( 'admin', '__Administration__' );
110 $return['employees'] = array( 'admin/employees', '__Employees__' );
111 $return['employees/edit'] = $title;
112 return $return;
113 }
114
115 public function renderJs()
116 {
117 ob_start();
118 ?>
119
120 <script language="JavaScript">
121 ( function(){
122
123 document.addEventListener('DOMContentLoaded', function()
124 {
125 var self = this;
126 var el = document.getElementById( 'sh4-calendars-employees' );
127
128 this.toggleAll = function( e ){
129 var checkers = el.getElementsByTagName( 'input' );
130 for( ii = 0; ii < checkers.length; ii++ ){
131 checkers[ii].checked = ! checkers[ii].checked;
132 }
133 };
134
135 var togglers = document.getElementsByClassName( 'sh4-calendars-employees-select-all' );
136 for( ii = 0; ii < togglers.length; ii++ ){
137 togglers[ii].addEventListener( 'change', self.toggleAll );
138 }
139 });
140
141 })();
142
143 </script>
144
145 <?php
146 return ob_get_clean();
147 }
148 }