From c87b48e0345aa40b12188983a80b34250832c901 Mon Sep 17 00:00:00 2001 From: nate Date: Sat, 10 Feb 2007 20:28:22 +0000 Subject: [PATCH] Refactoring AclBehavior git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4501 3807eeeb-6ff5-0310-8944-8be069107fe0 --- .../components/dbacl/models/aclnode.php | 2 +- cake/libs/model/behaviors/acl.php | 44 ++++++------------- cake/libs/model/model.php | 6 +-- 3 files changed, 17 insertions(+), 35 deletions(-) diff --git a/cake/libs/controller/components/dbacl/models/aclnode.php b/cake/libs/controller/components/dbacl/models/aclnode.php index 652dfab8d..744f37239 100644 --- a/cake/libs/controller/components/dbacl/models/aclnode.php +++ b/cake/libs/controller/components/dbacl/models/aclnode.php @@ -65,7 +65,7 @@ class AclNode extends AppModel { $prefix = $this->tablePrefix; if (empty($ref)) { - $ref = array('model' => $this->name, 'foreign_key' => $this->id); + return null; } elseif (is_string($ref)) { $path = explode('/', $ref); $start = $path[count($path) - 1]; diff --git a/cake/libs/model/behaviors/acl.php b/cake/libs/model/behaviors/acl.php index 35e8a06eb..0ba05f742 100644 --- a/cake/libs/model/behaviors/acl.php +++ b/cake/libs/model/behaviors/acl.php @@ -39,8 +39,19 @@ if (!defined('ACL_DATABASE')) { */ class AclBehavior extends ModelBehavior { +/** + * Maps ACL type options to ACL models + * + * @var array + * @access protected + */ var $__typeMaps = array('requester' => 'Aro', 'controlled' => 'Aco'); - +/** + * Sets up the configuation for the model, and loads ACL models if they haven't been already + * + * @param mixed $config + * @return void + */ function setup(&$model, $config = array()) { if (is_string($config)) { $config = array('type' => $config); @@ -69,40 +80,11 @@ class AclBehavior extends ModelBehavior { * @return array */ function node(&$model, $ref = null) { - $db =& ConnectionManager::getDataSource($model->useDbConfig); $type = $this->__typeMaps[low($this->settings[$model->name]['type'])]; - $table = low($type) . 's'; - $prefix = $model->tablePrefix; - $axo =& $model->{$type}; - if (empty($ref)) { $ref = array('model' => $model->name, 'foreign_key' => $model->id); - } elseif (is_string($ref)) { - $path = explode('/', $ref); - $start = $path[count($path) - 1]; - unset($path[count($path) - 1]); - - $query = "SELECT {$type}0.* From {$prefix}{$table} AS {$type}0 "; - foreach ($path as $i => $alias) { - $j = $i - 1; - $k = $i + 1; - $query .= "LEFT JOIN {$prefix}{$table} AS {$type}{$k} "; - $query .= "ON {$type}{$k}.lft > {$type}{$i}.lft && {$type}{$k}.rght < {$type}{$i}.rght "; - $query .= "AND {$type}{$k}.alias = " . $db->value($alias) . " "; - } - $result = $axo->query("{$query} WHERE {$type}0.alias = " . $db->value($start)); - - if (!empty($result)) { - $result = $result[0]["{$type}0"]; - } - } elseif (is_object($ref) && is_a($ref, 'Model')) { - $ref = array('model' => $ref->name, 'foreign_key' => $ref->id); } - - if (is_array($ref) && !empty($ref)) { - list($result) = array_values($axo->find($ref, null, null, -1)); - } - return $result; + return $model->{$type}->node($ref); } /** * Creates a new ARO/ACO node bound to this record diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index 355da2448..04def321c 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -1204,6 +1204,8 @@ class Model extends Overloadable { * @return boolean True on success */ function del($id = null, $cascade = true) { + pr($this->name); + pr($this->trace()); if (!empty($id)) { $this->id = $id; } @@ -1226,9 +1228,7 @@ class Model extends Overloadable { $this->_deleteDependent($this->id, $cascade); if (!empty($this->behaviors)) { for ($i = 0; $i < $ct; $i++) { - if ($this->behaviors[$behaviors[$i]]->afterDelete($this) === false) { - return false; - } + $this->behaviors[$behaviors[$i]]->afterDelete($this); } } $this->afterDelete();