2013-03-08 13:16:02 +01:00
< ? php
App :: uses ( 'AppModel' , 'Model' );
2016-08-25 11:38:37 +02:00
2013-03-08 13:16:02 +01:00
class Role extends AppModel {
public $validate = array (
2015-10-09 15:59:25 +02:00
'valueNotEmpty' => array (
'rule' => array ( 'valueNotEmpty' ),
2013-03-08 13:16:02 +01:00
),
);
public $hasMany = array (
'User' => array (
'className' => 'User' ,
'foreignKey' => 'role_id' ,
'dependent' => false ,
'conditions' => '' ,
'fields' => '' ,
'order' => '' ,
'limit' => '' ,
'offset' => '' ,
'exclusive' => '' ,
'finderQuery' => '' ,
'counterQuery' => ''
)
);
public $actsAs = array (
'Trim' ,
2013-03-07 11:51:43 +01:00
'SysLogLogable.SysLogLogable' => array ( // TODO Audit, logable
'roleModel' => 'Role' ,
'roleKey' => 'role_id' ,
'change' => 'full'
2013-03-08 13:16:02 +01:00
),
);
public $virtualFields = array (
2016-07-11 20:24:03 +02:00
'permission' => " CASE WHEN (Role.perm_add + Role.perm_modify + Role.perm_publish = 3) THEN '3' WHEN (Role.perm_add + Role.perm_modify_org = 2) THEN '2' WHEN (Role.perm_add = 1) THEN '1' ELSE '0' END " ,
2013-03-08 13:16:02 +01:00
);
2015-04-07 14:47:14 +02:00
public $permFlags = array (
'perm_admin' => array ( 'id' => 'RolePermAdmin' , 'text' => 'Admin' ),
'perm_site_admin' => array ( 'id' => 'RolePermSiteAdmin' , 'text' => 'Site Admin' ),
'perm_sync' => array ( 'id' => 'RolePermSync' , 'text' => 'Sync Actions' ),
'perm_audit' => array ( 'id' => 'RolePermAudit' , 'text' => 'Audit Actions' ),
'perm_auth' => array ( 'id' => 'RolePermAuth' , 'text' => 'Auth key access' ),
'perm_regexp_access' => array ( 'id' => 'RolePermRegexpAccess' , 'text' => 'Regex Actions' ),
2016-03-30 18:32:17 +02:00
'perm_tagger' => array ( 'id' => 'RolePermTagger' , 'text' => 'Tagger' ),
'perm_tag_editor' => array ( 'id' => 'RolePermTagEditor' , 'text' => 'Tag Editor' ),
2015-04-07 14:47:14 +02:00
'perm_template' => array ( 'id' => 'RolePermTemplate' , 'text' => 'Template Editor' ),
'perm_sharing_group' => array ( 'id' => 'RolePermSharingGroup' , 'text' => 'Sharing Group Editor' ),
2016-07-18 01:12:54 +02:00
'perm_delegate' => array ( 'id' => 'RolePermDelegate' , 'text' => 'Delegations access' )
2015-04-07 14:47:14 +02:00
);
2016-06-04 01:08:16 +02:00
2015-08-31 02:32:37 +02:00
public $premissionLevelName = array ( 'Read Only' , 'Manage Own Events' , 'Manage Organisation Events' , 'Manage and Publish Organisation Events' );
2013-04-25 14:04:08 +02:00
2013-03-08 13:16:02 +01:00
public function beforeSave ( $options = array ()) {
switch ( $this -> data [ 'Role' ][ 'permission' ]) {
case '0' :
2016-07-11 20:22:42 +02:00
$this -> data [ 'Role' ][ 'perm_add' ] = 0 ;
$this -> data [ 'Role' ][ 'perm_modify' ] = 0 ;
$this -> data [ 'Role' ][ 'perm_modify_org' ] = 0 ;
$this -> data [ 'Role' ][ 'perm_publish' ] = 0 ;
2013-03-08 13:16:02 +01:00
break ;
case '1' :
2016-07-11 20:22:42 +02:00
$this -> data [ 'Role' ][ 'perm_add' ] = 1 ;
$this -> data [ 'Role' ][ 'perm_modify' ] = 1 ; // SHOULD BE true
$this -> data [ 'Role' ][ 'perm_modify_org' ] = 0 ;
$this -> data [ 'Role' ][ 'perm_publish' ] = 0 ;
2013-03-08 13:16:02 +01:00
break ;
case '2' :
2016-07-11 20:22:42 +02:00
$this -> data [ 'Role' ][ 'perm_add' ] = 1 ;
$this -> data [ 'Role' ][ 'perm_modify' ] = 1 ;
$this -> data [ 'Role' ][ 'perm_modify_org' ] = 1 ;
$this -> data [ 'Role' ][ 'perm_publish' ] = 0 ;
2013-03-08 13:16:02 +01:00
break ;
case '3' :
2016-07-11 20:22:42 +02:00
$this -> data [ 'Role' ][ 'perm_add' ] = 1 ;
$this -> data [ 'Role' ][ 'perm_modify' ] = 1 ; // ?
$this -> data [ 'Role' ][ 'perm_modify_org' ] = 1 ; // ?
$this -> data [ 'Role' ][ 'perm_publish' ] = 1 ;
2013-03-08 13:16:02 +01:00
break ;
default :
break ;
}
return true ;
}
2016-06-06 10:09:55 +02:00
}