Exemple #1
0
 /**
  * Get a count or list of the comments on an item
  *
  * @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 comments($what = 'list', $filters = array(), $clear = false)
 {
     if (!isset($filters['item_id'])) {
         $filters['item_id'] = $this->get('id');
     }
     if (!isset($filters['item_type'])) {
         $filters['item_type'] = 'collection';
     }
     if (!isset($filters['state'])) {
         $filters['state'] = array(1, 3);
     }
     switch (strtolower(trim($what))) {
         case 'count':
             if ($this->_cache['comments.count'] === null) {
                 $total = Comment::all()->whereEquals('item_type', $filters['item_type'])->whereEquals('item_id', $this->get('id'))->whereIn('state', $filters['state'])->ordered()->total();
                 $this->_cache['comments.count'] = $total;
             }
             return $this->_cache['comments.count'];
             break;
         case 'list':
         case 'results':
         default:
             if (!is_array($this->_cache['comments.list'])) {
                 $results = Comment::all()->whereEquals('item_type', $filters['item_type'])->whereEquals('item_id', $this->get('id'))->whereIn('state', $filters['state'])->ordered()->rows();
                 $this->_cache['comments.list'] = $results;
             }
             return $this->_cache['comments.list'];
             break;
     }
 }
Exemple #2
0
 /**
  * Delete a review
  *
  * @return  void
  */
 public function deletereview()
 {
     $database = App::get('db');
     $publication =& $this->publication;
     // Incoming
     $reviewid = Request::getInt('comment', 0);
     // Do we have a review ID?
     if (!$reviewid) {
         $this->setError(Lang::txt('PLG_PUBLICATIONS_REVIEWS_NO_ID'));
         return;
     }
     // Do we have a publication ID?
     if (!$publication->exists()) {
         $this->setError(Lang::txt('PLG_PUBLICATIONS_REVIEWS_NO_RESOURCE_ID'));
         return;
     }
     $review = new \Components\Publications\Tables\Review($database);
     $review->load($reviewid);
     // Permissions check
     if ($review->created_by != User::get('id')) {
         return;
     }
     $review->state = 2;
     $review->store();
     // Delete the review's comments
     $comments1 = \Hubzero\Item\Comment::all()->whereEquals('parent', $reviewid)->whereEquals('item_id', $publication->get('id'))->whereEquals('item_type', 'pubreview')->ordered()->rows();
     foreach ($comments1 as $comment1) {
         $comment1->set('state', $comment1::STATE_DELETED);
         $comment1->save();
     }
     // Recalculate the average rating for the parent publication
     $publication->table()->calculateRating();
     $publication->table()->updateRating();
     App::redirect(Route::url($publication->link('reviews')), Lang::txt('PLG_PUBLICATIONS_REVIEWS_REVIEW_DELETED'));
     return;
 }
Exemple #3
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);
     // Get records
     // add the appropriate filters and apply them
     $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 = Comment::all()->whereEquals('item_type', $filters['item_type'])->whereEquals('parent', $filters['parent'])->ordered()->paginated()->rows();
     $comments = array();
     if (count($comments1) > 0) {
         $pre = '<span class="treenode">&#8970;</span>&nbsp;';
         $spacer = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
         foreach ($comments1 as $comment1) {
             $comment1->set('prfx', '');
             $comment1->set('wish', $this->view->filters['wish']);
             $comments[] = $comment1;
             foreach ($comment1->replies() as $comment2) {
                 $comment2->set('prfx', $spacer . $pre);
                 $comment2->set('wish', $this->view->filters['wish']);
                 $comments[] = $comment2;
                 foreach ($comment2->replies() as $comment3) {
                     $comment3->set('prfx', $spacer . $spacer . $pre);
                     $comment3->set('wish', $this->view->filters['wish']);
                     $comments[] = $comment3;
                 }
             }
         }
     }
     $this->view->total = Comment::all()->whereEquals('item_type', $filters['item_type'])->total();
     $this->view->rows = $comments;
     // Output the HTML
     $this->view->display();
 }