コード例 #1
0
ファイル: resources.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Removes an item reported as abusive
  *
  * @param      integer $referenceid ID of the database table row
  * @param      integer $parentid    If the element has a parent element
  * @param      string  $category    Element type (determines table to look in)
  * @param      string  $message     Message to user to append to
  * @return     string
  */
 public function deleteReportedItem($referenceid, $parentid, $category, $message)
 {
     if (!$this->_canHandle($category)) {
         return null;
     }
     $this->loadLanguage();
     $database = App::get('db');
     switch ($category) {
         case 'review':
             include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'tables' . DS . 'resource.php';
             include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'tables' . DS . 'review.php';
             // Delete the review
             $review = new \Components\Resources\Tables\Review($database);
             $review->load($referenceid);
             $review->state = 2;
             $review->store();
             // Recalculate the average rating for the parent resource
             $resource = new \Components\Resources\Tables\Resource($database);
             $resource->load($parentid);
             $resource->calculateRating();
             if (!$resource->store()) {
                 $this->setError($resource->getError());
                 return false;
             }
             $message .= Lang::txt('PLG_SUPPORT_RESOURCES_NOTIFICATION_OF_REMOVAL', $parentid);
             break;
         case 'reviewcomment':
             $comment = \Hubzero\Item\Comment::oneOrFail($referenceid);
             $comment->set('state', $comment::STATE_DELETED);
             if (!$comment->save()) {
                 $this->setError($comment->getError());
                 return false;
             }
             $message .= Lang::txt('PLG_SUPPORT_RESOURCES_NOTIFICATION_OF_REMOVAL', $parentid);
             break;
     }
     return $message;
 }
コード例 #2
0
ファイル: helper.php プロジェクト: mined-gatech/hubzero-cms
 /**
  * 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));
 }