Пример #1
0
 /**
  * Get a list or count of comments
  *
  * @param   string  $rtrn    Data format to return
  * @param   array   $filters Filters to apply to data fetch
  * @param   boolean $clear   Clear cached data?
  * @return  mixed
  */
 public function replies($rtrn = 'list', $filters = array(), $clear = false)
 {
     if (!isset($filters['item_id'])) {
         $filters['item_id'] = $this->get('id');
     }
     if (!isset($filters['item_type'])) {
         $filters['item_type'] = 'answer';
     }
     if (!isset($filters['parent'])) {
         $filters['parent'] = 0;
     }
     if (!isset($filters['state'])) {
         $filters['state'] = array(self::APP_STATE_PUBLISHED, self::APP_STATE_FLAGGED);
     }
     switch (strtolower($rtrn)) {
         case 'count':
             if (!isset($this->_comments_count) || !is_numeric($this->_comments_count) || $clear) {
                 $this->_comments_count = 0;
                 if (!$this->_comments) {
                     $c = $this->comments('list', $filters);
                 }
                 foreach ($this->_comments as $com) {
                     $this->_comments_count++;
                     if ($com->replies()) {
                         foreach ($com->replies() as $rep) {
                             $this->_comments_count++;
                             if ($rep->replies()) {
                                 $this->_comments_count += $rep->replies()->total();
                             }
                         }
                     }
                 }
             }
             return $this->_comments_count;
             break;
         case 'list':
         case 'results':
         default:
             if (!$this->_comments instanceof ItemList || $clear) {
                 $tbl = new Item\Comment($this->_db);
                 if ($this->get('replies', null) !== null) {
                     $results = $this->get('replies');
                 } else {
                     $results = $tbl->find($filters);
                 }
                 if ($results) {
                     foreach ($results as $key => $result) {
                         $results[$key] = new Comment($result);
                         $results[$key]->set('question_id', $this->get('question_id'));
                     }
                 } else {
                     $results = array();
                 }
                 $this->_comments = new ItemList($results);
             }
             return $this->_comments;
             break;
     }
 }
Пример #2
0
 /**
  * Display a list of entries
  *
  * @return  void
  */
 public function displayTask()
 {
     // Get filters
     $this->view->filters = array('search' => Request::getState($this->_option . '.' . $this->_controller . '.search', 'search', ''), 'wish' => Request::getState($this->_option . '.' . $this->_controller . '.wish', 'wish', 0, 'int'), 'sort' => Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'title'), 'sort_Dir' => Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'ASC'), 'limit' => Request::getState($this->_option . '.' . $this->_controller . '.limit', 'limit', Config::get('list_limit'), 'int'), 'start' => Request::getState($this->_option . '.' . $this->_controller . '.limitstart', 'limitstart', 0, 'int'));
     $this->view->filters['sortby'] = $this->view->filters['sort'];
     if (!$this->view->filters['wish']) {
         App::redirect(Route::url('index.php?option=' . $this->_option, false), Lang::txt('Missing wish ID'), 'error');
         return;
     }
     $this->view->wish = new Wish($this->database);
     $this->view->wish->load($this->view->filters['wish']);
     $this->view->wishlist = new Wishlist($this->database);
     $this->view->wishlist->load($this->view->wish->wishlist);
     $obj = new Comment($this->database);
     // Get records
     //$comments1 = $obj->get_wishes($this->view->filters['wishlist'], $this->view->filters, true);
     // add the appropriate filters and apply them to the Item::Comment
     $filters = array('item_type' => 'wish', 'parent' => 0, 'search' => $this->view->filters['search']);
     if ($this->view->filters['wish'] > 0) {
         $filters['item_id'] = $this->view->filters['wish'];
     }
     if (isset($this->view->filters['sort'])) {
         $filter['sort'] = $this->view->filters['sort'];
         if (isset($this->view->filters['sort_Dir'])) {
             $filters['sort_Dir'] = $this->view->filters['sort_Dir'];
         }
     }
     if (isset($this->view->filters['limit'])) {
         $filters['limit'] = $this->view->filters['limit'];
     }
     if (isset($this->view->filters['start'])) {
         $filters['start'] = $this->view->filters['start'];
     }
     /*
      * Load child comments of the parents in the first set.
      * This will result in a pagination limit break, but it provides
      * a clearer story of a wish
      */
     $comments1 = $obj->find($filters, 1);
     $comments = array();
     if (count($comments1) > 0) {
         $pre = '<span class="treenode">&#8970;</span>&nbsp;';
         $spacer = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
         foreach ($comments1 as $comment1) {
             $comment1->prfx = '';
             $comment1->wish = $this->view->filters['wish'];
             $comments[] = $comment1;
             $comments2 = $obj->find(array('item_id' => $comment1->item_id, 'item_type' => 'wish', 'parent' => $comment1->id), 1);
             if (count($comments2) > 0) {
                 foreach ($comments2 as $comment2) {
                     $comment2->prfx = $spacer . $pre;
                     $comment2->wish = $this->view->filters['wish'];
                     $comments[] = $comment2;
                     $comments3 = $obj->find(array('item_id' => $comment2->item_id, 'item_type' => 'wish', 'parent' => $comment2->id), 1);
                     if (count($comments3) > 0) {
                         foreach ($comments3 as $comment3) {
                             $comment3->prfx = $spacer . $spacer . $pre;
                             $comment3->wish = $this->view->filters['wish'];
                             $comments[] = $comment3;
                         }
                     }
                 }
             }
         }
     }
     $this->view->total = count($obj->find(array('item_type' => 'wish'), 1));
     // for pagination
     $this->view->rows = $comments;
     // Output the HTML
     $this->view->display();
 }