public function fillTreeTemplate()
 {
     $emptyOnLoad = false;
     $nodes_to_request = $_SESSION['frm'][(int) $this->topic->getId()]['openTreeNodes'];
     if (!$_SESSION['frm'][(int) $this->topic->getId()]['openTreeNodes'] || count($_SESSION['frm'][(int) $this->topic->getId()]['openTreeNodes']) == 1 && $_SESSION['frm'][(int) $this->topic->getId()]['openTreeNodes'][0] == 0) {
         $emptyOnLoad = true;
         $nodes_to_request = array();
     }
     $objects = $this->topic->getNestedSetPostChildren(null, $nodes_to_request);
     $counter = 0;
     $onloadNodes = array();
     $nodesFetchedWithChildren = array();
     $frm = new ilForum();
     $pageHits = $frm->getPageHits();
     include_once 'Services/JSON/classes/class.ilJsonUtil.php';
     foreach ($objects as $object) {
         if ($object['pos_pk'] != $this->root_id && !in_array($object['parent_pos'], $onloadNodes)) {
             continue;
         }
         if (in_array((int) $object['parent_pos'], $onloadNodes) && !in_array((int) $object['parent_pos'], $nodesFetchedWithChildren)) {
             $nodesFetchedWithChildren[] = (int) $object['parent_pos'];
         }
         $html = self::getTreeNodeHtml($object, $this->gui, $pageHits);
         $hasChildren = $object['children'] >= 1;
         $node = new stdClass();
         $node->html = $html;
         if ($object['pos_pk'] == $this->root_id) {
             $this->tpl->setVariable('FRM_TREE_ROOT_NODE_VARIABLE', 'frmNode' . $object['pos_pk']);
             $this->tpl->setVariable('FRM_TREE_ROOT_NODE_LINK', ilJsonUtil::encode($node));
             $this->tpl->setVariable('FRM_TREE_ROOT_NODE_HAS_CHILDREN', $hasChildren ? 'true' : 'false');
         } else {
             $this->tpl->setCurrentBlock('frm_nodes');
             $this->tpl->setVariable('FRM_NODES_VARNAME', 'frmNode' . $object['pos_pk']);
             $this->tpl->setVariable('FRM_NODES_PARENT_VARNAME', 'frmNode' . $object['parent_pos']);
             $this->tpl->setVariable('FRM_NODES_LINK', ilJsonUtil::encode($node));
             $this->tpl->setVariable('FRM_NODES_HAS_CHILDREN', $hasChildren ? 'true' : 'false');
             $this->tpl->parseCurrentBlock();
         }
         $onloadNodes[] = (int) $object['pos_pk'];
         ++$counter;
     }
     $this->tpl->setVariable('THR_ONLOAD_NODES', ilJsonUtil::encode($onloadNodes));
     $this->tpl->setVariable('THR_ONLOAD_NODES_FETCHED_WITH_CHILDREN', ilJsonUtil::encode($nodesFetchedWithChildren));
     if ($emptyOnLoad) {
         $this->tpl->setVariable('THR_OPEN_NODES', ilJsonUtil::encode($onloadNodes));
         $_SESSION['frm'][(int) $this->topic->getId()]['openTreeNodes'] = array_unique(array_merge(array(0), $onloadNodes));
     } else {
         $this->tpl->setVariable('THR_OPEN_NODES', ilJsonUtil::encode($_SESSION['frm'][(int) $this->topic->getId()]['openTreeNodes']));
     }
 }
Example #2
0
 public function fetchTreeChildrenAsyncObject()
 {
     include_once 'Services/JSON/classes/class.ilJsonUtil.php';
     include_once 'Modules/Forum/classes/class.ilForumExplorer.php';
     $response = new stdClass();
     $response->success = false;
     if ($_GET['nodeId']) {
         $response->success = true;
         $response->children = array();
         $key = array_search((int) $_GET['nodeId'], (array) $_SESSION['frm'][(int) $_GET['thr_pk']]['openTreeNodes']);
         if (false === $key) {
             $_SESSION['frm'][(int) $_GET['thr_pk']]['openTreeNodes'][] = (int) $_GET['nodeId'];
         }
         $children = $this->objCurrentTopic->getNestedSetPostChildren((int) $_GET['nodeId'], (array) $_SESSION['frm'][(int) $_GET['thr_pk']]['openTreeNodes']);
         $frm = new ilForum();
         $pageHits = $frm->getPageHits();
         $fetchedNodes = array();
         foreach ($children as $child) {
             if ($child['parent_pos'] != (int) $_GET['nodeId'] && !in_array($child['parent_pos'], $fetchedNodes)) {
                 continue;
             }
             $fetchedNodes[] = $child['pos_pk'];
             $this->ctrl->setParameter($this, 'thr_pk', (int) $_GET['thr_pk']);
             $html = ilForumExplorer::getTreeNodeHtml($child, $this, $pageHits);
             $responseChild = new stdClass();
             $responseChild->nodeId = $child['pos_pk'];
             $responseChild->parentId = $child['parent_pos'];
             $responseChild->hasChildren = $child['children'] >= 1;
             $responseChild->fetchedWithChildren = in_array((int) $child['pos_pk'], (array) $_SESSION['frm'][(int) $_GET['thr_pk']]['openTreeNodes']);
             $responseChild->html = $html;
             $response->children[] = $responseChild;
         }
     }
     echo ilJsonUtil::encode($response);
     exit;
 }