Skip to content

Instantly share code, notes, and snippets.

@balrok
Created June 23, 2010 13:49
Show Gist options
  • Save balrok/449932 to your computer and use it in GitHub Desktop.
Save balrok/449932 to your computer and use it in GitHub Desktop.
diff --git a/EBehavior.php b/EBehavior.php
index 72b3dc5..cccf17d 100755
--- a/EBehavior.php
+++ b/EBehavior.php
@@ -22,6 +22,16 @@
* @copyright Evresis A.E. <www.evresis.gr>
*/
class EBehavior extends CBehavior {
+ // specify a criteria with which the tree should be searched:
+ // for example: array('column1'=>2)
+ public $criteria;
+
+ // will set the initial values for the columns
+ // array('default'=>array('name'=>'string'), // default is special and will apply to all
+ // array('createroot'=>array('userid'=>1),
+ // array('createnode'=>array('name'=>'other string')), // will overwrite default
+ public $attributes;
+
/**
* @var string the name of the model class
*/
@@ -61,15 +71,11 @@ class EBehavior extends CBehavior {
*/
public $nodenaming;
- /**
- * New node's default name
- */
- public $defaultNodeName = 'New folder';
-
- /**
- * New root's default name
- */
- public $defaultRootName = 'New root';
+ public function __construct()
+ {
+ if(!$this->criteria)
+ $this->criteria = array();
+ }
/**
* Used internal function that takes a node and returns it as string.
@@ -163,11 +169,6 @@ class EBehavior extends CBehavior {
* @return CJSON::encode the node inserted in json encode
*/
public function insertingnode( $newnode=null,$refnode=null,$type=null, $nodenaming=true , $inheritvalues=false ) {
-// if ( $type=="inside") {
-// $parent=$refnode;
-// } else {
-// $parent=$refnode->parent();
-// }
$parent = ($type=="inside") ? $refnode : $refnode->parent();
$newnode= ($nodenaming) ? $this->nodeNaming($parent, $newnode) : $newnode;
@@ -257,5 +258,14 @@ class EBehavior extends CBehavior {
}
//}
}
+
+
+ public function getAttributes($class)
+ {
+ $attributes = $this->attributes;
+ $default_att = (isset($attributes['default']))?$attributes['default']:array();
+ $this_att = (isset($attributes[$class]))?$attributes[$class]:array();
+ return CMap::mergeArray($default_att, $this_att);
+ }
}
?>
diff --git a/EJsTreeEx.php b/EJsTreeEx.php
index d33d9e3..56b5718 100644
--- a/EJsTreeEx.php
+++ b/EJsTreeEx.php
@@ -217,4 +217,4 @@ class EJsTreeEx extends CJsTree {
parent::run();
}
-}
\ No newline at end of file
+}
diff --git a/actions/Createnode.php b/actions/Createnode.php
index 9141232..02f54a0 100755
--- a/actions/Createnode.php
+++ b/actions/Createnode.php
@@ -17,8 +17,6 @@ class Createnode extends CAction {
* This method calls the insertingnode() method from EBehavior.php
*/
public function run(){
- $defaultname = $this->getController()->defaultNodeName;
-
$refid=$_POST['ref_id'];
$type=$_POST['type'];
@@ -26,9 +24,9 @@ class Createnode extends CAction {
$modelclass=$this->getController()->classname;
$newnode=new $modelclass();
- $newnode->setAttribute($this->getController()->text,$defaultname);
+ $newnode->attributes = $this->getController()->getAttributes(strtolower(__CLASS__));
echo $this->getController()->insertingnode( $newnode,$refnode,$type,true,$this->getController()->crtinherit);
}
-}
\ No newline at end of file
+}
diff --git a/actions/Createroot.php b/actions/Createroot.php
index 9f71203..35ea7bc 100644
--- a/actions/Createroot.php
+++ b/actions/Createroot.php
@@ -10,13 +10,11 @@
*/
class Createroot extends CAction {
public function run(){
- $hasmanyroots = CActiveRecord::model($this->getController()->classname)->hasManyRoots;
+ $hasmanyroots = CActiveRecord::model($this->getController()->classname)->hasManyRoots;
if($hasmanyroots){
- $defaultname = $this->getController()->defaultRootName;
$modelclass=$this->getController()->classname;
$newroot = new $modelclass();
- $newroot->setAttribute($this->getController()->text,$defaultname);
- $newroot = $this->getController()->nodenaming( null , $newroot );
+ $newroot->attributes = $this->getController()->getAttributes(strtolower(__CLASS__));
$newroot->setAttribute($newroot->root, 1);
if ( $newroot->saveNode(false,null) ) {
echo 1;die;
@@ -24,4 +22,4 @@ class Createroot extends CAction {
}
echo 0;die;
}
-}
\ No newline at end of file
+}
diff --git a/actions/Movenode.php b/actions/Movenode.php
index 23cb431..0007d25 100755
--- a/actions/Movenode.php
+++ b/actions/Movenode.php
@@ -37,8 +37,6 @@ class Movenode extends CAction {
$parent = ($type=="inside") ? $refnode : $refnode->parent();
- $current=$this->getController()->nodeNaming($parent,$current);
-
$current->saveNode();
diff --git a/actions/Renamenode.php b/actions/Renamenode.php
index f0d2e4e..a3a7d2a 100755
--- a/actions/Renamenode.php
+++ b/actions/Renamenode.php
@@ -22,13 +22,13 @@ class Renamenode extends CAction {
$checkname = true;
if($node->isRoot()) {
if( $node->hasManyRoots ) {
- $siblings = CActiveRecord::model($this->getController()->classname)->roots()->findall();
+ $siblings = CActiveRecord::model($this->getController()->classname)->roots()->findall($this->getController()->criteria);
} else {
$checkname = false;
}
} else {
$parent=$node->parent();
- $siblings=$parent->children()->findAll();
+ $siblings=$parent->children()->findAll($this->getController()->criteria);
}
diff --git a/actions/Render.php b/actions/Render.php
index 6ebc346..00bd24d 100755
--- a/actions/Render.php
+++ b/actions/Render.php
@@ -27,14 +27,14 @@ class Render extends CAction {
$id=$_GET['id'];
if ( $id==0 ) {
- $nodestoformat = CActiveRecord::model($this->getController()->classname)->roots()->findall();
+ $nodestoformat = CActiveRecord::model($this->getController()->classname)->roots()->findall($this->getController()->criteria);
} else {
$node= CActiveRecord::model($this->getController()->classname)->findByPk($id);
- $nodestoformat=$node->children()->findall();
+ $nodestoformat=$node->children()->findall($this->getController()->criteria);
}
$rootsdata=$this->getController()->formatNode($nodestoformat);
echo CJSON::encode($rootsdata);
}
-}
\ No newline at end of file
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment