public function actionAdd()
 {
     $model = new Rating();
     $id = yii::$app->request->get('id');
     $type = yii::$app->request->get('type');
     $type = !empty($type) ? yii::$app->request->get('type') : 'like';
     $model->UpdateRating($id, $type);
     $item = $model::find()->where(['item' => $id])->one();
     return $this->render('index', ['rating' => $item->rating, 'id_item' => $id]);
 }
 /**
  * Displays a single Activity model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $rate = new \app\models\Rating();
     $activityProvider = new ActiveDataProvider(['query' => \app\models\Rating::find()->where(['activity_id' => $id]), 'pagination' => ['pageSize' => 8]]);
     Yii::$app->notification->viewer($id);
     return $this->render('view', ['model' => $this->findModel($id), 'rate' => $rate, 'activityProvider' => $activityProvider]);
 }
 /**
  * @param $rating
  * @param $rated_id
  * @param $rated_type
  * @param $rated_by_id
  * @param $rated_by_type
  * @return Rating
  */
 public function update($rating, $rated_id, $rated_type, $rated_by_id, $rated_by_type)
 {
     $current = Rating::where('rated_type', '=', $rated_type)->where('rated_id', $rated_id)->where('rated_by_type', $rated_by_type)->where('rated_by_id', $rated_by_id)->first();
     if ($current) {
         $current->rating = $rating;
         $this->raiseEvents($rated_id, $rated_type, $rated_by_id);
     }
     return $current;
 }
Esempio n. 4
0
 public function create()
 {
     $formats = Format::all();
     $genres = Genre::all();
     $labels = Label::all();
     $ratings = Rating::all();
     $sounds = Sound::all();
     return view('create', ['formats' => $formats, 'labels' => $labels, 'genres' => $genres, 'ratings' => $ratings, 'sounds' => $sounds]);
 }
Esempio n. 5
0
 /**
  * Lists all Country models.
  * @return mixed
  */
 public function actionIndex()
 {
     if (Yii::$app->request->isAjax) {
         \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
         $id = (int) Yii::$app->request->post('id', null);
         $rate = (double) Yii::$app->request->post('rate', null);
         if (!Yii::$app->user->isGuest && $id && $rate) {
             $rate_arr = ['Rating' => ['user_id' => $id, 'sender_id' => Yii::$app->user->getId(), 'created_at' => time(), 'rate' => $rate]];
             $rating = Rating::findOne(['user_id' => $id, 'sender_id' => Yii::$app->user->getId()]);
             if (!$rating) {
                 $rating = new Rating();
             }
             if ($rating->load($rate_arr) && $rating->validate()) {
                 $rating->save();
                 $user = User::findOne($id);
                 $count = count($user->rating);
                 $sum = 0;
                 foreach ($user->rating as $r) {
                     $sum += $r->rate;
                 }
                 $user->rate = round($sum / $count, 1);
                 $epsilon = 0.001;
                 $tmp = $user->rate - $user->rate % 10;
                 if ($tmp - 0.5 < $epsilon) {
                     $tmp = 0.5;
                 } elseif ($tmp > 0.5) {
                     $tmp = 1;
                 } else {
                     $tmp = 0;
                 }
                 $user->rate = $user->rate % 10 + $tmp;
                 $user->scenario = 'rate';
                 $user->save();
                 return ['status' => 1, 'rate' => $user->rate];
             } else {
                 $errors = ActiveForm::validate($rating);
                 return ['status' => 0, 'error' => $errors];
             }
         }
         return ['status' => 0, 'erorrs' => ['You have no access or incorrect data!']];
     }
 }
Esempio n. 6
0
 public function getRating(Request $request)
 {
     $id_place = $request['place_id'];
     $id_mozier = $request['mozier_id'];
     $rating = Rating::where('mozier_id', '=', $id_mozier)->where('place_id', '=', $id_place)->get();
     if ($rating) {
         return $rating;
     } else {
         return $this->notFoundResponse();
     }
 }
 public function findUniqueRatings($dvds)
 {
     $added = [];
     $ratings = [];
     foreach ($dvds as $dvd) {
         if (!array_key_exists($dvd->rating_id, $added)) {
             $added[$dvd->rating_id] = true;
             $ratings[] = Rating::find($dvd->rating_id);
         }
     }
     return $ratings;
 }
Esempio n. 8
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Rating::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'activity_id' => $this->activity_id, 'user_id' => $this->user_id, 'rate' => $this->rate]);
     return $dataProvider;
 }
 public function create()
 {
     return view('create', ['genres' => Genre::all(), 'ratings' => Rating::all(), 'labels' => Label::all(), 'sounds' => Sound::all(), 'formats' => Format::all()]);
 }
Esempio n. 10
0
            ?>
                                                <h3 class="text-center color-blue bold-fonts"><?php 
            echo $modela->title;
            ?>
</h3>    
                                                <?php 
        }
        ?>
                                            <p class="text-center"><?php 
        echo date("F jS, Y", strtotime($modela->date));
        ?>
