コード例 #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
ファイル: ActionIndex.php プロジェクト: aeshion/ZeroPHP
 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
ファイル: PortalAction.php プロジェクト: aeshion/ZeroPHP
 public function render($template_path = 'index/index.html.twig', array $context = array())
 {
     // 添加顶部导航
     $home_nav = CategoryModel::getRootNode();
     /** @var CategoryModel[] $nav_tree */
     $nav_tree = $home_nav->getSubTree();
     $list = array();
     foreach ($nav_tree as $i => $node) {
         if ($i == 0) {
             continue;
         }
         $list[$node->categoryId] = $node;
     }
     PortalBusiness::preOrderTree2RecursiveTree($list, $home_nav);
     $context['navigation'] = $home_nav;
     $template_path = '@TknyMedPortalModule/' . $template_path;
     return $this->renderTemplate($template_path, $context);
 }
コード例 #4
0
 protected function handle()
 {
     /** @var CategoryModel $root_node */
     $root_node = CategoryModel::getRootNode();
     if (!$root_node) {
         // 没有根分类,需要自动创建
         $node = new CategoryModel();
         $node->categoryName = '官网首页';
         $node->categoryDesc = '官网首页';
         $now = time();
         $node->createTimestamp = $now;
         $node->updateTimestamp = $now;
         $node->preOrderTreeLeft = 0;
         $node->preOrderTreeRight = 1;
         $root_node = CategoryModel::createPortalCategory($node);
     }
     /** @var CategoryModel[] $sub_tree */
     $sub_tree = $root_node->getSubTree();
     $list = array();
     foreach ($sub_tree as $i => $node) {
         if ($i == 0) {
             continue;
         }
         $list[$node->categoryId] = $node;
     }
     $request = $this->getRequest();
     if ($request->getMethod() == 'POST') {
         $session = $this->getSession();
         try {
             /*$root_category_name = $request->request->get('root_category_name');
               $root_category_name = trim($root_category_name);
               $root_category_desc = $request->request->get('root_category_desc');
               $root_category_desc = trim($root_category_desc);
               if (!$root_category_name) {
                   throw new \Exception("根菜单的名称不能为空");
               }
               $root_node->categoryName = $root_category_name;
               $root_node->categoryDesc = $root_category_desc;*/
             $root_category = $root_node->toArray();
             if (isset($root_category['depth'])) {
                 unset($root_category['depth']);
             }
             if (isset($root_category['width'])) {
                 unset($root_category['width']);
             }
             if (isset($root_category['children'])) {
                 unset($root_category['children']);
             }
             // 保存根菜单
             CategoryModel::editPortalCategory($root_category);
             $serialized_output = $request->request->get('serialized_output');
             $serialized_output = trim($serialized_output);
             $serialized_output = json_decode($serialized_output, true);
             $tree = $this->formatTree($serialized_output, $list);
             $root_node->children = $tree;
             $list = $this->recursiveTree2PreOrderTree($root_node);
             foreach ($list as $category) {
                 $category = $category->toArray();
                 if (isset($category['depth'])) {
                     unset($category['depth']);
                 }
                 if (isset($category['width'])) {
                     unset($category['width']);
                 }
                 if (isset($category['children'])) {
                     unset($category['children']);
                 }
                 // 保存根菜单
                 CategoryModel::editPortalCategory($category);
             }
             $session->addFlash('success', '操作成功');
         } catch (\Exception $e) {
             $session->addFlash('error', $e->getMessage());
         }
         return new RedirectResponse($this->generateUrl('admin_portal_category_manage'));
     }
     $this->preOrderTree2RecursiveTree($list, $root_node);
     return $this->render('category/manage-category.html.twig', array('root_node' => $root_node));
 }