acl.php
Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 class AclBehavior extends ModelBehavior {
00038
00039
00040
00041
00042
00043
00044
00045 var $__typeMaps = array('requester' => 'Aro', 'controlled' => 'Aco');
00046
00047
00048
00049
00050
00051 function setup(&$model, $config = array()) {
00052 if (is_string($config)) {
00053 $config = array('type' => $config);
00054 }
00055 $this->settings[$model->alias] = array_merge(array('type' => 'requester'), (array)$config);
00056 $type = $this->__typeMaps[$this->settings[$model->alias]['type']];
00057 if (!class_exists('AclNode')) {
00058 uses('model' . DS . 'db_acl');
00059 }
00060 $model->{$type} =& ClassRegistry::init($type);;
00061 if (!method_exists($model, 'parentNode')) {
00062 trigger_error("Callback parentNode() not defined in {$model->alias}", E_USER_WARNING);
00063 }
00064 }
00065
00066
00067
00068
00069
00070
00071 function node(&$model, $ref = null) {
00072 $type = $this->__typeMaps[strtolower($this->settings[$model->alias]['type'])];
00073 if (empty($ref)) {
00074 $ref = array('model' => $model->alias, 'foreign_key' => $model->id);
00075 }
00076 return $model->{$type}->node($ref);
00077 }
00078
00079
00080
00081
00082
00083 function afterSave(&$model, $created) {
00084 if ($created) {
00085 $type = $this->__typeMaps[strtolower($this->settings[$model->alias]['type'])];
00086 $parent = $model->parentNode();
00087 if (!empty($parent)) {
00088 $parent = $this->node($model, $parent);
00089 } else {
00090 $parent = null;
00091 }
00092
00093 $model->{$type}->create();
00094 $model->{$type}->save(array(
00095 'parent_id' => Set::extract($parent, "0.{$type}.id"),
00096 'model' => $model->alias,
00097 'foreign_key' => $model->id
00098 ));
00099 }
00100 }
00101
00102
00103
00104
00105 function afterDelete(&$model) {
00106 $type = $this->__typeMaps[strtolower($this->settings[$model->alias]['type'])];
00107 $node = Set::extract($this->node($model), "0.{$type}.id");
00108 if (!empty($node)) {
00109 $model->{$type}->delete($node);
00110 }
00111 }
00112 }
00113
00114 ?>