/**
  * Get array for this one question,
  * set $this->Question
  * and also set $this->aTplVars['body']
  * with parsed tplQuestion block
  *
  *
  * @throws Lampcms404Exception if question not found
  *
  * @return object $this
  */
 protected function getQuestion()
 {
     $isModerator = $this->Registry->Viewer->isModerator();
     $this->noComments = false === (bool) $this->Registry->Ini->MAX_COMMENTS;
     d('no comments: ' . $this->noComments);
     $aFields = $this->noComments || false === (bool) $this->Registry->Ini->SHOW_COMMENTS ? array('comments' => 0) : array();
     $this->aQuestion = $this->Registry->Mongo->QUESTIONS->findOne(array('_id' => (int) $this->Request['qid']), $aFields);
     /**
      * @todo Translate string
      */
     if (empty($this->aQuestion)) {
         throw new \Lampcms\Lampcms404Exception('Topic not found');
     }
     d('$this->aQuestion: ' . print_r($this->aQuestion, 1));
     /**
      * Only moderators can see ip address
      */
     if (!$isModerator && !empty($this->aQuestion['ip'])) {
         unset($this->aQuestion['ip']);
     }
     $deleted = !empty($this->aQuestion['i_del_ts']) ? ' deleted' : false;
     /**
      * Guests will have to see filtered
      * content
      */
     if (!$this->isLoggedIn()) {
         $this->aQuestion['b'] = Badwords::filter($this->aQuestion['b'], true);
     }
     $this->Question = new Question($this->Registry, $this->aQuestion);
     /**
      * @todo Translate string
      */
     if ($deleted) {
         if (!$isModerator && !\Lampcms\isOwner($this->Registry->Viewer, $this->Question)) {
             throw new \Lampcms\Lampcms404Exception('Topic was deleted on ' . date('F j Y', $this->aQuestion['i_del_ts']));
         }
         /**
          * If Viewer is moderator, then viewer
          * will be able to view deleted item
          * This will add 'deleted' class to question table
          */
         $this->aQuestion['deleted'] = $deleted;
         if (!empty($this->aQuestion['a_deleted'])) {
             $this->aQuestion['deletedby'] = \tplDeletedby::parse($this->aQuestion['a_deleted'], false);
             d('deletedby: ' . $this->aQuestion['deletedby']);
         }
     }
     if ($this->noComments) {
         $this->aQuestion['nocomments'] = ' nocomments';
     }
     $this->aQuestion['add_comment'] = $this->_('add comment');
     $this->aQuestion['reply'] = $this->_('Reply');
     $this->aQuestion['reply_t'] = $this->_('Reply to this comment');
     $this->aQuestion['edited'] = $this->_('Edited');
     $breadcrumb = empty($this->aQuestion['i_cat']) ? '' : $this->getBreadcrumb($this->aQuestion['i_cat']);
     $this->aPageVars['body'] = $breadcrumb . \tplQuestion::parse($this->aQuestion);
     return $this;
 }
Example #2
0
 /**
  * Get array for this one question,
  * set $this->Question
  * and also set $this->aTplVars['body']
  * with parsed tplQuestion block
  *
  * @throws \Lampcms\Lampcms404Exception is question not found
  * @return object $this
  */
 protected function getQuestion()
 {
     $isModerator = $this->Registry->Viewer->isModerator();
     $this->noComments = false === (bool) $this->Registry->Ini->MAX_COMMENTS;
     d('no comments: ' . $this->noComments);
     $aFields = $this->noComments || false === (bool) $this->Registry->Ini->SHOW_COMMENTS ? array('comments' => 0) : array();
     $this->aQuestion = $this->Registry->Mongo->QUESTIONS->findOne(array('_id' => (int) $this->qid), $aFields);
     if (empty($this->aQuestion)) {
         throw new \Lampcms\Lampcms404Exception('@@Question not found@@');
     }
     /**
      * Only moderators can see ip address
      */
     if (!$isModerator && !empty($this->aQuestion['ip'])) {
         unset($this->aQuestion['ip']);
     }
     $deleted = isset($this->aQuestion[Schema::RESOURCE_STATUS_ID]) && $this->aQuestion[Schema::RESOURCE_STATUS_ID] === Schema::DELETED || !empty($this->aQuestion[Schema::DELETED_TIMESTAMP]) ? ' deleted' : false;
     $this->aQuestion['pending'] = isset($this->aQuestion[Schema::RESOURCE_STATUS_ID]) && $this->aQuestion[Schema::RESOURCE_STATUS_ID] === Schema::PENDING;
     $this->Question = new Question($this->Registry, $this->aQuestion);
     if ($deleted) {
         if (!$isModerator && !\Lampcms\isOwner($this->Registry->Viewer, $this->Question)) {
             throw new \Lampcms\Lampcms404Exception('@@Question was deleted on@@ ' . date('F j Y', $this->aQuestion['i_del_ts']));
         }
         /**
          * If Viewer is moderator, then viewer
          * will be able to view deleted item
          * This will add 'deleted' class to question table
          */
         $this->aQuestion['deleted'] = $deleted;
         if (!empty($this->aQuestion['a_deleted'])) {
             $this->aQuestion['deletedby'] = \tplDeletedby::parse($this->aQuestion['a_deleted'], false);
             d('deletedby: ' . $this->aQuestion['deletedby']);
         }
     }
     /**
      * Only Moderator or Owner can see pending questions
      * A notice is added to the question indicating it's pending approval
      * Moderators will be able to approve it.
      * Author will be able to edit it.
      * Others will get 404 error
      */
     if ($this->aQuestion['pending']) {
         if (!$isModerator && !\Lampcms\isOwner($this->Registry->Viewer, $this->Question)) {
             throw new \Lampcms\Lampcms404Exception('@@Question not found@@');
         }
     }
     /**
      * Guests will have to see filtered
      * content
      */
     if (!$this->isLoggedIn()) {
         $this->aQuestion['b'] = Badwords::filter($this->aQuestion['b'], true);
     }
     if ($this->noComments) {
         $this->aQuestion['nocomments'] = ' nocomments';
     }
     $breadcrumb = empty($this->aQuestion[Schema::CATEGORY_ID]) ? '' : $this->getBreadcrumb($this->aQuestion[Schema::CATEGORY_ID]);
     $this->aPageVars['body'] = $breadcrumb . \tplQuestion::parse($this->aQuestion);
     return $this;
 }