/** * 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'))); }
/** * Vote on the entry * * @param mixed $vote * @return boolean */ public function vote($vote) { if (!$this->isOpen()) { $this->setError(Lang::txt('Cannot vote for closed wishes.')); return false; } if ($this->get('proposed_by') == User::get('id')) { $this->setError(Lang::txt('Cannot vote for your own entry.')); return false; } $tbl = new \Components\Answers\Tables\Vote($this->_db); $vote = strtolower($vote); // Check if the user already voted if ($voted = $tbl->checkVote($this->get('id'), 'wish', User::get('id'))) { $tbl->loadVote($this->get('id'), 'wish', User::get('id')); if ($vote == $tbl->helpful) { return true; } } $tbl->referenceid = $this->get('id'); $tbl->category = 'wish'; $tbl->voter = User::get('id'); $tbl->ip = Request::ip(); $tbl->voted = Date::toSql(); $tbl->helpful = $vote; if (!$tbl->check()) { $this->setError($tbl->getError()); return false; } if (!$tbl->store()) { $this->setError($tbl->getError()); return false; } return true; }