/** * 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; }
/** * 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; }