/** * @param Entity_Tree $tree * @param Entity_Item $item * @return bool */ public function updateItem($tree, $item) { $old = new Entity_Tree(); $old->init($this->treeDAO->getOne($tree->getId())); $link = rtrim($old->getLink(), $old->getName()) . $tree->getName(); $tree->setLink($link); $item->setId($old->getTypeId()); return $this->itemDAO->update($item) && $this->treeDAO->updateTree($tree); }
/** * @param Entity_Item $item * @return bool */ public function update($item) { $id = $item->getId(); $f = $item->getF(); $stmt = $this->DB->prepare('UPDATE `site_item` SET `item_f`=:f WHERE `item_id`=:id'); $stmt->bindParam(':id', $id); $stmt->bindParam(':f', $f); return $stmt->execute(); }
/** * @param array $data * @return bool */ public function updateItem($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_Item(); $entity->setF($this->isAjax() ? strip_tags($_POST['item_f']) : $data['item_f']); $result = $this->itemModel->updateItem($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; }