PluginProbe
ShiftController Employee Shift Scheduling / 4.9.85
ShiftController Employee Shift Scheduling v4.9.85
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 / calendars / permissions.php

permissions.php in ShiftController Employee Shift Scheduling 4.9.85, at sh4/calendars/permissions.php

217 lines 5.1 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 interface SH4_Calendars_IPermissions
3 {
4 public function set( SH4_Calendars_Model $calendar, $permissionId, $value );
5 public function get( SH4_Calendars_Model $calendar, $permissionId );
6 public function getAll( SH4_Calendars_Model $calendar );
7 public function options();
8 public function categorizedOptions();
9 }
10
11 class SH4_Calendars_Permissions implements SH4_Calendars_IPermissions
12 {
13 public $self, $dic, $settings, $calendarsQuery;
14
15 public function __construct(
16 HC3_Hooks $hooks,
17 HC3_Dic $dic,
18 HC3_Settings $settings,
19
20 SH4_Calendars_Query $calendarsQuery
21 )
22 {
23 $this->self = $hooks->wrap( $this );
24
25 $this->settings = $settings;
26 $this->dic = $dic;
27
28 $calendarsQuery = $hooks->wrap( $calendarsQuery );
29 $calendars = $calendarsQuery->findActive();
30
31 $defaults = $this->self->getDefaults();
32
33 reset( $calendars );
34 foreach( $calendars as $calendar ){
35 reset( $defaults );
36 foreach( $defaults as $key => $value ){
37 $key = $this->_settingsKey( $calendar, $key );
38 $this->settings->init( $key, $value );
39 }
40 }
41 }
42
43 public function categorizedOptions()
44 {
45 $ret = array( 'employee' => array(), 'employee2' => array(), 'visitor' => array() );
46
47 $options = $this->self->options();
48 foreach( $options as $o ){
49 $label = array_shift( $o );
50 $employeeOption = array_shift( $o );
51 $visitorOption = array_shift( $o );
52 $employee2Option = array_shift( $o );
53 // list( $label, $employeeOption, $visitorOption ) = $o;
54
55 if( $employeeOption ){
56 $ret['employee'][] = $employeeOption[0];
57 }
58 if( $visitorOption ){
59 $ret['visitor'][] = $visitorOption[0];
60 }
61 if( $employee2Option ){
62 $ret['employee2'][] = $employee2Option[0];
63 }
64 }
65
66 return $ret;
67 }
68
69 public function options()
70 {
71 $ret = array();
72
73 $ret[] = array(
74 '__View Own Published Shifts__',
75 array( 'employee_view_own_publish', 1 ),
76 NULL
77 );
78
79 $ret[] = array(
80 '__View Own Draft Shifts__',
81 array( 'employee_view_own_draft', 1 ),
82 NULL
83 );
84
85 $ret[] = array(
86 '__Create Own Published Shifts__',
87 array( 'employee_create_own_publish', 0 ),
88 NULL
89 );
90
91 $ret[] = array(
92 '__Create Own Draft Shifts__',
93 array( 'employee_create_own_draft', 0 ),
94 NULL
95 );
96
97 $ret[] = array(
98 '__Edit Own Published Shifts__',
99 array( 'employee_edit_own_publish', 0 ),
100 NULL
101 );
102
103 $ret[] = array(
104 '__Edit Own Draft Shifts__',
105 array( 'employee_edit_own_draft', 0 ),
106 NULL
107 );
108
109 $ret[] = array(
110 '__Delete Own Published Shifts__',
111 array( 'employee_delete_own_publish', 0 ),
112 NULL
113 );
114
115 $ret[] = array(
116 '__Delete Own Draft Shifts__',
117 array( 'employee_delete_own_draft', 0 ),
118 NULL
119 );
120
121 $ret[] = array(
122 '__Create Own Shifts With Conflicts__',
123 array( 'employee_create_own_conflicts', 0 ),
124 NULL
125 );
126
127 $ret[] = array(
128 '__View Others Published Shifts__',
129 array( 'employee_view_others_publish', 1 ),
130 array( 'visitor_view_others_publish', 1 ),
131 array( 'employee2_view_others_publish', 1 )
132 );
133
134 $ret[] = array(
135 '__View Others Draft Shifts__',
136 array( 'employee_view_others_draft', 0 ),
137 array( 'visitor_view_others_draft', 0 ),
138 array( 'employee2_view_others_draft', 0 )
139 );
140
141 $ret[] = array(
142 '__View Open Published Shifts__',
143 array( 'employee_view_open_publish', 1 ),
144 array( 'visitor_view_open_publish', 0 ),
145 array( 'employee2_view_open_publish', 0 )
146 );
147
148 $ret[] = array(
149 '__View Open Draft Shifts__',
150 array( 'employee_view_open_draft', 0 ),
151 array( 'visitor_view_open_draft', 0 ),
152 array( 'employee2_view_open_draft', 0 )
153 );
154
155 return $ret;
156 }
157
158 public function set( SH4_Calendars_Model $calendar, $permissionId, $value )
159 {
160 $key = $this->_settingsKey( $calendar, $permissionId );
161 $this->settings->set( $key, $value );
162 return $this;
163 }
164
165 public function getDefaults()
166 {
167 $defaults = array();
168
169 $options = $this->self->options();
170 foreach( $options as $option ){
171 $label = array_shift( $option );
172 while( $option ){
173 $prop = array_shift($option);
174 if( NULL === $prop ){
175 continue;
176 }
177
178 list( $permissionName, $defaultValue ) = $prop;
179 $defaults[ $permissionName ] = $defaultValue;
180 }
181 }
182
183 return $defaults;
184 }
185
186 public function getAll( SH4_Calendars_Model $calendar )
187 {
188 $defaults = $this->self->getDefaults();
189
190 foreach( array_keys($defaults) as $permissionName ){
191 $return[$permissionName] = $this->self->get( $calendar, $permissionName );
192 }
193
194 return $return;
195 }
196
197 public function get( SH4_Calendars_Model $calendar, $permissionId )
198 {
199 $key = $this->_settingsKey( $calendar, $permissionId );
200 $return = $this->settings->get( $key );
201 return $return;
202 }
203
204 protected function _settingsKey( SH4_Calendars_Model $calendar, $permissionId )
205 {
206 $calendarId = $calendar->getId();
207
208 $return = array();
209 $return[] = 'permissions';
210 $return[] = $permissionId;
211 $return[] = $calendarId;
212
213 $return = join( '_', $return );
214
215 return $return;
216 }
217 }