コード例 #1
0
ファイル: CategoryForm.php プロジェクト: skybird/phalcon
 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);
 }
コード例 #2
0
ファイル: NewsController.php プロジェクト: skybird/phalcon
 public function indexAction()
 {
     $limit = $this->request->getQuery('limit', 'int', 25);
     $limit = $limit > 100 ?: $limit;
     $limit = $limit < 10 ?: $limit;
     $order = $this->request->getQuery('order', 'string', '-created_at');
     $query = array('q' => $this->request->getQuery('q', 'string'), 'status' => 'published', 'tid' => $this->request->getQuery('tid', 'int'), 'uid' => $this->request->getQuery('uid', 'int'), 'cid' => $this->request->getQuery('cid', 'int'), 'username' => $this->request->getQuery('username', 'string'), 'order' => $order, 'limit' => $limit, 'page' => $this->request->getQuery('page', 'int', 1));
     if ($query['cid']) {
         $this->view->setVar('category', Category::findFirst($query['cid']));
     }
     if ($query['uid']) {
         $this->view->setVar('author', UserManager::findFirst($query['uid']));
     }
     if ($query['tid']) {
         $this->view->setVar('tag', Tag::findFirst($query['tid']));
     }
     $post = new Post();
     $posts = $post->findPosts($query);
     $paginator = new \Eva\EvaEngine\Paginator(array("builder" => $posts, "limit" => $limit, "page" => $query['page']));
     $paginator->setQuery($query);
     $pager = $paginator->getPaginate();
     $this->view->setVar('pager', $pager);
     $this->view->setVar('query', $query);
     $tag = new Tag();
     $tags = $tag->getPopularTags(6);
     $this->view->setVar('tags', $tags);
 }
コード例 #3
0
ファイル: FilterForm.php プロジェクト: skybird/phalcon
 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;
 }
コード例 #4
0
ファイル: NewsController.php プロジェクト: skybird/phalcon
 public function listAction()
 {
     $limit = $this->request->getQuery('limit', 'int', 25);
     $limit = $limit > 100 ? 100 : $limit;
     $limit = $limit < 10 ? 10 : $limit;
     $order = $this->request->getQuery('order', 'string', '-created_at');
     $query = array('q' => $this->request->getQuery('q', 'string'), 'status' => $this->request->getQuery('status', 'string', 'published'), 'uid' => $this->request->getQuery('uid', 'int'), 'cid' => $this->request->getQuery('cid', 'int'), 'username' => $this->request->getQuery('username', 'string'), 'order' => $order, 'limit' => $limit, 'page' => $this->request->getQuery('page', 'int', 1));
     if ($query['cid']) {
         $this->view->setVar('category', Category::findFirst($query['cid']));
     }
     $post = new Post();
     $posts = $post->findPosts($query);
     $paginator = new \Eva\EvaEngine\Paginator(array("builder" => $posts, "limit" => $limit, "page" => $query['page']));
     $paginator->setQuery($query);
     $pager = $paginator->getPaginate();
     $this->view->setVar('pager', $pager);
     return $paginator;
 }
コード例 #5
0
 /**
  * @operationName("Remove Post Category")
  * @operationDescription("Remove Post 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);
 }
コード例 #6
0
ファイル: Post.php プロジェクト: skybird/phalcon
 public function updatePost($data)
 {
     $textData = isset($data['text']) ? $data['text'] : array();
     $tagData = isset($data['tags']) ? $data['tags'] : array();
     $categoryData = isset($data['categories']) ? $data['categories'] : array();
     $connectionData = isset($data['connectids']) ? $data['connectids'] : array();
     if ($textData) {
         unset($data['text']);
         $text = new Text();
         $text->assign($textData);
         $this->text = $text;
     }
     $tags = array();
     //remove old relations
     if ($this->tagsPosts) {
         $this->tagsPosts->delete();
     }
     if ($tagData) {
         unset($data['tags']);
         $tagArray = is_array($tagData) ? $tagData : explode(',', $tagData);
         foreach ($tagArray as $tagName) {
             $tag = Entities\Tags::findFirst(array("conditions" => "tagName = :tagName:", "bind" => array('tagName' => $tagName)));
             if (!$tag) {
                 $tag = new Entities\Tags();
                 $tag->tagName = $tagName;
             }
             $tags[] = $tag;
         }
         if ($tags) {
             $this->tags = $tags;
         }
     }
     //remove old relations
     $categories = array();
     if ($this->categoriesPosts) {
         $this->categoriesPosts->delete();
     }
     if ($categoryData) {
         unset($data['categories']);
         foreach ($categoryData as $categoryId) {
             $category = Category::findFirst($categoryId);
             if ($category) {
                 $categories[] = $category;
             }
         }
         $this->categories = $categories;
     }
     $connections = array();
     //remove old relations
     if ($this->postConnects) {
         $this->postConnects->delete();
     }
     if ($connectionData) {
         unset($data['connectids']);
         foreach ($connectionData as $connectionId) {
             $connection = new Entities\Connections();
             $connection->sourceId = $this->id;
             $connection->targetId = $connectionId;
             $connection->createdAt = time();
             $connections[] = $connection;
         }
         $this->postConnects = $connections;
     }
     $this->assign($data);
     if (!$this->save()) {
         throw new Exception\RuntimeException('Update post failed');
     }
     return $this;
 }
コード例 #7
0
ファイル: PostForm.php プロジェクト: skybird/phalcon
 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;
 }