示例#1
0
 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);
 }
 /**
  * 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
0
文件: rating.php 项目: leader716/cops
 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;
 }
 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
0
 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
0
 /**
  * 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
0
 public function getIndex()
 {
     $rating = new Rating();
     $rating = Rating::where('ven_id', '=', '14')->avg('rvalue');
     echo $rating;
     //return 'Ratings';
 }
 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
0
 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);
 }
 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]);
 }
 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
0
 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
0
 public function save()
 {
     if (!isset($this->timestamp) || $this->timestamp == '') {
         $this->timestamp = date('Y-m-d H:i:s');
     }
     return parent::save();
 }
 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));
 }
 public static function can_edit($id)
 {
     $v = Rating::find($id);
     if ($v && static::is_logged_user($v->user_id)) {
         return true;
     }
     return false;
 }
示例#16
0
		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);
		}
 public function executeRate()
 {
     $params = explode('.', $this->getRequestParameter('object_id'));
     $type = $params[0];
     $object_id = $params[1];
     $value = $this->getRequestParameter('value');
     $rating = null;
     if ($type == Rating::APPLICATION) {
         $object = Doctrine::getTable('Application')->find($object_id);
         $q = new Doctrine_Query();
         $rating = $q->select('r.*')->from('Rating r')->where('application_id = ? and user_id = ?', array($object_id, $this->getUser()->getId()))->fetchOne();
         if (!$rating) {
             $rating = new Rating();
             $rating->setUserId($this->getUser()->getId());
             $rating->setApplicationId($object_id);
         }
     } elseif ($type == Rating::MODULE) {
         $object = Doctrine::getTable('Madule')->find($object_id);
         $q = new Doctrine_Query();
         $rating = $q->select('r.*')->from('Rating r')->where('madule_id = ? and user_id = ?', array($object_id, $this->getUser()->getId()))->fetchOne();
         if (!$rating) {
             $rating = new Rating();
             $rating->setUserId($this->getUser()->getId());
             $rating->setMaduleId($object_id);
         }
     } elseif ($type == Rating::THEME) {
         $object = Doctrine::getTable('Theme')->find($object_id);
         $q = new Doctrine_Query();
         $rating = $q->select('r.*')->from('Rating r')->where('theme_id = ? and user_id = ?', array($object_id, $this->getUser()->getId()))->fetchOne();
         if (!$rating) {
             $rating = new Rating();
             $rating->setUserId($this->getUser()->getId());
             $rating->setThemeId($object_id);
         }
     }
     $this->forward404Unless($value <= 5);
     $this->forward404Unless($value >= 1);
     if ($rating) {
         $rating->setValue($value);
         $rating->save();
         $this->my_rating = $value;
         $this->rating = $object->getRating();
     }
 }
 public function testCreateRatingSuccess()
 {
     $_params = $this->_params;
     $_params['user_id'] = $this->_user_id;
     $response = $this->_getAuth($_params);
     //get created login information
     $rating_infor = Rating::get(array('user_id', 'wine_unique_id', 'rate', 'comment_count', 'like_count', 'is_my_wine', 'updated_at', 'created_at', 'id'))->last();
     $this->assertNotNull($rating_infor);
     $this->assertEquals(array("code" => ApiResponse::OK, "data" => $rating_infor->toArray()), json_decode($response->getContent(), true));
 }
示例#19
0
 /**
  * Override delete method
  * Delete topic itself and all it's comments, ratings, and view counter
  */
 public function delete()
 {
     $tid = $this->id;
     // delete view counter
     Counter::where("[entityId] = ? AND [entityTypeId] = ?", [$tid, Topic::ENTITY_TYPE])->delete();
     Rating::where("[entityId] = ? AND [entityType] = ?", [$tid, Topic::ENTITY_TYPE])->delete();
     RatingStatistic::where("[entityId] = ? AND [entityType] = ?", [$tid, Topic::ENTITY_TYPE])->delete();
     Comment::where("[topicId] = ?", $tid)->delete();
     parent::delete();
 }
 public function testUpdateRatingSuccess()
 {
     $this->setUpRating();
     $_params = $this->_params;
     //dd(json_encode($_params));
     $response = $this->action('POST', 'RatingController@update', array('id' => 1), array('data' => json_encode($_params), '_method' => 'PUT'));
     //get created login information
     $rating_infor = Rating::where('id', 1)->first();
     $this->assertEquals(array("code" => ApiResponse::OK, "data" => $rating_infor->toArray()), json_decode($response->getContent(), true));
 }
示例#21
0
 public function showIndexJson()
 {
     // $parking_lots = ParkingLot::all();
     $lots_array = [];
     $parking_lots = DB::table('parking_lots')->select('id', 'name', 'lat', 'lng', 'address', 'price', 'max_spots')->get();
     // $ratings = new RatingsController();
     $parking_lots = Rating::ratingOrder($parking_lots);
     Log::info($parking_lots);
     return Response::json($parking_lots);
 }
示例#22
0
 public function comments_column_content($column, $comment_ID)
 {
     if ('wpkb_rating' !== $column) {
         return;
     }
     $comment = get_comment($comment_ID);
     if ($comment->comment_type === '_wpkb_rating') {
         $rating = Rating::from_comment($comment);
         echo $rating->rating;
     }
 }
