Example #1
0
 public function initialize($entity = null, $options = null)
 {
     $select = new Select('parentId');
     $category = new Models\Category();
     $categories = $category->find(array("order" => "id DESC", "limit" => 100));
     $categoryArray = array('None');
     foreach ($categories as $key => $item) {
         $categoryArray[$item->id] = $item->categoryName;
     }
     $select->setOptions($categoryArray);
     $this->add($select);
 }
Example #2
0
 public function addCid()
 {
     if ($this->cid) {
         return $this->cid;
     }
     $category = new Models\Category();
     $categories = $category->find(array("order" => "id DESC", "limit" => 100));
     if ($categories) {
         $options = array('All Categories');
         foreach ($categories as $categoryitem) {
             $options[$categoryitem->id] = $categoryitem->categoryName;
         }
         $element = new Select('cid', $options);
     }
     $this->add($element);
     return $this->cid = $element;
 }
Example #3
0
 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;
 }
Example #4
0
 public function getCategories()
 {
     if ($this->categories) {
         return $this->categories;
     }
     $category = new Models\Category();
     $categories = $category->find(array("order" => "id DESC", "limit" => 100));
     $post = $this->getModel();
     $values = array();
     if ($post && $post->categories) {
         foreach ($post->categories as $categoryitem) {
             $values[] = $categoryitem->id;
         }
     }
     foreach ($categories as $key => $item) {
         $check = new Check('categories[]', array('value' => $item->id));
         if (in_array($item->id, $values)) {
             $check->setDefault($item->id);
         }
         $check->setLabel($item->categoryName);
         $this->categories[] = $check;
     }
     return $this->categories;
 }
Example #5
0
 /**
  * @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);
 }