/** * @param Entity_Block $block * @return bool */ public function update($block) { $id = $block->getId(); $side = $block->getSide(); $text = $block->getText(); $is_text = $block->getIs_text(); $stmt = $this->DB->prepare('UPDATE `site_block` SET `block_side`=:side, `block_text`=:text, `block_is_text`=:is_text WHERE `block_id`=:id'); $stmt->bindParam(':id', $id); $stmt->bindParam(':side', $side); $stmt->bindParam(':text', $text); $stmt->bindParam(':is_text', $is_text); return $stmt->execute(); }
/** * @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; }