/**
  * Finds the Rate model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Rate the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Rate::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Esempio n. 2
0
 public function rateByUser($user_id, $rate_score)
 {
     $rater = User::findOne(['id' => $user_id]);
     if ($rater) {
         $rate = Rate::findOne(['rated_id' => $this->id, 'rater_id' => intval($user_id)]);
         $rate_score = floatval($rate_score);
         if (!$rate && !$this->isNewRecord && 0 < $rate_score && 5 >= $rate_score) {
             $rate = new Rate();
             $rate->rated_id = $this->id;
             $rate->rater_id = $rater->id;
             $rate->rate = $rate_score;
             $rate->save();
         }
     }
     return false;
 }