public function testEditParentLeafNodeToDifferentBranch()
 {
     $expected = array(0 => array('Tree' => array('id' => '1', 'name' => '1', 'parent_id' => NULL, 'lft' => '1', 'rght' => '12', 'child_count' => '5', 'direct_child_count' => '3')), 1 => array('Tree' => array('id' => '3', 'name' => '1.1', 'parent_id' => '1', 'lft' => '2', 'rght' => '7', 'child_count' => '2', 'direct_child_count' => '2')), 2 => array('Tree' => array('id' => '6', 'name' => '1.1.1', 'parent_id' => '3', 'lft' => '3', 'rght' => '4', 'child_count' => '0', 'direct_child_count' => '0')), 3 => array('Tree' => array('id' => '8', 'name' => '1.1.3', 'parent_id' => '3', 'lft' => '5', 'rght' => '6', 'child_count' => '0', 'direct_child_count' => '0')), 4 => array('Tree' => array('id' => '4', 'name' => '1.2', 'parent_id' => '1', 'lft' => '8', 'rght' => '9', 'child_count' => '0', 'direct_child_count' => '0')), 5 => array('Tree' => array('id' => '5', 'name' => '1.3', 'parent_id' => '1', 'lft' => '10', 'rght' => '11', 'child_count' => '0', 'direct_child_count' => '0')), 6 => array('Tree' => array('id' => '2', 'name' => '2', 'parent_id' => NULL, 'lft' => '13', 'rght' => '16', 'child_count' => '1', 'direct_child_count' => '1')), 7 => array('Tree' => array('id' => '7', 'name' => '1.1.2', 'parent_id' => '2', 'lft' => '14', 'rght' => '15', 'child_count' => '0', 'direct_child_count' => '0')));
     $Tree = new Tree();
     $Tree->save(array('Tree' => array('id' => '7', 'parent_id' => '2')));
     $results = $Tree->find('all', array('order' => 'lft'));
     $this->assertEqual($results, $expected);
 }
Exemple #2
0
 function doNewTree($newick = null, $import = 0)
 {
     $title = $_REQUEST['title'];
     $description = $_REQUEST['description'];
     $newick = isset($_REQUEST['newick']) ? $_REQUEST['newick'] : $newick;
     $tree = new Tree($this->dbconn);
     if (!$tree->validateTitle($title) or !$tree->validateDescription($description) or !$tree->validateNewick($newick)) {
         $error_data = 1;
     }
     if (!isset($error_data)) {
         $tree->title = $title;
         $tree->description = $description;
         $tree->user_id = $_SESSION['user_id'];
         //парсваме newick текста и ако има SEQ редове си вкарваме и параметрите за нодовете
         $tree->parse($newick);
         if ($tree->save()) {
             //ако след парсването има параметри ги записва и тях
             $tree->saveParameters();
             //ако импортираме от файл
             if ($import == 1) {
                 return TRUE;
             }
             header('Location: tree.php?id=' . $tree->id);
             exit;
         } else {
             //ако импортираме от файл
             if ($import == 1) {
                 return FALSE;
             }
             $this->showErrors();
             $this->newTree();
         }
     } else {
         //ако импортираме от файл
         if ($import == 1) {
             return FALSE;
         }
         $this->showErrors();
         $this->newTree();
     }
 }
Exemple #3
0
 /**
  * New node saved as root
  *
  * @test
  */
 public function can_create_new_node_as_root()
 {
     $root = new Tree();
     $this->assertNotEmpty($root->setAsRoot());
     // Should return this
     $this->assertTrue($root->isRoot(), 'Assert root node');
     // Assert path and level set properly
     $this->assertEquals($root->id, 1);
     $this->assertEquals($root->path, $root->id . '/');
     $this->assertEquals($root->level, 0);
     $this->assertEmpty($root->parent, 'Expected no parent');
     $root2 = new Tree();
     $this->assertNotEmpty($root2->save());
     // Standard save - we expect root node
     $this->assertTrue($root2->isRoot(), 'Assert root node');
     // Assert path, level and parent set properly
     $this->assertEquals($root2->id, 2);
     $this->assertEquals($root2->path, $root2->id . '/');
     $this->assertEquals($root2->level, 0);
     $this->assertEmpty($root2->parent, 'Expected no parent');
 }
Exemple #4
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Tree();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Tree'])) {
         $model->attributes = $_POST['Tree'];
         if (!$model->use_material) {
             $model->use_organization = false;
             $model->use_tape = false;
             $model->module = null;
         } else {
             if (!Yii::app()->user->admin) {
                 $record = Tree::model()->findByPk($model->id_parent);
                 if (count($record) > 0) {
                     $model->module = $record->module;
                 }
             }
         }
         if ($model->save()) {
             $permissionGroups = isset($_POST['Tree']['permissionGroup']) ? $_POST['Tree']['permissionGroup'] : array();
             $permissionUsers = isset($_POST['Tree']['permissionUser']) ? $_POST['Tree']['permissionUser'] : array();
             $model->saveRelationsPermissions($model->id, $model, $permissionGroups, $permissionUsers);
             /* дополнительные настройки прав */
             $flagDopAccessModel = false;
             if ($model->module != null && Yii::app()->user->admin) {
                 $dopAccessModel = new $model->module();
                 if ($dopAccessModel) {
                     $flagDopAccessModel = true;
                 }
             }
             if ($flagDopAccessModel) {
                 $this->redirect(array('access', 'id' => $model->id));
             } else {
                 $this->redirect(array('view', 'id' => $model->id));
             }
         }
     }
     $this->render('create', array('model' => $model));
 }
 public function actionUpdateTree()
 {
     /* @var $tree Tree */
     //get params from request
     $id = Yii::app()->request->getParam('id', null);
     $label = Yii::app()->request->getParam('label', '');
     $status = Yii::app()->request->getParam('status', Constants::STATUS_HIDDEN);
     $type = Yii::app()->request->getParam('type', Constants::TYPE_TEXT_PAGE_1_ARRINGTON);
     $names = Yii::app()->request->getParam('name', array());
     //try to find by pk
     $tree = Tree::model()->findByPk($id);
     //if not found by pk - that means that id not found ind request, need to create new
     if ($tree == null) {
         $tree = new Tree();
     }
     //set main parameters
     $tree->status = $status;
     $tree->type = $type;
     $tree->label = $label;
     //if this is creation
     if ($tree->getIsNewRecord()) {
         //set priority
         $tree->priority = DwHelper::getNextPriority("Tree");
         //creation date
         $tree->date_created = time();
         //last change date
         $tree->date_changed = time();
         //save new record in db
         $tree->save();
     } else {
         //last change date
         $tree->date_changed = time();
         //update
         $tree->update();
     }
     //get all lng objects by active languages on site
     foreach (Constants::GetLngArray() as $lng) {
         //get object
         $treeLng = $tree->getLngObject($lng);
         //set name using multi-language array given from request
         $treeLng->name = $names[$lng];
         //update or create if not exist
         if ($treeLng->getIsNewRecord()) {
             $treeLng->save();
         } else {
             $treeLng->update();
         }
     }
     //back to list
     $this->redirect($this->createUrl('/admin/panel/treelist'));
 }