public function getAddLeafForm() { $tpl = $this->getTPL('tree/add_leaf'); $toReplace = array('{pid}', '{id}', '{title}', '{name}', '{option}'); $option = '<option value="">Выбрать</option>'; $typeModel = new Admin_Models_Type(); $option .= $typeModel->getAllTypesOption(); $replace = array(intval($_POST['pid']), 'select-type-leaf', 'Выберите тип элемента', '', $option); $result = str_replace($toReplace, $replace, $tpl); $this->putAjax($result); }
/** * @param int $id * @return String */ public function getBlock($id = null) { $id = $this->isAjax() ? intval($_POST['id']) : $id; $tree = $this->blockModel->getBlock($id); $entity = new Entity_Block(); $entity->init($tree); $toReplace = array('{action}', '{tree_title}', '{tree_name}', '{tree_pid}', '{id_value}', '{side_value}', '{text_value}', '{is_text_value}', '{choiceFile}', '{uniqID}'); $choice = new Admin_Controllers_ChoiceFile(false); $replace = array(empty($id) ? 'add' : 'update', $tree['title'], $tree['name'], empty($id) ? intval($_POST['pid']) : $tree['pid'], $tree['id'], $entity->getSide(), $entity->getText(), $entity->getIs_text(), $choice->genHTML(), uniqid()); $typeModel = new Admin_Models_Type(); $type = $typeModel->getTypeByName('block'); $fields = json_decode($type->getJson(), true); $cnt = count($fields); if (empty($id)) { for ($i = 0; $i < $cnt; $i++) { $cntJ = count($fields[$i]['variants']); for ($j = 0; $j < $cntJ; $j++) { $toReplace[] = '{' . $fields[$i]['name'] . '_' . $j . '_value}'; $replace[] = $fields[$i]['selects'] == $j ? $fields[$i]['type'] == 'select' ? 'selected="selected"' : 'checked="checked"' : ''; } } } else { for ($i = 0; $i < $cnt; $i++) { $cntJ = count($fields[$i]['variants']); $str = 'get' . ucfirst($fields[$i]['name']); $arr = explode(',', $entity->{$str}()); for ($j = 0; $j < $cntJ; $j++) { $toReplace[] = '{' . $fields[$i]['name'] . '_' . $j . '_value}'; if (in_array($fields[$i]['variants'][$j], $arr)) { $replace[] = $fields[$i]['type'] == 'select' ? 'selected="selected"' : 'checked="checked"'; } else { $replace[] = ''; } } } } $file = file_get_contents(ADMIN . '/views/types/block.tpl'); $result = str_replace($toReplace, $replace, $file); if ($this->isAjax()) { $this->putAjax($result); } return $result; }
/** * @param int $id * @return String */ public function getPage($id = null) { $id = $this->isAjax() ? intval($_POST['id']) : $id; $tree = $this->pageModel->getPage($id); $entity = new Entity_Page(); $entity->init($tree); $toReplace = array('{action}', '{tree_title}', '{tree_name}', '{tree_pid}', '{id_value}', '{seo_title_value}', '{seo_keywords_value}', '{seo_description_value}'); $replace = array(empty($id) ? 'add' : 'update', $tree['title'], $tree['name'], empty($id) ? intval($_POST['pid']) : $tree['pid'], $tree['id'], $entity->getSeoTitle(), $entity->getSeoKeywords(), $entity->getSeoDescription()); $typeModel = new Admin_Models_Type(); $type = $typeModel->getTypeByName('page'); $fields = json_decode($type->getJson(), true); $cnt = count($fields); if (empty($id)) { for ($i = 0; $i < $cnt; $i++) { $cntJ = count($fields[$i]['variants']); for ($j = 0; $j < $cntJ; $j++) { $toReplace[] = '{' . $fields[$i]['name'] . '_' . $j . '_value}'; $replace[] = $fields[$i]['selects'] == $j ? $fields[$i]['type'] == 'select' ? 'selected="selected"' : 'checked="checked"' : ''; } } } else { for ($i = 0; $i < $cnt; $i++) { $cntJ = count($fields[$i]['variants']); $str = 'get' . ucfirst($fields[$i]['name']) . '()'; $arr = explode(',', $entity->{$str}); for ($j = 0; $j < $cntJ; $j++) { $toReplace[] = '{' . $fields[$i]['name'] . '_' . $j . '_value}'; if (in_array($fields[$i]['variants'][$j], $arr)) { $replace[] = $fields[$i]['type'] == 'select' ? 'selected="selected"' : 'checked="checked"'; } else { $replace[] = ''; } } } } $file = file_get_contents(ADMIN . '/views/types/page.tpl'); $result = str_replace($toReplace, $replace, $file); if ($this->isAjax()) { $this->putAjax($result); } return $result; }
public function updateType($data = null) { $id = $this->isAjax() ? strip_tags($_POST['id']) : $data['id']; $name = $this->isAjax() ? strip_tags($_POST['name']) : $data['name']; $title = $this->isAjax() ? strip_tags($_POST['title']) : $data['title']; $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(); } $seo = $this->isAjax() ? intval($_POST['seo']) == 1 : intval($data['seo']) == 1; $json = array(); $cnt = $this->isAjax() ? count($_POST['cnt']) : count($data['cnt']); for ($i = 0; $i < $cnt; $i++) { $tmp = array(); $tmp['name'] = $this->isAjax() ? strip_tags($_POST['name-' . $i]) : $data['name-' . $i]; $tmp['title'] = $this->isAjax() ? strip_tags($_POST['title-' . $i]) : $data['title-' . $i]; $tmp['type'] = $this->isAjax() ? strip_tags($_POST['type-' . $i]) : $data['type-' . $i]; $tmp['variants'] = array(); $tmpCnt = $this->isAjax() ? count($_POST['variants-' . $i]) : count($data['variants-' . $i]); for ($j = 0; $j < $tmpCnt; $j++) { $tmp['variants'][] = $this->isAjax() ? strip_tags($_POST['variants-' . $i][$j]) : $data['variants-' . $i][$j]; } $tmp['selects'] = $this->isAjax() ? strip_tags($_POST['selects-' . $i]) : $data['selects-' . $i]; $tmp['int'] = $this->isAjax() ? intval($_POST['int-' . $i]) == 1 : intval($data['int-' . $i]) == 1; $json[] = $tmp; } $this->typeModel->updateType($id, $title, $name, $json, $seo); $result['error'] = false; $result['clear'] = false; $result['mess'] = 'Тип обновлен'; if ($this->isAjax()) { $this->putJSON($result); } return $result; }