25 return $class::findAll(
'collection_id = :id AND path =""', array(
':id' => $this->
id));
35 $nodes = $nodeClass::model()->findAll(
'collection_id = :id', array(
':id' => $this->
id));
38 foreach($nodes as $node){
55 $source[
'field'] =
'path';
56 $sourcePrefix = $source[
'table'].
'.'.$source[
'field'];
58 $pathExpression =
'CONCAT("^", '.$sourcePrefix.
', '
59 .$source[
'table'].
'.id, '
62 $method = !$disableInheritance ?
'REGEX' :
'=';
64 return $destination[
'table'].
'.'.$destination[
'field'].
'_path'
65 .
' '.$method.
' '.$pathExpression;
88 $preparedConditions =
' ( ';
90 foreach($positions as $key =>$position){
92 $preparedConditions .=
' OR ';
93 $preparedConditions .= sprintf(
" ( '%s' REGEXP CONCAT('^', %s.%s_path ))",
94 $position, $table, $type);
97 $preparedConditions .=
' ) ';
99 return $preparedConditions;
112 $node =
new $class();
113 $node->collection_id = $this->id;
122 throw new RuntimeException(
'Unable to create Node');
144 $nodes = $this->getNOdes();
147 foreach($nodes as $node){
155 $condition .=
' AND t.collection_id = :id ';
156 $params[
':id'] = $parent->id;
159 return $nodeName::model()->with($type)->findAll(
' t.path '.$condition);
181 foreach($paths as $path){
187 $ids[] = $info[
'id'];
193 if($parent !== NULL){
194 $condition .=
' AND collection_id = :id ';
195 $params[
':id'] = $parent->id;
198 return $nodeName::model()->with($type)->findAll(
' t.id '.$condition);
213 $num = $class::model()->deleteAll($condition);
216 throw new RuntimeException(
'Unable to delete all nodes of '.$this->
id);
220 throw new RuntimeException(
'Unable to delete associated permissions of '.$this->
id);
222 return $num !==
false;
234 $objNodes = $obj->getNodes();
236 $transaction = Yii::app()->db->beginTransaction();
238 foreach($objNodes as $objNode){
241 $transaction->commit();
244 $transaction->rollback();
260 $paths = $obj->getPaths();
264 $oneLevelCondition =
'path = ":path"';
267 $transaction = Yii::app()->db->beginTransaction();
269 $nodes = $nodeClass::model()->findAll(
'collection_id = :id AND '.$pathCondition,
270 array(
':id' => $this->
id));
272 foreach($nodes as $node){
274 throw new RuntimeException(
'Unable to delete node');
276 $transaction->commit();
280 $transaction->rollback();
290 public function is($obj){
294 $paths = $obj->getPaths();
300 return $nodeClass::model()->find(
'collection_id = :id AND'.$pathCondition,
301 array(
':id' => $this->
id)) !== NULL;