Skip to content
18 changes: 13 additions & 5 deletions src/Model/Behavior/AclBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,16 @@ public function __construct(Table $model, array $config = [])
}
foreach ($types as $type) {
$alias = Inflector::pluralize($type);
$className = App::className($alias . 'Table', 'Model/Table');
$className = App::className($alias, 'Model/Table', 'Table');
if ($className == false) {
$className = App::className('Acl.' . $alias . 'Table', 'Model/Table');
$className = App::className('Acl.' . $alias, 'Model/Table', 'Table');
}
$config = [];
if (!TableRegistry::getTableLocator()->exists($alias)) {
$config = ['className' => $className];
}
$model->hasMany($type, [

$model->hasMany($alias, [
'targetTable' => TableRegistry::getTableLocator()->get($alias, $config),
]);
}
Expand All @@ -94,7 +95,7 @@ public function __construct(Table $model, array $config = [])
* Retrieves the Aro/Aco node for this model
*
* @param string|array|Model $ref Array with 'model' and 'foreign_key', model object, or string value
* @param string $type Only needed when Acl is set up as 'both', specify 'Aro' or 'Aco' to get the correct node
* @param string $type Pluralized! Only needed when Acl is set up as 'both', specify 'Aros' or 'Acos' to get the correct node
* @return \Cake\ORM\Query
* @link https://book.cakephp.org/2.0/en/core-libraries/behaviors/acl.html#node
* @throws \Cake\Core\Exception\Exception
Expand All @@ -113,7 +114,12 @@ public function node($ref = null, $type = null)
throw new Exception\Exception(__d('cake_dev', 'ref parameter must be a string or an Entity'));
}

return $this->_table->{$type}->node($ref);
if(property_exists($this->_table, $type)){
return $this->_table->{$type}->node($ref);
}else{
$type = Inflector::pluralize($type);
return $this->_table->{$type}->node($ref);
}
}

/**
Expand All @@ -131,6 +137,7 @@ public function afterSave(Event $event, Entity $entity)
$types = [$types];
}
foreach ($types as $type) {
$type = Inflector::pluralize($type);
$parent = $entity->parentNode();
if (!empty($parent)) {
$parent = $this->node($parent, $type)->first();
Expand Down Expand Up @@ -171,6 +178,7 @@ public function afterDelete(Event $event, Entity $entity)
$types = [$types];
}
foreach ($types as $type) {
$type = Inflector::pluralize($type);
$node = $this->node($entity, $type)->toArray();
if (!empty($node)) {
$event->getSubject()->{$type}->delete($node[0]);
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Table/AcoActionsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class AcoActionsTable extends Table
public function initialize(array $config) :void
{
$this->belongsTo('Acos', [
'className' => App::className('Acl.AcosTable', 'Model/Table'),
'className' => 'Acl.Acos'
]);
}
}
8 changes: 4 additions & 4 deletions src/Model/Table/AcosTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ public function initialize(array $config) :void
$this->addBehavior('Tree', ['type' => 'nested']);

$this->belongsToMany('Aros', [
'through' => App::className('Acl.PermissionsTable', 'Model/Table'),
'className' => App::className('Acl.ArosTable', 'Model/Table'),
'through' => 'Acl.Permissions',
'className' => 'Acl.Aros',
]);
$this->hasMany('AcoChildren', [
'className' => App::className('Acl.AcosTable', 'Model/Table'),
'className' => 'Acl.Acos',
'foreignKey' => 'parent_id',
]);
$this->setEntityClass(App::className('Acl.Aco', 'Model/Entity'));
$this->setEntityClass('Acl.Aco');
}
}
6 changes: 3 additions & 3 deletions src/Model/Table/ArosTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ public function initialize(array $config) :void
$this->addBehavior('Tree', ['type' => 'nested']);

$this->belongsToMany('Acos', [
'through' => App::className('Acl.PermissionsTable', 'Model/Table'),
'className' => App::className('Acl.AcosTable', 'Model/Table'),
'through' => 'Acl.Permissions',
'className' => 'Acl.Acos',
]);
$this->hasMany('AroChildren', [
'className' => App::className('Acl.ArosTable', 'Model/Table'),
'className' => 'Acl.Aros',
'foreignKey' => 'parent_id',
]);

Expand Down
4 changes: 2 additions & 2 deletions src/Model/Table/PermissionsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ public function initialize(array $config) :void
$this->setAlias('Permissions');
$this->setTable('aros_acos');
$this->belongsTo('Aros', [
'className' => App::className('Acl.ArosTable', 'Model/Table'),
'className' => 'Acl.Aros'
]);
$this->belongsTo('Acos', [
'className' => App::className('Acl.AcosTable', 'Model/Table'),
'className' => 'Acl.Acos'
]);
$this->Aro = $this->Aros->getTarget();
$this->Aco = $this->Acos->getTarget();
Expand Down