'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 * @access public */ function setup(&$model, $config = array()) { if (is_string($config)) { $config = array('type' => $config); } $this->settings[$model->name] = array_merge(array('type' => 'requester'), (array)$config); $type = $this->__typeMaps[$this->settings[$model->name]['type']]; if (!class_exists('AclNode')) { require LIBS . 'model' . DS . 'db_acl.php'; } $model->{$type} =& ClassRegistry::init($type); if (!method_exists($model, 'parentNode')) { trigger_error("Callback parentNode() not defined in {$model->alias}", E_USER_WARNING); } } /** * Retrieves the Aro/Aco node for this model * * @param mixed $ref * @return array * @access public */ function node(&$model, $ref = null) { $type = $this->__typeMaps[strtolower($this->settings[$model->name]['type'])]; if (empty($ref)) { $ref = array('model' => $model->name, 'foreign_key' => $model->id); } return $model->{$type}->node($ref); } /** * Creates a new ARO/ACO node bound to this record * * @param boolean $created True if this is a new record * @return void * @access public */ function afterSave(&$model, $created) { if ($created) { $type = $this->__typeMaps[strtolower($this->settings[$model->name]['type'])]; $parent = $model->parentNode(); if (!empty($parent)) { $parent = $this->node($model, $parent); } else { $parent = null; } $model->{$type}->create(); $model->{$type}->save(array( 'parent_id' => Set::extract($parent, "0.{$type}.id"), 'model' => $model->name, 'foreign_key' => $model->id )); } } /** * Destroys the ARO/ACO node bound to the deleted record * * @return void * @access public */ function afterDelete(&$model) { $type = $this->__typeMaps[strtolower($this->settings[$model->name]['type'])]; $node = Set::extract($this->node($model), "0.{$type}.id"); if (!empty($node)) { $model->{$type}->delete($node); } } } ?>