Пример #1
0
 public function actionReview()
 {
     $review = new Reviews();
     $review->created = date("Y-m-d H:i");
     $query = Reviews::find();
     $reviews = $query->orderBy('created DESC');
     $countQuery = clone $reviews;
     $pages = new Pagination(['defaultPageSize' => 10, 'totalCount' => $countQuery->count()]);
     $reviews = $query->offset($pages->offset)->limit($pages->limit)->all();
     if ($review->load(Yii::$app->request->post()) && $review->save()) {
         return $this->redirect(['review/review']);
     } else {
         return $this->render('review', ['reviews' => $reviews, 'review' => $review, 'pages' => $pages]);
     }
 }
Пример #2
0
 public function afterSave($insert, $changedAttributes)
 {
     $reviews = \common\models\Reviews::find();
     $transaction = new \yii\db\Query();
     $id = $this->review_trainer_id;
     $rating_count = $reviews->where(['review_trainer_id' => $id])->count();
     $rating_count_positive = $reviews->where(['review_trainer_id' => $id])->andWhere('review_rating > 3')->count();
     $amount_sum = $transaction->from('transaction_history')->where("`class_id` IN (SELECT `class_id` FROM `classes` WHERE `class_trainer_id` = " . abs((int) $id) . ")")->sum('amount');
     $rating_count_positive = @round($rating_count_positive / $rating_count * 100);
     $status = (int) $amount_sum > 1000 && $rating_count_positive >= 75 ? 'Gold' : 'Silver';
     PaymentInformations::updateAll(['payment_user_status' => $status], ['payment_user_id' => [$id]]);
 }
Пример #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Reviews::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]);
     $query->andFilterWhere(['like', 'firstname', $this->firstname])->andFilterWhere(['like', 'review', $this->review]);
     return $dataProvider;
 }
Пример #4
0
 public function actionGetUserRating($id)
 {
     $reviews = \common\models\Reviews::find();
     $rating_count = $reviews->where(['review_trainer_id' => $id])->count();
     $rating_sum = $reviews->where(['review_trainer_id' => $id])->sum('review_rating');
     $rating = @round($rating_sum / $rating_count, 1) % 10;
     if ($rating == 5) {
         $rating = @round($rating_sum / $rating_count) - 0.5;
     } else {
         $rating = @round($rating_sum / $rating_count);
     }
     return ApiHelper::successResponse(['rating' => $rating]);
 }
Пример #5
0
 /**
  * Finds the Reviews model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Reviews the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Reviews::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }