/** * Searching articles by title. */ public function simpleAction() { $order = 'time_publish DESC'; $page = $this->params('p', 1); $module = $this->getModule(); $config = Pi::config('', $module); $limit = intval($config['page_limit_all']) ?: 40; $offset = $limit * ($page - 1); // Build where $where = array(); $keyword = $this->params('keyword', ''); if ($keyword) { $where['subject like ?'] = sprintf('%%%s%%', $keyword); } // Retrieve data $articleResultset = Entity::getAvailableArticlePage($where, $page, $limit, null, $order, $module); // Total count $where = array_merge($where, array('time_publish <= ?' => time(), 'status' => Article::FIELD_STATUS_PUBLISHED, 'active' => 1)); $modelArticle = $this->getModel('article'); $totalCount = $modelArticle->getSearchRowsCount($where); // Paginator $paginator = Paginator::factory($totalCount, array('limit' => $limit, 'page' => $page, 'url_options' => array('page_param' => 'p', 'params' => array('module' => $module, 'controller' => 'search', 'action' => 'simple', 'keyword' => $keyword)))); // Prepare search form $form = new SimpleSearchForm(); $form->setData($this->params()->fromQuery()); $this->view()->assign(array('title' => __('Search result of '), 'articles' => $articleResultset, 'keyword' => $keyword, 'p' => $page, 'paginator' => $paginator, 'count' => $totalCount, 'form' => $form)); }
/** * List all articles for pulling */ public function pullAction() { // Fetch topic details $topic = $this->params('topic', ''); if (empty($topic)) { return $this->jumpTo404(_a('Invalid topic ID!')); } if (is_numeric($topic)) { $rowTopic = $this->getModel('topic')->find($topic); } else { $rowTopic = $this->getModel('topic')->find($topic, 'slug'); } $where = array(); $page = $this->params('p', 1); $limit = $this->params('limit', 20); $data = $ids = array(); $module = $this->getModule(); $modelArticle = $this->getModel('article'); $categoryModel = $this->getModel('category'); $modelRelation = $this->getModel('article_topic'); // Get topic articles $rowRelation = $modelRelation->select(array('topic' => $rowTopic->id)); $topicArticles = array(); foreach ($rowRelation as $row) { $topicArticles[] = $row['article']; } // Get category $category = $this->params('category', 0); if ($category > 1) { $categoryIds = $categoryModel->getDescendantIds($category); if ($categoryIds) { $where['category'] = $categoryIds; } } // Get topic $model = $this->getModel('topic'); $topics = $model->getList(); // Build where $where['status'] = Article::FIELD_STATUS_PUBLISHED; $where['active'] = 1; $keyword = $this->params('keyword', ''); if (!empty($keyword)) { $where['subject like ?'] = sprintf('%%%s%%', $keyword); } // Retrieve data $data = Entity::getArticlePage($where, $page, $limit); // Getting article topic $articleIds = array_keys($data); if (empty($articleIds)) { $articleIds = array(0); } $rowRelation = $this->getModel('article_topic')->select(array('article' => $articleIds)); $relation = array(); foreach ($rowRelation as $row) { if (isset($relation[$row['article']])) { $relation[$row['article']] .= ',' . $topics[$row['topic']]; } else { $relation[$row['article']] = $topics[$row['topic']]; } } // Total count $select = $modelArticle->select()->columns(array('total' => new Expression('count(id)')))->where($where); $resulsetCount = $modelArticle->selectWith($select); $totalCount = (int) $resulsetCount->current()->total; // Paginator $paginator = Paginator::factory($totalCount, array('limit' => $limit, 'page' => $page, 'url_options' => array('page_param' => 'p', 'params' => array_filter(array('module' => $module, 'controller' => 'topic', 'action' => 'pull', 'topic' => $topic, 'category' => $category, 'keyword' => $keyword))))); // Prepare search form $form = new SimpleSearchForm(); $form->setData($this->params()->fromQuery()); $count = $this->getModel('article_topic')->count(array('topic' => $rowTopic->id)); $this->view()->assign(array('title' => _a('All Articles'), 'data' => $data, 'form' => $form, 'paginator' => $paginator, 'category' => $category, 'categories' => Pi::api('api', $module)->getCategoryList(), 'action' => 'pull', 'topics' => $topics, 'relation' => $relation, 'topic' => $rowTopic->toArray(), 'pulled' => $topicArticles, 'count' => $count)); }
/** * List all published article for management * * @return ViewModel */ public function publishedAction() { // Denied user viewing if no front-end management permission assigned if (!$this->config('enable_front_edit') && 'front' == $this->section) { return $this->jumpTo404(); } $page = $this->params('p', 1); $limit = $this->params('limit', 20); $from = $this->params('from', 'my'); $keyword = $this->params('keyword', ''); $category = $this->params('category', 0); $filter = $this->params('filter', ''); $order = 'time_publish DESC'; $where = array(); // Get permission $rules = Rule::getPermission(); if (empty($rules)) { return $this->jumpToDenied(); } $categories = array(); foreach (array_keys($rules) as $key) { $categories[$key] = true; } $where['category'] = array_keys($categories); // Select article of mine if ('my' == $from) { $where['uid'] = Pi::user()->getId() ?: 0; } $module = $this->getModule(); $modelArticle = $this->getModel('article'); $categoryModel = $this->getModel('category'); if (!empty($category) and !in_array($category, $where['category'])) { return $this->jumpToDenied(); } if ($category > 1) { $categoryIds = $categoryModel->getDescendantIds($category); if ($categoryIds) { $where['category'] = $categoryIds; } } // Build where $where['status'] = Article::FIELD_STATUS_PUBLISHED; if (!empty($keyword)) { $where['subject like ?'] = sprintf('%%%s%%', $keyword); } $where = array_filter($where); // The where must be added after array_filter function if ($filter == 'active') { $where['active'] = 1; } else { if ($filter == 'deactive') { $where['active'] = 0; } } // Retrieve data $data = Entity::getArticlePage($where, $page, $limit, null, $order); // Total count $totalCount = $modelArticle->count($where); // Paginator /* $paginator = Paginator::factory($totalCount); $paginator->setItemCountPerPage($limit) ->setCurrentPageNumber($page) ->setUrlOptions(array( 'page_param' => 'p', 'router' => $this->getEvent()->getRouter(), 'route' => $this->getEvent() ->getRouteMatch() ->getMatchedRouteName(), 'params' => array_filter(array( 'module' => $module, 'controller' => 'article', 'action' => 'published', 'category' => $category, 'filter' => $filter, 'keyword' => $keyword, )), )); */ $params = array(); foreach (array('category', 'filter', 'keyword', 'from') as $key) { if (${$key}) { $params[$key] = ${$key}; } } $paginator = Paginator::factory($totalCount, array('limit' => $limit, 'page' => $page, 'url_options' => array('page_param' => 'p', 'params' => $params))); // Prepare search form $form = new SimpleSearchForm(); $form->setData($this->params()->fromQuery()); $flags = array('draft' => DraftModel::FIELD_STATUS_DRAFT, 'pending' => DraftModel::FIELD_STATUS_PENDING, 'rejected' => DraftModel::FIELD_STATUS_REJECTED, 'published' => Article::FIELD_STATUS_PUBLISHED); $cacheCategories = Pi::api('api', $module)->getCategoryList(); $this->view()->assign(array('title' => __('Published'), 'data' => $data, 'form' => $form, 'paginator' => $paginator, 'summary' => Entity::getSummary($from, $rules), 'category' => $category, 'filter' => $filter, 'categories' => array_intersect_key($cacheCategories, $categories), 'action' => 'published', 'flags' => $flags, 'status' => Article::FIELD_STATUS_PUBLISHED, 'from' => $from, 'rules' => $rules)); if ('my' == $from) { $this->view()->setTemplate('draft-list', $module, 'front'); } else { $this->view()->setTemplate('article-published', $module, 'front'); } }