示例#23
0
		public static function wrap($ratings)
		{
			//package all ratings
			$rateList = array();
			foreach( $ratings as $rating )
			{
				array_push($rateList, new Rating($rating['ratingid'], $rating['rating'], $rating['userid'], $rating['itemid'], $rating['time'], $rating['commentid']));
			}
			
			return Rating::sendback($rateList);
		}
示例#24
0
 public function deleteIssue()
 {
     if (Auth::user()->isAdmin()) {
         $issue_id = Input::get('issue_id');
         $deletedRatings = Rating::where('issue_id', '=', $issue_id)->delete();
         $deletedIssueFollows = IssueFollow::where('issue_id', '=', $issue_id)->delete();
         $issue = Issue::find($issue_id);
         $issue->delete();
     } else {
         return App::abort(404);
     }
 }
 protected function setConn()
 {
     try {
         // Connect and create the PDO object
         self::$conn = new PDO("mysql:host=" . DBHOST . "; dbname=" . DBNAME, DBUSER, DBPASS);
         // Sets to handle the errors in the ERRMODE_EXCEPTION mode
         self::$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         self::$conn->exec('SET CHARACTER SET utf8');
         // Sets encoding UTF-8
     } catch (PDOException $e) {
         $this->eror = 'Unable to connect to MySQL: ' . $e->getMessage();
     }
 }
示例#26
0
 public static function getRating($type, $id)
 {
     $rating = 0;
     $ratings = Rating::where('item_id', $id)->where('item_type', $type)->get();
     $numRatings = sizeof($ratings);
     if ($numRatings) {
         for ($i = 0; $i < $numRatings; $i++) {
             $rating += $ratings[$i]['rating'];
         }
         $rating = $rating / $numRatings;
     }
     return array('rating' => $rating, 'numRatings' => $numRatings);
 }
示例#27
0
 public function run()
 {
     $faker = Faker::create();
     $parking_lot = ParkingLot::all()->random();
     $user = User::firstOrFail();
     foreach (range(1, 10) as $index) {
         $rating = new Rating();
         $rating->stars = $faker->numberBetween($min = 1, $max = 5);
         $rating->comment = 'Great Parking Lot';
         $rating->recommended = $faker->boolean;
         $rating->parking_lot_id = $parking_lot->id;
         $rating->user_id = $user->id;
         $rating->save();
         $parking_lot = ParkingLot::all()->random();
         $rating2 = new Rating();
         $rating2->stars = $faker->numberBetween($min = 1, $max = 5);
         $rating2->comment = 'Excellent Service';
         $rating2->recommended = $faker->boolean;
         $rating2->parking_lot_id = $parking_lot->id;
         $rating2->user_id = $user->id;
         $rating2->save();
         $parking_lot = ParkingLot::all()->random();
         $rating3 = new Rating();
         $rating3->stars = $faker->numberBetween($min = 1, $max = 5);
         $rating3->comment = 'Average Parking Lot';
         $rating3->recommended = $faker->boolean;
         $rating3->parking_lot_id = $parking_lot->id;
         $rating3->user_id = $user->id;
         $rating3->save();
         $parking_lot = ParkingLot::all()->random();
         $rating4 = new Rating();
         $rating4->stars = $faker->numberBetween($min = 1, $max = 5);
         $rating4->comment = 'Bad Customer Service';
         $rating4->recommended = $faker->boolean;
         $rating4->parking_lot_id = $parking_lot->id;
         $rating4->user_id = $user->id;
         $rating4->save();
     }
 }
示例#28
0
 /**
  * @param array $arrays
  * @return Collection
  */
 public static function fromArray(array $arrays)
 {
     $collection = new self(array());
     foreach ($arrays as $array) {
         // skip empty ratings
         if (empty($array['rating'])) {
             continue;
         }
         $rating = Rating::fromArray($array);
         $collection->add($rating);
     }
     return $collection;
 }
 public function testUserSumRating()
 {
     Rating::unguard();
     $post1 = Post::find(1);
     $post2 = Post::find(2);
     $user1 = User::find(1);
     Rating::create(['id' => 5, 'rating' => 1, 'rateable_id' => $post1->id, 'rateable_type' => 'Post', 'user_id' => $user1->id]);
     Rating::create(['id' => 6, 'rating' => 1, 'rateable_id' => $post2->id, 'rateable_type' => 'Post', 'user_id' => $user1->id]);
     Rating::reguard();
     $this->assertEquals(6, Post::find(1)->userSumRating);
     $this->assertEquals(6, Post::find(1)->userSumRating());
     $this->assertEquals(2, Post::find(2)->userSumRating);
     $this->assertEquals(2, Post::find(2)->userSumRating());
 }
示例#30
0
 public function run()
 {
     if (isset($this->model->rating)) {
         $rating = $this->model->rating;
     } else {
         $rating = Rating::getValue($this->model);
         $rating = Rating::getHtml($rating);
     }
     $model_id = get_class($this->model);
     $value = null;
     if (!Yii::app()->user->isGuest) {
         $value = Rating::model()->fetchScalarByAttributes(array('user_id' => Yii::app()->user->id, 'object_id' => $this->model->id, 'model_id' => $model_id), 'value');
     }
     $this->render('RatingWidget', array('object_id' => $this->model->id, 'user_id' => $this->model->getUserId(), 'model_id' => $model_id, 'rating' => $rating, 'value' => $value));
 }