/** * 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'))); }
/** * Purge data associated with this wish * * @param string $what What to purge * @return boolean True on success, false if not */ public function purge($what) { $what = strtolower($what); switch ($what) { case 'rank': case 'ranks': case 'rankings': $objR = new Tables\Wish\Rank($this->_db); if (!$objR->remove_vote($this->get('id'))) { $this->setError($objR->getError()); return false; } break; case 'vote': case 'votes': case 'feedback': $v = new \Components\Answers\Tables\Vote($this->_db); if (!$v->deleteVotes(array('id' => $this->get('id'), 'category' => 'wish'))) { $this->setError($v->getError()); return false; } break; case 'plan': $plan = $this->plan(); if (!$plan->delete()) { $this->setError($plan->getError()); return false; } break; case 'comment': case 'comments': foreach ($this->comments() as $comment) { if (!$comment->delete()) { $this->setError($comment->getError()); return false; } } break; default: break; } return true; }