</p>
                                        </div>
                                        <div class="rating-box">
                                            <?php 
        echo StarRating::widget(['name' => 'Rating[rate]', 'value' => Rating::averageRating($modela->id) == 0 ? 0 : Rating::averageRating($modela->id), 'disabled' => true, 'id' => 'rateinput' . $modela->id]);
        ?>
                                            <?php 
        echo Html::hiddenInput('Rating[activity_id]', $modela->id);
        ?>
                                        </div>
                                    </div>
                                </div>
                                <?php 
        if (++$i > 2) {
            break;
        }
    }
    ?>
                        <?php 
} elseif ($model->level == 3) {
Esempio n. 11
0
 public function postRating(Request $request)
 {
     $input = $request->only(['rating', 'article_id']);
     $input['user_id'] = Auth::id();
     if ($input['rating'] > 0 && $input['rating'] < 6) {
         if ($rating = Rating::where('user_id', '=', $input['user_id'])->where('article_id', '=', $input['article_id'])->first()) {
             $rating->update($input);
         } else {
             Rating::create($input);
         }
     }
     return response()->json(['result' => 'success']);
 }
 public function insertdvd(Request $request)
 {
     $format_id = $request->input('format');
     $genre_id = $request->input('genre');
     $label_id = $request->input('label');
     $rating_id = $request->input('rating');
     $sound_id = $request->input('sound');
     $title = $request->input('title');
     $validator = Validator::make($request->all(), ['title' => 'required|min:5']);
     if ($validator->fails()) {
         return redirect("/dvds/create")->withErrors($validator)->withInput();
     }
     $dvd = new DVD();
     $dvd->title = $title;
     $dvd->format_id = $format_id;
     $dvd->genre_id = $genre_id;
     $dvd->label_id = $label_id;
     $dvd->rating_id = $rating_id;
     $dvd->sound_id = $sound_id;
     $dvd->save();
     $request->session()->flash('success', 'DVD successfully added!');
     $formats = Format::all();
     $genres = Genre::all();
     $labels = Label::all();
     $ratings = Rating::all();
     $sounds = Sound::all();
     return view('create', ['formats' => $formats, 'genres' => $genres, 'labels' => $labels, 'ratings' => $ratings, 'sounds' => $sounds, 'success' => $request->session()->get('success')]);
 }
Esempio n. 13
0
echo $model->description;
?>
</p>
            </div>
        </div>

        <div class="rating-box box-body box box-primary">
            <div class="col-md-12 background-white"><h3 class="color-blue text-aqua text-center">Current Rating</h3></div>
            <div class="col-md-6">
                <div class="rating-box">

                    <?php 
$form = ActiveForm::begin(['action' => '@web/rating/create', 'id' => 'rateform' . $model->id]);
?>
                    <?php 
echo StarRating::widget(['name' => 'Rating[rate]', 'value' => Rating::averageRating($model->id) == 0 ? 0 : Rating::averageRating($model->id), 'disabled' => Yii::$app->user->identity->level == 0 ? true : Rating::countEntered(Yii::$app->user->id, $model->id), 'id' => 'rateinput' . $model->id]);
?>
                    <?php 
echo Html::hiddenInput('Rating[activity_id]', $model->id);
?>
                    <?php 
//var_dump($model->id); die();
?>
                    <?php 
ActiveForm::end();
?>
                </div>        
            </div>
            <div class="col-md-6">
                <h1 class="font-large color-green text-center">Your activity got <span class="color-orange"><?php 
echo $rate->averageRating($model->id);
Esempio n. 14
0
 public function getLikes()
 {
     return $this->hasOne(Rating::className(), ['item' => 'id']);
 }
Esempio n. 15
0
 public function getRatings()
 {
     return $this->hasMany(Rating::className(), ['user_id' => 'id'])->orderBy(['id' => SORT_DESC]);
 }
Esempio n. 16
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRatings()
 {
     return $this->hasMany(Rating::className(), ['activity_id' => 'id']);
 }
 /**
  * Finds the Rating model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Rating the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Rating::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Esempio n. 18
0
 public function average()
 {
     return Rating::where("coupon_id", "=", $this->id)->avg("value");
 }
Esempio n. 19
0
 public function getTeacherRatingValueAttribute()
 {
     $rating = Rating::where('article_id', '=', $this->id)->where('text', '<>', '')->first(['rating']);
     return $rating->rating;
 }
Esempio n. 20
0
 public function countEntered($id, $aid)
 {
     return count(Rating::find()->where(['user_id' => $id, 'activity_id' => $aid])->all()) > 0 ? true : false;
 }
Esempio n. 21
0
 public function _post_rating($coupon, $value)
 {
     if ($value == 0) {
         return false;
     }
     $user = Auth::user()->id;
     $rating = Rating::where("user_id", "=", $user)->where("coupon_id", "=", $coupon)->first();
     if (!$rating) {
         $rating = new Rating();
     }
     $rating->user_id = $user;
     $rating->coupon_id = $coupon;
     $rating->value = $value;
     $rating->save();
     return true;
 }
Esempio n. 22
0
 public function checkRateChange()
 {
     $rating = Rating::findOne(['user_id' => $this->id, 'sender_id' => Yii::$app->user->getId()]);
     return !$rating;
 }