/** * Return data on a resource view (this will be some form of HTML) * * @param object $publication Current publication * @param string $option Name of the component * @param array $areas Active area(s) * @param string $rtrn Data to be returned * @param string $version Version name * @param boolean $extended Whether or not to show panel * @return array */ public function onPublication($model, $option, $areas, $rtrn = 'all', $version = 'default', $extended = true) { $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->onPublicationAreas($model)) && !array_intersect($areas, array_keys($this->onPublicationAreas($model)))) { $rtrn = 'metadata'; } } if (!$model->category()->_params->get('plg_reviews') || !$extended) { return $arr; } include_once __DIR__ . DS . 'models' . DS . 'review.php'; // Instantiate a helper object and perform any needed actions $h = new PlgPublicationsReviewsHelper(); $h->publication = $model; $h->option = $option; $h->_option = $option; $h->execute(); // Get reviews for this publication $database = App::get('db'); $r = new \Components\Publications\Tables\Review($database); $reviews = $r->getRatings($model->get('id')); if (!$reviews) { $reviews = array(); } $arr['count'] = count($reviews); $arr['name'] = 'reviews'; // 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) { $rtrn = Request::getVar('REQUEST_URI', Route::url($model->link($this->_name)), 'server'); App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode($rtrn)), Lang::txt('PLG_PUBLICATIONS_REVIEWS_LOGIN_NOTICE'), 'warning'); return; } // Instantiate a view $view = $this->view('default', 'browse')->set('option', $option)->set('publication', $model)->set('reviews', $reviews)->set('voting', $this->params->get('voting', 1))->set('h', $h)->set('banking', $this->banking)->set('infolink', $this->infolink)->set('config', $this->params); if ($h->getError()) { $view->setError($h->getError()); } // 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')->set('url', Route::url($model->link($this->_name)))->set('url2', Route::url($model->link($this->_name) . '&action=addreview#reviewform'))->set('reviews', $reviews); $arr['metadata'] = $view->loadTemplate(); } return $arr; }