TimeTrex/classes/modules/plugins/PermissionFactory.plugin.example

80 lines
2.5 KiB
Plaintext
Raw Normal View History

2022-12-13 07:10:06 +01:00
<?php
/*$License$*/
//
// Example plugin to modify available permissions
//
class PermissionFactoryPlugin extends PermissionListFactoryPlugin {
private $exclude_section_group = array( 'payroll' ); //Disable entire payroll section group
private $exclude_section = array( 'request' ); //Disable entire request section
private $exclude_name = array(
'absence' => array('view', 'edit'), //Disable specific permissions in absence section
'user' => array('edit_own_bank', 'edit_child_bank'), //Disable specific permission in user section
);
function _getFactoryOptions( $name, $parent = NULL ) {
$retarr = parent::_getFactoryOptions( $name );
switch( $name ) {
case 'section_group':
case 'section_group_map':
if ( is_array( $this->exclude_section_group) ) {
foreach( $this->exclude_section_group as $exclude_section_group ) {
unset($retarr[$exclude_section_group]);
}
}
break;
case 'section':
//Exclude entire groups first.
$section_group_map = parent::_getFactoryOptions( 'section_group_map' );
if ( is_array( $this->exclude_section_group) ) {
foreach( $this->exclude_section_group as $exclude_section_group ) {
foreach( $section_group_map[$exclude_section_group] as $exclude_section_from_group ) {
$this->exclude_section[] = $exclude_section_from_group;
}
}
}
//Exclude individual sections next.
if ( is_array($this->exclude_section) ) {
foreach( $this->exclude_section as $exclude_section ) {
unset($retarr[$exclude_section]);
}
}
break;
case 'name':
//Exclude entire groups first.
$section_group_map = parent::_getFactoryOptions( 'section_group_map' );
if ( is_array( $this->exclude_section_group) ) {
foreach( $this->exclude_section_group as $exclude_section_group ) {
foreach( $section_group_map[$exclude_section_group] as $exclude_section_from_group ) {
$this->exclude_section[] = $exclude_section_from_group;
}
}
}
//Exclude individual sections next.
if ( is_array($this->exclude_section) ) {
foreach( $this->exclude_section as $exclude_section ) {
unset($retarr[$exclude_section]); //Remove all sections in the payroll group.
}
}
//Exclude individual permissions last.
if ( is_array($this->exclude_name) ) {
foreach( $this->exclude_name as $exclude_section => $exclude_name_arr ) {
foreach( $exclude_name_arr as $exclude_name ) {
unset($retarr[$exclude_section][$exclude_name]);
}
}
}
break;
}
return $retarr;
}
}