Exemple #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 comments($rtrn = 'list', $filters = array(), $clear = false)
 {
     $tbl = new \Hubzero\Item\Comment($this->_db);
     if (!isset($filters['item_id'])) {
         $filters['item_id'] = $this->get('id');
     }
     if (!isset($filters['item_type'])) {
         $filters['item_type'] = 'wish';
     }
     if (!isset($filters['parent'])) {
         $filters['parent'] = 0;
     }
     if (!isset($filters['state'])) {
         $filters['state'] = array(static::APP_STATE_PUBLISHED, static::APP_STATE_FLAGGED);
     }
     switch (strtolower($rtrn)) {
         case 'count':
             if (!is_numeric($this->_cache['comments.count']) || $clear) {
                 $this->_cache['comments.count'] = 0;
                 if (!$this->_cache['comments.list']) {
                     $c = $this->comments('list', $filters);
                 }
                 foreach ($c as $com) {
                     $this->_cache['comments.count']++;
                     if ($com->replies()->total()) {
                         foreach ($com->replies() as $rep) {
                             $this->_cache['comments.count']++;
                             if ($rep->replies()->total()) {
                                 $this->_cache['comments.count'] += $rep->replies()->total();
                             }
                         }
                     }
                 }
             }
             return $this->_cache['comments.count'];
             break;
         case 'authors':
             if (!is_array($this->_cache['comments.authors']) || $clear) {
                 $this->_cache['comments.authors'] = array();
                 if (!$this->_cache['comments.authors']) {
                     $c = $this->comments('list', $filters);
                 }
                 foreach ($c as $com) {
                     $this->_cache['comments.authors'][] = $com->get('added_by');
                     if ($com->replies()->total()) {
                         foreach ($com->replies() as $rep) {
                             $this->_cache['comments.authors'][] = $rep->get('added_by');
                             if ($rep->replies()->total()) {
                                 foreach ($rep->replies() as $res) {
                                     $this->_cache['comments.authors'][] = $res->get('added_by');
                                 }
                             }
                         }
                     }
                 }
                 $this->_cache['comments.authors'] = array_unique($this->_cache['comments.authors']);
             }
             return $this->_cache['comments.authors'];
             break;
         case 'list':
         case 'results':
         default:
             if (!$this->_cache['comments.list'] instanceof ItemList || $clear) {
                 if ($results = $tbl->find($filters)) {
                     foreach ($results as $key => $result) {
                         $results[$key] = new Comment($result);
                     }
                 } else {
                     $results = array();
                 }
                 $this->_cache['comments.list'] = new ItemList($results);
             }
             return $this->_cache['comments.list'];
             break;
     }
 }
Exemple #2
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'] = 'review';
     }
     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 \Hubzero\Base\ItemList || $clear) {
                 $tbl = new \Hubzero\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 ResourcesModelComment($result);
                     }
                 } else {
                     $results = array();
                 }
                 $this->_comments = new \Hubzero\Base\ItemList($results);
             }
             return $this->_comments;
             break;
     }
 }
Exemple #3
0
 /**
  * Get all replies for an item
  *
  * @param      object  $item     Item to look for reports on
  * @param      string  $category Item type
  * @param      integer $level    Depth
  * @param      boolean $abuse    Abuse flag
  * @return     array
  */
 public static function getComments($id, $item, $category, $level, $abuse = false)
 {
     $database = App::get('db');
     $level++;
     $hc = new \Hubzero\Item\Comment($database);
     $comments = $hc->find(array('parent' => $level == 1 ? 0 : $item->id, 'item_id' => $id, 'item_type' => $category));
     if ($comments) {
         foreach ($comments as $comment) {
             $comment->replies = self::getComments($id, $comment, 'review', $level, $abuse);
             if ($abuse) {
                 $comment->abuse_reports = self::getAbuseReports($comment->id, 'review');
             }
         }
     }
     return $comments;
 }
Exemple #4
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
     $reply = new \Hubzero\Item\Comment($database);
     $comments1 = $reply->find(array('parent' => $reviewid, 'item_type' => 'pubreview', 'item_id' => $publication->get('id')));
     if (count($comments1) > 0) {
         foreach ($comments1 as $comment1) {
             $reply->setState($comment1->id, 2);
         }
     }
     // 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 #5
0
 /**
  * Delete a review
  *
  * @return     void
  */
 public function deletereview()
 {
     $database = App::get('db');
     $resource =& $this->resource;
     // Incoming
     $reviewid = Request::getInt('comment', 0);
     // Do we have a review ID?
     if (!$reviewid) {
         $this->setError(Lang::txt('PLG_RESOURCES_REVIEWS_NO_ID'));
         return;
     }
     // Do we have a resource ID?
     if (!$resource->id) {
         $this->setError(Lang::txt('PLG_RESOURCES_REVIEWS_NO_RESOURCE_ID'));
         return;
     }
     $review = new \Components\Resources\Tables\Review($database);
     $review->load($reviewid);
     // Permissions check
     if ($review->user_id != User::get('id') && !User::authorise('core.admin')) {
         return;
     }
     $review->state = 2;
     $review->store();
     // Delete the review's comments
     $reply = new \Hubzero\Item\Comment($database);
     $comments1 = $reply->find(array('parent' => $reviewid, 'item_type' => 'review', 'item_id' => $resource->id));
     if (count($comments1) > 0) {
         foreach ($comments1 as $comment1) {
             $reply->setState($comment1->id, 2);
         }
     }
     // Recalculate the average rating for the parent resource
     $resource->calculateRating();
     $resource->updateRating();
     App::redirect(Route::url('index.php?option=' . $this->_option . '&id=' . $resource->id . '&active=reviews', false));
 }