case 4.5: $class = ' fourhalf-stars'; break; case 5: $class = ' five-stars'; break; case 0: default: $class = ' no-stars'; break; } $helper = new \Components\Resources\Helpers\Helper($line->id, $database); $helper->getContributors(); // If the user is logged in, get their rating for this resource if (!User::isGuest()) { $mr = new \Components\Resources\Tables\Review($database); $myrating = $mr->loadUserRating($line->id, User::get('id')); } else { $myrating = 0; } switch ($myrating) { case 0.5: $myclass = ' half-stars'; break; case 1: $myclass = ' one-stars'; break; case 1.5: $myclass = ' onehalf-stars'; break; case 2:
/** * 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; }
/** * Return data on a resource view (this will be some form of HTML) * * @param object $resource Current resource * @param string $option Name of the component * @param array $areas Active area(s) * @param string $rtrn Data to be returned * @return array */ public function onResources($model, $option, $areas, $rtrn = 'all') { $arr = array('area' => $this->_name, 'html' => '', 'metadata' => ''); // Check if our area is in the array of areas we want to return results for if (is_array($areas)) { if (!array_intersect($areas, $this->onResourcesAreas($model)) && !array_intersect($areas, array_keys($this->onResourcesAreas($model)))) { $rtrn = 'metadata'; } } if (!$model->type->params->get('plg_reviews')) { return $arr; } $ar = $this->onResourcesAreas($model); if (empty($ar)) { $rtrn = ''; } include_once __DIR__ . DS . 'models' . DS . 'review.php'; // Instantiate a helper object and perform any needed actions $h = new PlgResourcesReviewsHelper(); $h->resource = $model->resource; $h->option = $option; $h->_option = $option; $h->execute(); // Get reviews for this resource $database = App::get('db'); $r = new \Components\Resources\Tables\Review($database); $reviews = $r->getRatings($model->resource->id); if (!$reviews) { $reviews = array(); } // Are we returning any HTML? if ($rtrn == 'all' || $rtrn == 'html') { // Did they perform an action? // If so, they need to be logged in first. if (!$h->loggedin) { // Instantiate a view $rtrn = Request::getVar('REQUEST_URI', Route::url('index.php?option=' . $option . '&id=' . $model->resource->id . '&active=' . $this->_name, false, true), 'server'); App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode($rtrn))); return; } // Instantiate a view $view = new \Hubzero\Plugin\View(array('folder' => $this->_type, 'element' => $this->_name, 'name' => 'browse')); // Thumbs voting CSS & JS $view->voting = $this->params->get('voting', 1); // Pass the view some info $view->option = $option; $view->resource = $model->resource; $view->reviews = $reviews; //$view->voting = $voting; $view->h = $h; $view->banking = $this->banking; $view->infolink = $this->infolink; $view->config = $this->params; if ($h->getError()) { foreach ($h->getErrors() as $error) { $view->setError($error); } } // Return the output $arr['html'] = $view->loadTemplate(); } // Build the HTML meant for the "about" tab's metadata overview if ($rtrn == 'all' || $rtrn == 'metadata') { $view = $this->view('default', 'metadata'); $url = 'index.php?option=' . $option . '&' . ($model->resource->alias ? 'alias=' . $model->resource->alias : 'id=' . $model->resource->id) . '&active=' . $this->_name; $view->reviews = $reviews; $view->url = Route::url($url); $view->url2 = Route::url($url . '&action=addreview#reviewform'); $arr['metadata'] = $view->loadTemplate(); } return $arr; }
/** * 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)); }