public function updateNews($data) { $this->getDI()->getEventsManager()->fire('livenews:beforeUpdate', $this); $categoryData = isset($data['categories']) ? $data['categories'] : array(); $textData = isset($data['text']) ? $data['text'] : array(); $hasMore = 0; if ($textData) { unset($data['text']); foreach ($textData as $textValue) { $textValue = trim($textValue); if ($textData && $textValue !== '<p></p>') { $hasMore = 1; break; } } $text = new Text(); $text->assign($textData); $this->text = $text; } //remove old relations if ($this->categoriesNews) { $this->categoriesNews->delete(); } $categories = array(); if ($categoryData) { unset($data['categories']); foreach ($categoryData as $categoryId) { $category = Category::findFirst($categoryId); if ($category) { $categories[] = $category; } } $this->categorySet = implode(',', $categoryData); $this->categories = $categories; } $data['hasMore'] = $hasMore; $this->assign($data); if (!$this->save()) { throw new Exception\RuntimeException('Update news failed'); } $this->getDI()->getEventsManager()->fire('livenews:afterUpdate', $this); return $this; }
/** * @operationName("Remove Livenews Category") * @operationDescription("Remove Livenews Category") */ public function deleteAction() { if (!$this->request->isDelete()) { $this->response->setStatusCode('405', 'Method Not Allowed'); $this->response->setContentType('application/json', 'utf-8'); return $this->response->setJsonContent(array('errors' => array(array('code' => 405, 'message' => 'ERR_POST_REQUEST_METHOD_NOT_ALLOW')))); } $id = $this->dispatcher->getParam('id'); $category = Models\Category::findFirst($id); try { $category->delete(); } catch (\Exception $e) { return $this->showExceptionAsJson($e, $category->getMessages()); } $this->response->setContentType('application/json', 'utf-8'); return $this->response->setJsonContent($category); }