PluginProbe
ShiftController Employee Shift Scheduling / 4.9.26
ShiftController Employee Shift Scheduling v4.9.26
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.26, at sh4/calendars/permissions.php

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