Example #1
0
 /**
  * Manage children.
  *
  * @param  string    $type 
  * @param  int       $category    the current category id.
  * @access public
  * @return void
  */
 public function children($type, $category = 0)
 {
     /* If type is forum, assign board to category. */
     if ($type == 'forum') {
         $this->lang->category = $this->lang->board;
         $this->view->boardChildrenCount = $this->dao->select('count(*) as count')->from(TABLE_CATEGORY)->where('grade')->eq(2)->andWhere('type')->eq('forum')->fetch('count');
     }
     $isWechatMenu = treeModel::isWechatMenu($type);
     if ($isWechatMenu) {
         $this->lang->category = $this->lang->wechatMenu;
     }
     if (!empty($_POST)) {
         $result = $this->tree->manageChildren($type, $this->post->parent, $this->post->children);
         $locate = $this->inLink('browse', "type={$type}&root={$this->post->parent}");
         if ($result === true) {
             $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $locate));
         }
         $this->send(array('result' => 'fail', 'message' => dao::isError() ? dao::getError() : $result));
     }
     $this->view->isWechatMenu = $isWechatMenu;
     $this->view->title = $this->lang->tree->manage;
     $this->view->type = $type;
     $this->view->children = $this->tree->getChildren($category, $type);
     $this->view->origins = $this->tree->getOrigin($category);
     $this->view->parent = $category;
     $this->display();
 }
Example #2
0
 /**
  * Get the tree menu in <ul><ol> type.
  * 
  * @param string    $type           the tree type
  * @param int       $startCategoryID  the start category
  * @param string    $userFunc       which function to be called to create the link
  * @access public
  * @return string   the html code of the tree menu.
  */
 public function getTreeMenu($type = 'article', $startCategoryID = 0, $userFunc, $siteID = 0)
 {
     $treeMenu = array();
     $stmt = $this->dbh->query($this->buildQuery($type, $startCategoryID, $siteID));
     while ($category = $stmt->fetch()) {
         if (treeModel::isWechatMenu($type)) {
             $category->children = $this->dao->select('id')->from(TABLE_CATEGORY)->where('parent')->eq($category->id)->fetchAll();
         }
         $linkHtml = call_user_func($userFunc, $category);
         if (isset($treeMenu[$category->id]) and !empty($treeMenu[$category->id])) {
             if (!isset($treeMenu[$category->parent])) {
                 $treeMenu[$category->parent] = '';
             }
             $treeMenu[$category->parent] .= "<li>{$linkHtml}";
             $treeMenu[$category->parent] .= "<ul>" . $treeMenu[$category->id] . "</ul>\n";
         } else {
             if (isset($treeMenu[$category->parent]) and !empty($treeMenu[$category->parent])) {
                 $treeMenu[$category->parent] .= "<li>{$linkHtml}\n";
             } else {
                 $treeMenu[$category->parent] = "<li>{$linkHtml}\n";
             }
         }
         $treeMenu[$category->parent] .= "</li>\n";
     }
     $lastMenu = "<ul class='tree'>" . @array_pop($treeMenu) . "</ul>\n";
     return $lastMenu;
 }