47 'disableInheritance' =>
false,
59 if(is_object($conditions) && get_class($conditions) ==
'CDbCriteria'){
60 $criteria = $conditions;
63 $criteria =
new CDbCriteria;
64 $criteria->mergeWith(array(
65 'condition' => $conditions,
77 $criteria->distinct =
true;
81 $collection =
'INNER JOIN `'.$acoClass::model()->tableName().
'` AS acoC ON acoC.model = :RAR_model AND acoC.foreign_key = t.id';
82 $criteria->params[
':RAR_model'] = get_class($this);
86 $nodes =
' INNER JOIN `'.$acoNodeClass::model()->tableName().
'` AS aco ON aco.collection_id = acoC.id';
91 $aro = $aroClass::model()->find(
'model = :model AND foreign_key = :foreign_key',
92 array(
':model'=> static::$model,
':foreign_key' => $user->id));
97 $aro = $aroClass::model()->find(
'alias = :alias',
98 array(
':alias' => $guest));
106 $aroPositions = $aro->fetchComprisedPositions();
107 $aroPositionCheck = $aro->addPositionCheck($aroPositions,
"aro",
"map");
110 $action =
Action::model()->find(
'name = :name', array(
':name' =>
'read'));
113 throw new RuntimeException(
'Unable to find action read');
116 $acoCondition = $acoClass::buildTreeQueryCondition(
117 array(
'table' =>
'aco'),
118 array(
'table' =>
'map',
'field' =>
'aco'),
119 $options[
'disableInheritance']
121 $connection =
' INNER JOIN `'.Permission::model()->tableName().
'` AS map ON '.$acoCondition.
' AND '.$aroPositionCheck.
' AND map.action_id = :acl_action_id';
122 $criteria->params[
':acl_action_id'] = $action->id;
124 $joins = array($collection, $nodes, $connection);
126 foreach($joins as $join){
127 $criteria->mergeWith(array(
'join' => $join),
true);
135 public function find($conditions =
'', $params = array()){
143 public function findByPk($pk, $conditions =
'', $params = array()){
152 public function findAll($conditions =
'', $params = array()){
160 public function findAllByPk($pk, $conditions =
'', $params = array()){
179 $actions =
Action::model()->findAll(
'name '.$actionCondition);
181 $actionIds = array();
182 foreach($actions as $action){
183 $actionIds[] = $action->id;
190 $positions = $aco->fetchComprisedPositions();
195 $rGroupTable = RGroup::model()->tableName();
196 $nodeTable = $aroNodeClass::model()->tableName();
198 return Yii::app()->db->createCommand()
199 ->selectDistinct(
't.id AS collection_id, t.foreign_key, t.model, p.action_id')
200 ->from($rGroupTable.
' t')
201 ->join($nodeTable.
' n',
'n.collection_id = t.id')
202 ->join($permTable.
' p',
203 'p.aro_id = n.id AND p.aco_path '.$acoCondition.
' AND p.action_id '. $actionIdCondition)
215 if(!$this->isNewRecord){
218 if(!$aro->may($this,
'update'))
219 throw new RuntimeException(
'You are not allowed to update this record');
232 if(!$aro->may($this,
'delete'))
233 throw new RuntimeException(
'You are not allowed to delete this record');
237 $aco = $class::model()->find(
'model = :model AND foreign_key = :key', array(
':model' => get_class($this),
':key' => $this->
id));
239 throw new RuntimeException(
'No associated Aco!');
242 throw new RuntimeException(
'Unable to delete associated Aco');
255 if($this->isNewRecord){
261 $aco->model = get_class($this);
262 $aco->foreign_key = $this->getPrimaryKey();
265 throw new RuntimeException(
'Unable to create corresponding Aco for new '.get_class($this));
268 $aro->grant($aco,
'*');
279 return $aro->may($this, $permission);
291 if(self::$inAttendance !== NULL)
294 $user = Yii::app()->user;
296 $aro = $class::model()->find(
'model = :model AND foreign_key = :foreign_key',
297 array(
'model' => static::$model,
'foreign_key' => $user->id));
299 throw new RuntimeException(
'Invalid Aro');