本文整理汇总了PHP中Rating类的典型用法代码示例。如果您正苦于以下问题:PHP Rating类的具体用法?PHP Rating怎么用?PHP Rating使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Rating类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: starRating
public function starRating($recipeId, $id = null, $value = null)
{
$session = Zend_Registry::get('session');
$log = Zend_Registry::get('log');
// fetch the rating
$ra = new Rating();
$rating = $ra->getRating($recipeId);
// If were passing through a value we already know what to display and are probably read only
if (isset($value)) {
return $this->displayRating($value, $id);
}
// Logged in?
if (!$session->user) {
return $this->displayRating($rating);
}
//$log->debug( $session->user['name'] . ' is logged in' );
$r = new Recipe();
if ($r->isOwner($recipeId)) {
return $this->displayRating($rating);
}
//$log->debug( $session->user['name'] . ' is not the owner' );
// Has this user already rated?
$db = Zend_Registry::get('db');
$select = $db->select()->from('ratings', array("numberOfRatings" => "COUNT(*)"))->where("recipe_id = ?", $recipeId)->where("user_id = ?", $session->user['id']);
//$log->debug( $select->__toString() );
//$log->debug( $db->fetchOne( $select ) );
// If we get a result show the user the overall rating
if ($db->fetchOne($select) > 0) {
return $this->displayRating($rating);
}
//$log->debug( $session->user['name'] . ' has not already rated this' );
// Otherwise show the rating but make it clickable
return $this->displayRating($rating, null, false);
}
示例2: addRate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function addRate($rating_score, $bus_Id)
{
$rateMod = new Rating();
$rateMod->rating_score = $rating_score;
$rateMod->product_id = $bus_Id;
$rateMod->rating_type = 1;
if ($rateMod->save()) {
return $rateMod->rating_id;
}
return 0;
}
示例3: getEntryArray
public static function getEntryArray($query, $params)
{
list(, $result) = parent::executeQuery($query, self::RATING_COLUMNS, "", $params, -1);
$entryArray = array();
while ($post = $result->fetchObject()) {
$ratingObj = new Rating($post->id, $post->rating);
$rating = $post->rating / 2;
$rating = str_format(localize("ratingword", $rating), $rating);
array_push($entryArray, new Entry($rating, $ratingObj->getEntryId(), str_format(localize("bookword", $post->count), $post->count), "text", array(new LinkNavigation($ratingObj->getUri())), "", $post->count));
}
return $entryArray;
}
示例4: saveRating
public function saveRating($params)
{
if (!is_array($params) || count($params) < 1) {
return false;
}
$em = $this->getEntityManager();
$rating = new Rating();
$rating->setArticleId($params['article_id']);
$rating->setStarRating($params['rating']);
$rating->setCreatedOn(new \DateTime());
$em->persist($rating);
$em->flush();
return true;
}
示例5: getPartialUpdate
public function getPartialUpdate(Rating $prior, Rating $fullPosterior, $updatePercentage)
{
$priorGaussian = new GaussianDistribution($prior->getMean(), $prior->getStandardDeviation());
$posteriorGaussian = new GaussianDistribution($fullPosterior->getMean(), $fullPosterior . getStandardDeviation());
// From a clarification email from Ralf Herbrich:
// "the idea is to compute a linear interpolation between the prior and posterior skills of each player
// ... in the canonical space of parameters"
$precisionDifference = $posteriorGaussian->getPrecision() - $priorGaussian->getPrecision();
$partialPrecisionDifference = $updatePercentage * $precisionDifference;
$precisionMeanDifference = $posteriorGaussian->getPrecisionMean() - $priorGaussian . getPrecisionMean();
$partialPrecisionMeanDifference = $updatePercentage * $precisionMeanDifference;
$partialPosteriorGaussion = GaussianDistribution::fromPrecisionMean($priorGaussian->getPrecisionMean() + $partialPrecisionMeanDifference, $priorGaussian->getPrecision() + $partialPrecisionDifference);
return new Rating($partialPosteriorGaussion->getMean(), $partialPosteriorGaussion->getStandardDeviation(), $prior->_conservativeStandardDeviationMultiplier);
}
示例6: calculateNewRating
/**
* This is the function processing described in step 5 of Glickman's paper.
*
* @param Rating $player
* @param array $results
*/
protected function calculateNewRating(Rating $player, array $results)
{
$phi = $player->getGlicko2RatingDeviation();
$sigma = $player->getVolatility();
$a = log(pow($sigma, 2));
$delta = $this->delta($player, $results);
$v = $this->v($player, $results);
// step 5.2 - set the initial values of the iterative algorithm to come in step 5.4
$A = $a;
$B = 0;
if (pow($delta, 2) > pow($phi, 2) + $v) {
$B = log(pow($delta, 2) - pow($phi, 2) - $v);
} else {
$k = 1;
$B = $a - $k * abs($this->tau);
while ($this->f($B, $delta, $phi, $v, $a, $this->tau) < 0) {
$k++;
$B = $a - $k * abs($this->tau);
}
}
// step 5.3
$fA = $this->f($A, $delta, $phi, $v, $a, $this->tau);
$fB = $this->f($B, $delta, $phi, $v, $a, $this->tau);
// step 5.4
while (abs($B - $A) > self::CONVERGENCE_TOLERANCE) {
$C = $A + ($A - $B) * $fA / ($fB - $fA);
$fC = $this->f($C, $delta, $phi, $v, $a, $this->tau);
if ($fC * $fB < 0) {
$A = $B;
$fA = $fB;
} else {
$fA = $fA / 2;
}
$B = $C;
$fB = $fC;
}
$newSigma = exp($A / 2);
$player->setWorkingVolatility($newSigma);
// Step 6
$phiStar = $this->calculateNewRatingDeviation($phi, $newSigma);
// Step 7
$newPhi = 1 / sqrt(1 / pow($phiStar, 2) + 1 / $v);
// note that the newly calculated rating values are stored in a "working" area in the Rating object
// this avoids us attempting to calculate subsequent participants' ratings against a moving target
$player->setWorkingRating($player->getGlicko2Rating() + pow($newPhi, 2) * $this->outcomeBasedRating($player, $results));
$player->setWorkingRatingDeviation($newPhi);
$player->incrementNumberOfResults(count($results));
}
示例7: getIndex
public function getIndex()
{
$rating = new Rating();
$rating = Rating::where('ven_id', '=', '14')->avg('rvalue');
echo $rating;
//return 'Ratings';
}
示例8: get
public function get($id)
{
$doctor = Doctor::with(['companions', 'episodes'])->find($id);
$ratings = Rating::getRating('doctor', $id);
$comments = Comment::where('item_id', $id)->where('item_type', 'doctor')->with('user')->orderBy('created_at', 'desc')->get();
return View::make('items.doctor', ['doctor' => $doctor, 'ratings' => $ratings, 'comments' => $comments]);
}
示例9: deleteLike
public static function deleteLike($rating_id)
{
$error_code = ApiResponse::OK;
$user_id = Session::get('user_id');
if (Rating::where('id', $rating_id)->first()) {
$like = Like::where('rating_id', $rating_id)->where('user_id', $user_id)->first();
if ($like) {
//update like_count on rating
$like_rating = Rating::where('id', $like->rating_id)->first();
if ($like_rating != null) {
$like_rating->like_count = $like_rating->like_count - 1;
$like_rating->save();
}
$like->delete();
$data = 'Like deleted';
} else {
$error_code = ApiResponse::NOT_EXISTED_LIKE;
$data = ApiResponse::getErrorContent(ApiResponse::NOT_EXISTED_LIKE);
}
} else {
$error_code = ApiResponse::UNAVAILABLE_RATING;
$data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_RATING);
}
return array("code" => $error_code, "data" => $data);
}
示例10: get
public function get($season, $episode)
{
$episode = Episode::with(['doctors', 'companions', 'enemies'])->where('season', $season)->where('episode', $episode)->first();
$ratings = Rating::getRating('episode', $episode->id);
$comments = Comment::where('item_id', $episode->id)->where('item_type', 'episode')->with('user')->orderBy('created_at', 'desc')->get();
return View::make('items.episode', ['episode' => $episode, 'ratings' => $ratings, 'comments' => $comments]);
}
示例11: get
public function get($id)
{
$enemy = Enemy::with('episodes')->find($id);
$ratings = Rating::getRating('enemy', $id);
$comments = Comment::where('item_id', $id)->where('item_type', 'enemy')->with('user')->orderBy('created_at', 'desc')->get();
return View::make('items.enemy', ['enemy' => $enemy, 'ratings' => $ratings, 'comments' => $comments]);
}
示例12: show_vars
public static function show_vars(&$vars, $id)
{
$vars['ratings'] = array();
foreach (Rating::find_by('user_id', $id) as $k => $v) {
$vars['ratings'][] = array('rating' => $v, 'beer' => Beer::find($v->beer_id));
}
}
示例13: testGetRatingDetailSuccess
public function testGetRatingDetailSuccess()
{
$this->setUpRating();
$response = $this->call('GET', 'api/rating/1');
$rating_infor = Rating::where('id', 1)->with('wine')->first();
$this->assertEquals(array("code" => ApiResponse::OK, "data" => $rating_infor->toArray()), json_decode($response->getContent(), true));
}
示例14: can_edit
public static function can_edit($id)
{
$v = Rating::find($id);
if ($v && static::is_logged_user($v->user_id)) {
return true;
}
return false;
}
示例15: getByUser
public static function getByUser($id)
{
global $db;
$ratingSQL = "SELECT * FROM ratings WHERE userid=?";
$values = array($id);
$ratings = $db->qwv($ratingSQL, $values);
return Rating::wrap($ratings);
}