Пример #1
0
 /**
  * Удаление данные
  *
  * @param array|Cond $cond
  *
  * @throws Exception\ErrorException
  * @throws \Model\Exception\ErrorException
  * @return Result
  */
 public function delete($cond = null)
 {
     if (!is_array($cond) && !$cond instanceof Cond && !is_null($cond)) {
         throw new Exception\ErrorException('Unknown Cond type');
     }
     if (is_array($cond)) {
         $cond = $this->getCond()->where($cond);
     }
     $result = new Result();
     try {
         $select = $this->prepareSelect($cond);
         $table = $cond->getCond('from', $this->getRawName());
         $stmt = $this->getDb()->delete($table, $select);
         $result->setResult($stmt->rowCount());
     } catch (\Exception $ex) {
         $result->addError($ex->getMessage(), $ex->getCode());
     }
     return $result;
 }
Пример #2
0
 protected function afterAdd(Result $result, array $data, Cond $cond = null)
 {
     if (!$result->isError() && $result->getResult()) {
         $parentId = isset($data['parent_id']) ? $data['parent_id'] : null;
         $parent = $this->getById($parentId);
         $updateData = array('tree_path' => trim($parent->getTreePath() . ',' . $result->getResult(), ','));
         $this->updateById($updateData, $result->getResult());
     }
     return $result;
 }