Example #1
0
 public function action_getTree()
 {
     $id = Arr::get($_POST, 'id');
     $table = Arr::get($_POST, 'table', 'tree');
     $materials = new Model_Material($table);
     $tree = $materials->getTree($id);
     $view = View::factory('/admin/widgets/select')->bind('tree', $tree);
     echo $view;
 }
Example #2
0
 public function createFromGroups($parentId, $groupId)
 {
     $material = new Model_Material('groups');
     $base = new Model_Base();
     //получаем дерево групп
     $groups = $material->getTree($groupId);
     // 1. Получаем количество групп
     $groupCount = count($groups);
     // 2. Получаем крайний правый ключ
     $parentGroup = $material->getNode($groupId);
     $rightKey = (int) $parentGroup['right_key'] + 1;
     // 3. Получаем левый ключ
     $parentNode = $this->nstree->getNode($parentId);
     // получаем левел
     $level = (int) $parentNode['level'];
     $leftKey = (int) $parentNode['left_key'] + 1;
     //echo $leftKey.'-'.$rightKey;
     $this->nstree->modifyNodes($leftKey, $rightKey);
     $parent_node_lk = $parentNode["left_key"];
     $parent_node_rk = $parentNode["right_key"];
     $parent_node_level = $parentNode["level"];
     $parent_group_lk = $parentGroup["left_key"];
     $parent_group_rk = $parentGroup["left_key"];
     $parent_group_level = $parentGroup["level"];
     foreach ($groups as $group) {
         // Преобразование level'a группы для ноды
         $level_offset = $parent_node_level - $parent_group_level;
         $url = $base->str2url($group["name"]);
         while (!$this->unique_url($url)) {
             $url = $url . "-";
         }
         $node = array("name" => $group["name"], "url" => $url, "id" => NULL, "left_key" => $group["left_key"] + $leftKey, "right_key" => $group["right_key"] + $leftKey, "level" => $group["level"] + $level_offset);
         list($insert_id, $tmp) = DB::insert("tree", array_keys($node))->values(array_values($node))->execute();
         DB::query(NULL, "COMMIT")->execute();
         //Подключаем материалы
         $action = "sidebar";
         $left_menu = array("id" => NULL, "node_id" => $insert_id, "widget_id" => 2, "param" => "twig", "action" => $action, "options" => '{"' . $action . '_parent_id":"' . $parentId . '"}', "position" => "left_block", "title" => "Меню", "ordering" => 10);
         //list($insert_id, $tmp) = DB::insert("tree_widgets_rel", array_keys($left_menu))->values(array_values($left_menu))->execute();
         DB::insert("tree_widgets_rel", array_keys($left_menu))->values(array_values($left_menu))->execute();
         $action = "index";
         $catalog = array("id" => NULL, "node_id" => $insert_id, "widget_id" => 1, "param" => "twig", "action" => $action, "options" => '{"' . $action . '_catalog_id":"' . $group['id'] . '"}', "position" => "right_block", "title" => "Каталог", "ordering" => 10);
         //list($insert_id, $tmp) = DB::insert("tree_widgets_rel", array_keys($catalog))->values(array_values($catalog))->execute();
         DB::insert("tree_widgets_rel", array_keys($catalog))->values(array_values($catalog))->execute();
     }
     /*foreach ($groups as $group)
     		{
     			//берем узел
     			//var_dump($group);
     			//обновляем данные
     			
     			$url = $base->str2url($group["name"]);
     
     			while(!$this->unique_url($url))
     			{
     				$url = $url."-";
     			}
     
     			$extrafields = array("name" => $group["name"], "url" =>$url);
     			$node = array(
     				"id" => NULL,
     				"left_key" => $group["left_key"] + $leftKey,
     				"right_key" => $group["right_key"] + $leftKey,
     				"level" => $group["level"] + $level
     			);
     			$node = $node + $extrafields;
     			list($insert_id, $tmp) = DB::insert("tree", array_keys($node))->values(array_values($node))->execute();
     
     			DB::query(NULL, "COMMIT")->execute();
     			
     			//Подключаем материалы
     
     			$action = "sidebar";
     
     			$left_menu = array(
     				"id" => NULL,
     				"node_id" => $insert_id,
     				"widget_id" => 1,
     				"param"     => "twig",
     				"action" => $action,
     				"options" => '{"' . $action . '_parent_id":"' . $parentId . '"}',
     				"position"  => "left_block",
     				"title"     => "Меню",
     				"ordering"  => 10,
     			);
     
     			list($insert_id, $tmp) = DB::insert("tree_widgets_rel", array_keys($left_menu))->values(array_values($left_menu))->execute();
     
     			$action = "index";
     			
     			$catalog = array(
     				"id" => NULL,
     				"node_id" => $insert_id,
     				"widget_id" => 1,
     				"param"     => "twig",
     				"action" => $action,
     				"options" => '{"' . $action . '_catalog_id":"' . $group['id'] . '"}',
     				"position"  => "right_block",
     				"title"     => "Каталог",
     				"ordering"  => 10,
     			);
     
     			list($insert_id, $tmp) = DB::insert("tree_widgets_rel", array_keys($catalog))->values(array_values($catalog))->execute();
     			
     		}*/
 }
Example #3
0
 public function action_deleteMaterial()
 {
     $group = new Model_Material('groups');
     $data['groups'] = $group->getTree();
     $url = $this->request->param('url');
     $gid = $this->request->param('id');
     if ($url == 'clear_cart') {
         $res = $group->clearCart();
     } else {
         $mid = $materialId = $group->getMaterialIdByUrl($this->request->param('url'), $gid);
         $res = $group->deleteMaterial($mid, $gid);
     }
     if ($res) {
         Controller::redirect('admin/materials/' . $gid);
     } else {
         $data['errors'] = $group->getErrors();
     }
     $wpm['status'] = Cookie::get('wpm', FALSE);
     $wpm['folder'] = Cookie::get('wpm_folder', '');
     $this->template->content = View::factory('admin/admMaterials', array('data' => $data, 'wpm' => $wpm, 'user' => $this->user));
 }