Example #1
0
 /**
  * Delete a review
  *
  * @return  void
  */
 public function deletereview()
 {
     // Is the user logged in?
     if (User::isGuest()) {
         $this->setError(Lang::txt('PLG_RESOURCES_REVIEWS_LOGIN_NOTICE'));
         return;
     }
     $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 = \Components\Resources\Reviews\Models\Review::oneOrFail($reviewid);
     // Permissions check
     if ($review->get('user_id') != User::get('id') && !User::authorise('core.admin')) {
         return;
     }
     $review->set('state', \Components\Resources\Reviews\Models\Review::STATE_DELETED);
     $review->save();
     // 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));
 }
Example #2
0
 /**
  * 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
     $reviews = \Components\Resources\Reviews\Models\Review::all()->whereEquals('resource_id', $model->resource->id)->whereIn('state', array(\Components\Resources\Reviews\Models\Review::STATE_PUBLISHED, \Components\Resources\Reviews\Models\Review::STATE_FLAGGED))->ordered()->rows();
     // 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)));
         }
         // Instantiate a view
         $view = $this->view('default', 'browse')->set('voting', $this->params->get('voting', 1))->set('option', $option)->set('resource', $model->resource)->set('reviews', $reviews)->set('banking', $this->banking)->set('infolink', $this->infolink)->set('config', $this->params)->set('h', $h)->setErrors($h->getErrors());
         // Return the output
         $arr['html'] = $view->loadTemplate();
     }
     // Build the HTML meant for the "about" tab's metadata overview
     if ($rtrn == 'all' || $rtrn == 'metadata') {
         $url = 'index.php?option=' . $option . '&' . ($model->resource->alias ? 'alias=' . $model->resource->alias : 'id=' . $model->resource->id) . '&active=' . $this->_name;
         $view = $this->view('default', 'metadata')->set('reviews', $reviews)->set('url', Route::url($url))->set('url2', Route::url($url . '&action=addreview#reviewform'));
         $arr['metadata'] = $view->loadTemplate();
     }
     return $arr;
 }