Example #1
0
 /**
  * Rate an item
  *
  * @return  void
  */
 public function rateitem()
 {
     $database = App::get('db');
     $publication =& $this->publication;
     $id = Request::getInt('refid', 0);
     $ajax = Request::getInt('no_html', 0);
     $cat = Request::getVar('category', 'pubreview');
     $vote = Request::getVar('vote', '');
     $ip = Request::ip();
     if (!$id || !$publication->exists()) {
         // Cannot proceed
         return;
     }
     // Is the user logged in?
     if (User::isGuest()) {
         $this->setError(Lang::txt('PLG_PUBLICATIONS_REVIEWS_LOGIN_NOTICE'));
         return;
     }
     // Load answer
     $rev = new \Components\Publications\Tables\Review($database);
     $rev->load($id);
     $voted = $rev->getVote($id, $cat, User::get('id'), 'v.id');
     if ($vote) {
         require_once PATH_CORE . DS . 'components' . DS . 'com_answers' . DS . 'tables' . DS . 'vote.php';
         $v = new \Components\Answers\Tables\Vote($database);
         if ($voted) {
             $v->load($voted);
         }
         $v->referenceid = $id;
         $v->category = $cat;
         $v->voter = User::get('id');
         $v->ip = $ip;
         $v->voted = Date::toSql();
         $v->helpful = $vote;
         if (!$v->check()) {
             $this->setError($v->getError());
             return;
         }
         if (!$v->store()) {
             $this->setError($v->getError());
             return;
         }
     }
     // update display
     if ($ajax) {
         $response = $rev->getRating($publication->get('id'), User::get('id'));
         $view = new \Hubzero\Plugin\View(array('folder' => 'publications', 'element' => 'reviews', 'name' => 'browse', 'layout' => '_rateitem'));
         $view->option = $this->_option;
         $view->item = new PublicationsModelReview($response[0]);
         $view->rid = $publication->get('id');
         $view->display();
         exit;
     }
     App::redirect(Route::url($publication->get('reviews')));
 }