コード例 #1
0
ファイル: DraftController.php プロジェクト: Andyyang1981/pi
 /**
  * List articles for management
  */
 public function listAction()
 {
     // Denied user viewing if no front-end management permission assigned
     if (!$this->config('enable_front_edit') && 'front' == $this->section) {
         return $this->jumpTo404();
     }
     $status = $this->params('status', DraftModel::FIELD_STATUS_DRAFT);
     $from = $this->params('from', 'my');
     $where = $this->params('where', '');
     $where = json_decode(urldecode($where), true);
     $where = is_array($where) ? array_filter($where) : array();
     if (!in_array($from, array('my', 'all'))) {
         throw new \Exception(__('Invalid source'));
     }
     // Getting permission
     $rules = Rule::getPermission('my' == $from ? true : false);
     $categories = array_keys($rules);
     $where['category'] = empty($categories) ? 0 : $categories;
     $this->showDraftPage($status, $from, $where);
     $title = '';
     switch ($status) {
         case DraftModel::FIELD_STATUS_DRAFT:
             $title = __('Draft');
             $name = 'draft';
             break;
         case DraftModel::FIELD_STATUS_PENDING:
             $title = __('Pending');
             $name = 'pending';
             break;
         case DraftModel::FIELD_STATUS_REJECTED:
             $title = __('Rejected');
             $name = 'rejected';
             break;
     }
     $flags = array('draft' => DraftModel::FIELD_STATUS_DRAFT, 'pending' => DraftModel::FIELD_STATUS_PENDING, 'rejected' => DraftModel::FIELD_STATUS_REJECTED, 'published' => \Module\Article\Model\Article::FIELD_STATUS_PUBLISHED);
     $this->view()->assign(array('title' => $title, 'summary' => Entity::getSummary($from, $rules), 'flags' => $flags, 'rules' => $rules));
     $module = $this->getModule();
     if ('all' == $from) {
         $template = sprintf('%s-%s', 'article', $name);
         $this->view()->setTemplate($template, $module, 'front');
     } else {
         $this->view()->setTemplate('draft-list', $module, 'front');
     }
 }
コード例 #2
0
ファイル: ArticleController.php プロジェクト: Andyyang1981/pi
 /**
  * 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');
     }
 }