77
88class Permissions
99{
10- public const pageAddPermission = ' page-add ' ;
11- public const pageCreatePermission = ' page-create ' ;
12- public const pageDeletePermission = ' page-delete ' ;
13- public const pageEditPermission = ' page-edit ' ;
14- public const pageMovePermission = ' page-move ' ;
15- public const pageViewPermission = ' page-view ' ;
16- public const pageEditCreatedPermission = ' page-edit-created ' ;
17- public const pageEditTrashCreatedPermission = ' page-edit-trash-created ' ;
10+ public const pageAddPermission = " page-add " ;
11+ public const pageCreatePermission = " page-create " ;
12+ public const pageDeletePermission = " page-delete " ;
13+ public const pageEditPermission = " page-edit " ;
14+ public const pageMovePermission = " page-move " ;
15+ public const pageViewPermission = " page-view " ;
16+ public const pageEditCreatedPermission = " page-edit-created " ;
17+ public const pageEditTrashCreatedPermission = " page-edit-trash-created " ;
1818
1919 /**
2020 * Checks if the page using this template can be viewed by the current user.
@@ -60,23 +60,27 @@ public static function canCreate(Template $template)
6060 }
6161
6262 // can't create if allowed parents are not legal
63- if ($ template ->noParents == 0 && count ($ template ->parentTemplates )) {
64-
63+ if (!$ template ->noParents && count ($ template ->parentTemplates )) {
6564 // filter out the parents that has noChildren checked or
6665 // has configured childTemplates without the target template
67- $ parentTemplates = array_filter ($ template ->parentTemplates , function ($ templateId ) use ($ template ) {
66+ $ parentTemplates = array_filter ($ template ->parentTemplates , function (
67+ $ templateId
68+ ) use ($ template ) {
6869 $ parentTemplate = Utils::templates ()->get ($ templateId );
6970 if ($ parentTemplate ->noChildren ) {
7071 return false ;
7172 }
72- if (count ($ parentTemplate ->childTemplates ) && !in_array ($ template ->id , $ parentTemplate ->childTemplates )) {
73+ if (
74+ count ($ parentTemplate ->childTemplates ) &&
75+ !in_array ($ template ->id , $ parentTemplate ->childTemplates )
76+ ) {
7377 return false ;
7478 }
7579 return true ;
7680 });
7781
7882 // get templates that user can add pages to
79- $ addTemplates = self ::getAddTemplates ()->explode (' id ' );
83+ $ addTemplates = self ::getAddTemplates ()->explode (" id " );
8084 if (!count (array_intersect ($ addTemplates , $ parentTemplates ))) {
8185 return false ;
8286 }
@@ -219,7 +223,11 @@ public static function canAdd(Template $template)
219223
220224 // can't add a page if the allowed childTemplates are not legal
221225 if ($ template ->noChildren == 0 && count ($ template ->childTemplates )) {
222- if (!count (array_intersect (self ::getTemplateIds (), $ template ->childTemplates ))) {
226+ if (
227+ !count (
228+ array_intersect (self ::getTemplateIds (), $ template ->childTemplates )
229+ )
230+ ) {
223231 return false ;
224232 }
225233 }
@@ -251,7 +259,7 @@ public static function canAdd(Template $template)
251259 */
252260 public static function canEditField (Field $ field , Template $ template )
253261 {
254- return self ::hasFieldPermission (' edit ' , $ field , $ template );
262+ return self ::hasFieldPermission (" edit " , $ field , $ template );
255263 }
256264
257265 /**
@@ -263,7 +271,7 @@ public static function canEditField(Field $field, Template $template)
263271 */
264272 public static function canViewField (Field $ field , Template $ template )
265273 {
266- return self ::hasFieldPermission (' view ' , $ field , $ template );
274+ return self ::hasFieldPermission (" view " , $ field , $ template );
267275 }
268276
269277 /**
@@ -274,8 +282,11 @@ public static function canViewField(Field $field, Template $template)
274282 * @param Template $template The context of the field.
275283 * @return boolean Returns true if user has rights and false otherwise
276284 */
277- public static function hasFieldPermission (string $ permission , Field $ field , Template $ template )
278- {
285+ public static function hasFieldPermission (
286+ string $ permission ,
287+ Field $ field ,
288+ Template $ template
289+ ) {
279290 $ user = Utils::user ();
280291
281292 // can view/edit a field if superuser
@@ -289,7 +300,7 @@ public static function hasFieldPermission(string $permission, Field $field, Temp
289300 return false ;
290301 }
291302
292- $ roles = $ permission . ' Roles ' ;
303+ $ roles = $ permission . " Roles " ;
293304
294305 foreach ($ user ->roles as $ role ) {
295306 if (in_array ($ role ->id , $ field ->$ roles )) {
@@ -300,7 +311,6 @@ public static function hasFieldPermission(string $permission, Field $field, Temp
300311 return false ;
301312 }
302313
303-
304314 /**
305315 * Tells if the template or field has access control defined.
306316 *
@@ -309,7 +319,7 @@ public static function hasFieldPermission(string $permission, Field $field, Temp
309319 */
310320 public static function definesAccess ($ context )
311321 {
312- return (boolean ) $ context ->useRoles ;
322+ return (bool ) $ context ->useRoles ;
313323 }
314324
315325 /**
@@ -320,7 +330,7 @@ public static function definesAccess($context)
320330 public static function getTemplates ()
321331 {
322332 $ templates = Utils::templates ();
323- $ legalTemplateNames = implode (' | ' , Utils::module ()->legalTemplates );
333+ $ legalTemplateNames = implode (" | " , Utils::module ()->legalTemplates );
324334 return $ templates ->find ("name= $ legalTemplateNames " );
325335 }
326336
@@ -331,7 +341,7 @@ public static function getTemplates()
331341 */
332342 public static function getTemplateIds ()
333343 {
334- return array_merge ([], self ::getTemplates ()->explode (' id ' ));
344+ return array_merge ([], self ::getTemplates ()->explode (" id " ));
335345 }
336346
337347 public static function filterTemplatesByPermission ($ predicator )
0 commit comments