示例#1
0
 /**
  * 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;
 }