예제 #1
0
 protected function handle()
 {
     /** @var CategoryModel[] $tree */
     $tree = CategoryModel::getTree();
     /** @var CategoryModel $root_node */
     $root_node = CategoryModel::getRootNode();
     $categories = array();
     foreach ($tree as $category) {
         $categories[$category->categoryId] = $category;
     }
     $request = $this->getRequest();
     $category_id = $request->query->get('category_id');
     if (!$category_id || $category_id == $root_node->categoryId) {
         $category_id = null;
     }
     $page = $request->query->get('page');
     if (!$page) {
         $page = 1;
     }
     $size = 10;
     $pager = ArticleModel::listPortalArticles($page, $size, function (QueryBuilder $qb) use($category_id) {
         if ($category_id) {
             $qb->andWhere($qb->expr()->eq('category_id', ':category_id'))->setParameter(':category_id', $category_id);
         }
         $qb->addOrderBy('create_timestamp', 'DESC');
     });
     $pager->setQuery(array('category_id' => $category_id));
     return $this->render('article/manage-article.html.twig', array('tree' => $tree, 'pager' => $pager, 'categories' => $categories));
 }
예제 #2
0
 public function __invoke()
 {
     $homepage_node = CategoryModel::getRootNode();
     $category_id = $homepage_node->categoryId;
     $articles_pager = ArticleModel::listPortalArticles(1, 3, function (QueryBuilder $qb) use($category_id) {
         $qb->andWhere($qb->expr()->eq('category_id', ':category_id'))->setParameter(':category_id', $category_id);
         $qb->andWhere($qb->expr()->gt('publish_timestamp', 0));
         $qb->addOrderBy('publish_timestamp', 'desc');
     });
     return $this->render('homepage/index.html.twig', array('pager' => $articles_pager));
 }
예제 #3
0
 public function __invoke($category_id = null)
 {
     $session = $this->getSession();
     $category = CategoryModel::getPortalCategory($category_id);
     if (!$category) {
         $session->addFlash('error', '分类不存在');
         return new RedirectResponse($this->generateUrl('portal_homepage'));
     }
     //        $parent_category = $category->getDirectParentNode();
     //        if ($parent_category->isRootNode()) {
     //            $parent_category = null;
     //        }
     switch ($category->categoryType) {
         case 'article':
         case 'article-menu':
             // 文章列表
             // 面包屑导航
             $breadcrumb = $category->getNodeSinglePath();
             unset($breadcrumb[0]);
             $breadcrumb = array_values($breadcrumb);
             // 边栏导航
             /** @var CategoryModel $top_nav */
             $top_nav = $breadcrumb[0];
             $side_nav = $top_nav->getDirectChildNodes();
             // 文章内容
             $article_id = $category->categoryDesc;
             $article_id = intval($article_id);
             $article = ArticleModel::getPortalArticle($article_id);
             if (!$article) {
                 $session->addFlash('error', '文章不存在');
                 return new RedirectResponse($this->generateUrl('portal_homepage'));
             }
             return $this->render('category/article.html.twig', array('breadcrumb' => $breadcrumb, 'side_nav' => $side_nav, 'category' => $category, 'parent_category' => $top_nav, 'article' => $article));
             break;
         case 'menu':
             // 面包屑导航
             $breadcrumb = $category->getNodeSinglePath();
             unset($breadcrumb[0]);
             $breadcrumb = array_values($breadcrumb);
             // 边栏导航
             /** @var CategoryModel $top_nav */
             $top_nav = $breadcrumb[0];
             $side_nav = $top_nav->getDirectChildNodes();
             $category = $side_nav[0];
             // 内容列表
             $request = $this->getRequest();
             $page = $request->query->get('page');
             if (!$page) {
                 $page = 1;
             }
             $size = 20;
             $pager = ArticleModel::listPortalArticles($page, $size, function (QueryBuilder $qb) use($category) {
                 /** @var CategoryModel $category */
                 $qb->andWhere($qb->expr()->eq('category_id', ':category_id'))->setParameter(':category_id', $category->categoryId);
                 $qb->andWhere($qb->expr()->gt('publish_timestamp', 0));
             });
             return $this->render('category/index.html.twig', array('breadcrumb' => $breadcrumb, 'side_nav' => $side_nav, 'pager' => $pager, 'category' => $category, 'parent_category' => $top_nav));
             break;
         case 'page':
             $breadcrumb = $category->getNodeSinglePath();
             unset($breadcrumb[0]);
             $breadcrumb = array_values($breadcrumb);
             // 边栏导航
             /** @var CategoryModel $top_nav */
             $top_nav = $breadcrumb[0];
             $side_nav = $top_nav->getDirectChildNodes();
             $category = $side_nav[0];
             return $this->render($category->categoryDesc, array('breadcrumb' => $breadcrumb, 'side_nav' => $side_nav, 'category' => $category, 'parent_category' => $top_nav));
             break;
         case 'link':
             return new RedirectResponse($category->categoryDesc);
             break;
         default:
             $session->addFlash('error', '错误的分类类型');
             return new RedirectResponse($this->generateUrl('portal_homepage'));
             break;
     }
 }