public function genAddField() { $res = new Entity_Tree(); $res->init($this->treeDAO->getOne(Config::$lang)); $res->setTitle('Новый элемент'); return $this->genOnePoint($res, 'fa-plus', 'add-tree-leaf', '', false); }
/** * @param String $title * @param String $name * @param int $pid * @param Entity_Block $block * @return int id */ public function addBlock($title, $name, $pid, $block) { $parent = $this->treeDAO->getOne($pid); $treeLeaf = new Entity_Tree(); $treeLeaf->setTitle($title); $treeLeaf->setLink($parent['link'] . '/' . $name); $treeLeaf->setName($name); $treeLeaf->setType('block'); $treeLeaf->setRightKey($parent['right_key']); $treeLeaf->setLevel($parent['level']); $treeLeaf->setPid($pid); return $this->blockDAO->add($treeLeaf, $block); }
/** * @param array $data * @return bool */ public function updatePage($data = array()) { $tree = new Entity_Tree(); $tree->setId($this->isAjax() ? strip_tags($_POST['id']) : $data['id']); $tree->setTitle($this->isAjax() ? strip_tags($_POST['title']) : $data['tree_title']); $tree->setName($this->isAjax() ? strip_tags($_POST['name']) : $data['tree_name']); $id = $tree->getId(); $title = $tree->getTitle(); $name = $tree->getName(); $validator = new Libs_Validator(array('title' => 'Титулка', 'name' => 'Имя', 'pid' => 'Ид родителя')); $data = array('title' => $title, 'name' => $name, 'id' => $id); $valid = array('title' => array('required' => true), 'name' => array('required' => true), 'id' => array('required' => true)); if (!$validator->isValid($data, $valid)) { if ($this->isAjax()) { $json = array('error' => true, 'mess' => $validator->getErrors()); $this->putJSON($json); } return $validator->getErrors(); } $entity = new Entity_Page(); $entity->setSeoTitle($this->isAjax() ? strip_tags($_POST['seo_title']) : $data['seo_title']); $entity->setSeoKeywords($this->isAjax() ? strip_tags($_POST['seo_keywords']) : $data['seo_keywords']); $entity->setSeoDescription($this->isAjax() ? strip_tags($_POST['seo_description']) : $data['seo_description']); $id = $this->pageModel->updatePage($tree, $entity); if ($this->isAjax()) { $json = array(); if ($id) { $json['error'] = false; $json['mess'] = 'Обновлено'; $json['clear'] = false; $json['callback'] = 'function callback(){reloadMenu();}'; } else { $json['error'] = true; $json['mess'] = 'Ошибка'; } $this->putJSON($json); } return $id; }
/** * @param array $data * @return bool */ public function updateBlock($data = array()) { $tree = new Entity_Tree(); $tree->setId($this->isAjax() ? strip_tags($_POST['id']) : $data['id']); $tree->setTitle($this->isAjax() ? strip_tags($_POST['title']) : $data['tree_title']); $tree->setName($this->isAjax() ? strip_tags($_POST['name']) : $data['tree_name']); $id = $tree->getId(); $title = $tree->getTitle(); $name = $tree->getName(); $validator = new Libs_Validator(array('title' => 'Титулка', 'name' => 'Имя', 'pid' => 'Ид родителя')); $data = array('title' => $title, 'name' => $name, 'id' => $id); $valid = array('title' => array('required' => true), 'name' => array('required' => true), 'id' => array('required' => true)); if (!$validator->isValid($data, $valid)) { if ($this->isAjax()) { $json = array('error' => true, 'mess' => $validator->getErrors()); $this->putJSON($json); } return $validator->getErrors(); } $entity = new Entity_Block(); $entity->setSide($this->isAjax() ? strip_tags($_POST['block_side']) : $data['block_side']); $entity->setText($this->isAjax() ? strip_tags($_POST['block_text']) : $data['block_text']); $entity->setIsText($this->isAjax() ? strip_tags($_POST['block_is_text']) : $data['block_is_text']); $result = $this->blockModel->updateBlock($tree, $entity); if ($this->isAjax()) { $json = array(); if ($result) { $json['error'] = false; $json['mess'] = 'Обновлено'; $json['clear'] = false; $json['callback'] = 'function callback(){reloadMenu();}'; } else { $json['error'] = true; $json['mess'] = 'Ошибка'; } $this->putJSON($json); } return $result; }