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
 protected function initHeaderAction($a_sub_type = null, $a_sub_id = null)
 {
     /**
      * @var $ilUser ilObjUser
      */
     global $ilUser;
     $lg = parent::initHeaderAction();
     // Workaround: Do not show "desktop actions" in thread view
     if ($this->objCurrentTopic->getId()) {
         $container_obj = null;
         $lg->setContainerObject($container_obj);
     }
     if ($lg instanceof ilObjForumListGUI) {
         if ($ilUser->getId() != ANONYMOUS_USER_ID && $this->ilias->getSetting('forum_notification') != 0) {
             $is_user_allowed_to_deactivate_notification = $this->isUserAllowedToDeactivateNotification();
             $frm = $this->object->Forum;
             $frm->setForumId($this->object->getId());
             $frm->setForumRefId($this->object->getRefId());
             $frm->setMDB2Wherecondition('top_frm_fk = %s ', array('integer'), array($frm->getForumId()));
             $frm_notificiation_enabled = $frm->isForumNotificationEnabled($ilUser->getId());
             if ($this->objCurrentTopic->getId()) {
                 $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId());
             }
             if ($this->isParentObjectCrsOrGrp()) {
                 // special behaviour for CRS/GRP-Forum notification!!
                 if ($frm_notificiation_enabled && $is_user_allowed_to_deactivate_notification) {
                     $lg->addCustomCommand($this->ctrl->getLinkTarget($this, 'disableForumNotification'), "forums_disable_forum_notification");
                 } else {
                     $lg->addCustomCommand($this->ctrl->getLinkTarget($this, 'enableForumNotification'), "forums_enable_forum_notification");
                 }
             } else {
                 if ($frm_notificiation_enabled) {
                     $lg->addCustomCommand($this->ctrl->getLinkTarget($this, 'disableForumNotification'), "forums_disable_forum_notification");
                 } else {
                     $lg->addCustomCommand($this->ctrl->getLinkTarget($this, 'enableForumNotification'), "forums_enable_forum_notification");
                 }
             }
             $topic_notification_enabled = false;
             if ($this->objCurrentTopic->getId()) {
                 $topic_notification_enabled = $this->objCurrentTopic->isNotificationEnabled($ilUser->getId());
                 if ($topic_notification_enabled) {
                     $lg->addCustomCommand($this->ctrl->getLinkTarget($this, 'toggleThreadNotification'), "forums_disable_notification");
                 } else {
                     $lg->addCustomCommand($this->ctrl->getLinkTarget($this, 'toggleThreadNotification'), "forums_enable_notification");
                 }
             }
             $this->ctrl->setParameter($this, 'thr_pk', '');
             if ($frm_notificiation_enabled || $topic_notification_enabled) {
                 $lg->addHeaderIcon("not_icon", ilUtil::getImagePath("notification_on.svg"), $this->lng->txt("frm_notification_activated"));
             } else {
                 $lg->addHeaderIcon("not_icon", ilUtil::getImagePath("notification_off.svg"), $this->lng->txt("frm_notification_deactivated"));
             }
         }
     }
     return $lg;
 }
 protected function initHeaderAction($a_sub_type = null, $a_sub_id = null)
 {
     /**
      * @var $ilUser ilObjUser
      */
     global $ilUser;
     $lg = parent::initHeaderAction();
     // Workaround: Do not show "desktop actions" in thread view
     if ($this->objCurrentTopic->getId()) {
         $container_obj = null;
         $lg->setContainerObject($container_obj);
     }
     if ($lg instanceof ilObjForumListGUI) {
         include_once 'Modules/Forum/classes/class.ilForumNotification.php';
         $frm_noti = new ilForumNotification((int) $_GET['ref_id']);
         $frm_noti->setUserId($ilUser->getId());
         $user_toggle = $frm_noti->isUserToggleNotification();
         // Notification button
         $notificiation_enabled = false;
         if ($ilUser->getId() != ANONYMOUS_USER_ID && $this->ilias->getSetting('forum_notification') != 0 && $user_toggle != 1) {
             $frm = $this->object->Forum;
             $frm->setForumId($this->object->getId());
             $frm->setForumRefId($this->object->getRefId());
             $frm->setMDB2Wherecondition('top_frm_fk = %s ', array('integer'), array($frm->getForumId()));
             if ($this->objCurrentTopic->getId()) {
                 $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId());
             }
             if ($frm->isForumNotificationEnabled($ilUser->getId())) {
                 $lg->addCustomCommand($this->ctrl->getLinkTarget($this, 'disableForumNotification'), "forums_disable_forum_notification");
                 $notificiation_enabled = true;
             } else {
                 $lg->addCustomCommand($this->ctrl->getLinkTarget($this, 'enableForumNotification'), "forums_enable_forum_notification");
             }
             if ($this->objCurrentTopic->getId()) {
                 if ($this->objCurrentTopic->isNotificationEnabled($ilUser->getId())) {
                     $lg->addCustomCommand($this->ctrl->getLinkTarget($this, 'toggleThreadNotification'), "forums_disable_notification");
                     $notificiation_enabled = true;
                 } else {
                     $lg->addCustomCommand($this->ctrl->getLinkTarget($this, 'toggleThreadNotification'), "forums_enable_notification");
                 }
             }
             $this->ctrl->setParameter($this, 'thr_pk', '');
             if ($notificiation_enabled) {
                 $lg->addHeaderIcon("not_icon", ilUtil::getImagePath("notification_on.png"), $this->lng->txt("frm_notification_activated"));
             } else {
                 $lg->addHeaderIcon("not_icon", ilUtil::getImagePath("notification_off.png"), $this->lng->txt("frm_notification_deactivated"));
             }
         }
     }
     return $lg;
 }
 /**
  * @param ilForumTopic $thread
  */
 public function fillRow(ilForumTopic $thread)
 {
     /**
      * @var $ilUser ilObjUser
      */
     global $ilUser;
     $this->ctrl->setParameter($this->getParentObject(), 'thr_pk', $thread->getId());
     if ('mergeThreads' == $this->parent_cmd) {
         $checked = $this->max_count == 1 || isset($_POST['thread_ids']) && in_array($thread->getId(), $_POST['thread_ids']);
         $this->tpl->setVariable('VAL_CHECK', ilUtil::formRadioButton($checked, 'thread_ids[]', $thread->getId()));
     } else {
         if ('showThreads' == $this->parent_cmd) {
             $this->tpl->setVariable('VAL_CHECK', ilUtil::formCheckbox(isset($_POST['thread_ids']) && in_array($thread->getId(), $_POST['thread_ids']) ? true : false, 'thread_ids[]', $thread->getId()));
         } else {
             if ($thread->isSticky()) {
                 $this->tpl->setVariable('VAL_SORTING_NAME', 'thread_sorting[' . $thread->getId() . ']');
                 $this->tpl->setVariable('VAL_SORTING', (int) $this->position * 10);
             } else {
                 $this->tpl->setVariable('VAL_CHECK', '');
             }
             $this->position++;
         }
     }
     $subject = '';
     if ($thread->isSticky()) {
         $subject .= '<span class="light">[' . $this->lng->txt('sticky') . ']</span> ';
     }
     if ($thread->isClosed()) {
         $subject .= '<span class="light">[' . $this->lng->txt('topic_close') . ']</span> ';
     }
     if (!$ilUser->isAnonymous() && $this->ilias->getSetting('forum_notification') != 0 && $thread->getUserNotificationEnabled()) {
         $subject .= '<span class="light">[' . $this->lng->txt('forums_notification_enabled') . ']</span> ';
     }
     $num_posts = $thread->getNumPosts();
     $num_unread = $thread->getNumUnreadPosts();
     $num_new = $thread->getNumNewPosts();
     if ($num_posts > 0) {
         $subject = '<div><a href="' . $this->ctrl->getLinkTarget($this->getParentObject(), 'viewThread') . '">' . $thread->getSubject() . '</a></div>' . $subject;
     } else {
         $subject = $thread->getSubject() . $subject;
     }
     $this->tpl->setVariable('VAL_SUBJECT', $subject);
     // Author
     $this->ctrl->setParameter($this->getParentObject(), 'backurl', urlencode($this->ctrl->getLinkTargetByClass("ilrepositorygui", "")));
     $this->ctrl->setParameter($this->getParentObject(), 'user', $thread->getUserId());
     $authorinfo = new ilForumAuthorInformation($thread->getUserId(), $thread->getUserAlias(), $thread->getImportName(), array('class' => 'il_ItemProperty', 'href' => $this->ctrl->getLinkTarget($this->getParentObject(), 'showUser')));
     $this->tpl->setVariable('VAL_AUTHOR', $authorinfo->getLinkedAuthorName());
     $topicStats = $num_posts;
     if (!$ilUser->isAnonymous()) {
         if ($num_unread > 0) {
             $topicStats .= '<br /><span class="alert ilWhiteSpaceNowrap">' . $this->lng->txt('unread') . ': ' . $num_unread . '</span>';
         }
         if ($num_new > 0 && $this->getOverviewSetting() == 0) {
             $topicStats .= '<br /><span class="alert ilWhiteSpaceNowrap">' . $this->lng->txt('new') . ': ' . $num_new . '</span>';
         }
     }
     $this->tpl->setVariable('VAL_ARTICLE_STATS', $topicStats);
     $this->tpl->setVariable('VAL_NUM_VISIT', $thread->getVisits());
     // Last posting
     if ($num_posts > 0) {
         if ($this->getIsModerator()) {
             $objLastPost = $thread->getLastPost();
         } else {
             $objLastPost = $thread->getLastActivePost();
         }
         if (is_object($objLastPost)) {
             $authorinfo = new ilForumAuthorInformation($objLastPost->getUserId(), $objLastPost->getUserAlias(), $objLastPost->getImportName(), array('href' => $this->ctrl->getLinkTarget($this->getParentObject(), 'viewThread') . '#' . $objLastPost->getId()));
             $this->tpl->setVariable('VAL_LP_DATE', '<div class="ilWhiteSpaceNowrap">' . ilDatePresentation::formatDate(new ilDateTime($objLastPost->getCreateDate(), IL_CAL_DATETIME)) . '</div>' . '<div class="ilWhiteSpaceNowrap">' . $this->lng->txt('from') . ' ' . $authorinfo->getLinkedAuthorName() . '</div>');
         }
     }
     // Row style
     $css_row = $this->css_row;
     if ($thread->isSticky()) {
         $css_row = $css_row == 'tblrow1' ? 'tblstickyrow1' : 'tblstickyrow2';
     }
     $this->tpl->setVariable('CSS_ROW', $css_row);
     $this->ctrl->setParameter($this->getParentObject(), 'thr_pk', '');
     $this->ctrl->setParameter($this->getParentObject(), 'user', '');
     $this->ctrl->setParameter($this->getParentObject(), 'backurl', '');
 }
    /**
     * generate new dataset in frm_threads
     * @param	integer	$topic
     * @param	integer	$user
     * @param	string	$subject
     * @param	string	$message
     * @param	integer	$notify
     * @param	integer	$notify_posts
     * @param	integer	$anonymize
     * @param	datetime	$date
     * @return	integer	new post ID
     * @access public
     */
    public function generateThread($forum_id, $user, $subject, $message, $notify, $notify_posts, $alias = '', $date = '')
    {
        global $ilDB;
        $objNewThread = new ilForumTopic();
        $objNewThread->setForumId($forum_id);
        $objNewThread->setUserId($user);
        $objNewThread->setSubject($subject);
        if ($date == "") {
            $objNewThread->setCreateDate(date("Y-m-d H:i:s"));
        } else {
            if (strpos($date, "-") > 0) {
                $objNewThread->setCreateDate($date);
            } else {
                $objNewThread->setCreateDate(date("Y-m-d H:i:s", $date));
            }
        }
        $objNewThread->setImportName($this->getImportName());
        $objNewThread->setUserAlias($alias);
        $objNewThread->insert();
        if ($notify_posts == 1) {
            $objNewThread->enableNotification($user);
        }
        // update forum
        $statement = $ilDB->manipulateF('
			UPDATE frm_data 
			SET top_num_threads = top_num_threads + 1
			WHERE top_pk = %s', array('integer'), array($forum_id));
        return $this->generatePost($forum_id, $objNewThread->getId(), $user, $message, 0, $notify, $subject, $alias, $objNewThread->getCreateDate());
    }