public function run() { // query $review = Review::find()->where(['=', 'review_moderation', 'yes'])->orderBy('id_review DESC')->limit(3)->all(); //render view return $this->render('latest', ['review' => $review]); }
public static function getListByBlogId($blog_id, $p = 1, $pageSize = 30) { $blog_id = intval($blog_id); $query = Review::find()->where(['blog_id' => $blog_id]); $count = $query->count(); $pagination = new Pagination(['defaultPageSize' => $pageSize, 'totalCount' => $count]); $list = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['time' => SORT_ASC])->asArray()->limit($pageSize)->all(); return ['list' => $list]; }
/** * Lists all Review models. * @return mixed */ public function actionIndex() { $this->layout = 'main'; $model = new ReviewForm(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['index']); } return $this->render('index', ['reviews' => Review::find()->orderBy(['created_at' => SORT_DESC])->all(), 'model' => $model]); }
public function afterSave($insert, $changedAttributes) { $part = $this->getPartFk()->one(); $query = Review::find()->where(['part_fk' => $this->part_fk]); $sum = $query->sum('rating'); $count = $query->count(); $part->overal_rating = $sum / $count; $part->updateAttributes(['overal_rating']); parent::afterSave($insert, $changedAttributes); }
/** * Displays a single Part model. * @param integer $id * @return mixed */ public function actionView($id) { $model = $this->findModel($id); $parameters = new ActiveDataProvider(['query' => $model->getParameters()]); if (!Yii::$app->user->isGuest) { $userReview = Review::find()->where(['user_fk' => Yii::$app->user->identity->user_id])->andWhere(['part_fk' => $model->part_id])->one(); $partBuildPair = BuildPart::findOne(['part_fk' => $model['part_id'], 'build_guide_fk' => Yii::$app->session['build_id']]); } else { $userReview = NULL; $partBuildPair = NULL; } return $this->render('view', ['model' => $model, 'parameters' => $parameters, 'review' => $userReview, 'partBuildPair' => $partBuildPair]); }
/** * Lists all your student Review models. * @return mixed */ public function actionIndex() { // Show only your reviews // Now hardcoded user ID = 1 which is a student $student_ID = \Yii::$app->user->identity->getId(); // Get the AVG score $avgScore = Review::find()->where(['receiver_id' => $student_ID])->average('score'); Yii::trace($avgScore); // Get the reviews $query = Review::find()->where(['receiver_id' => $student_ID]); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 20]]); return $this->render('index', ['dataProvider' => $dataProvider, 'avgScore' => $avgScore]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Review::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, 'writer_id' => $this->writer_id, 'receiver_id' => $this->receiver_id, 'vacancy_id' => $this->vacancy_id, 'is_anonymous' => $this->is_anonymous, 'score' => $this->score, 'creation_date' => $this->creation_date]); $query->andFilterWhere(['like', 'explanation', $this->explanation]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Review::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(['review_id' => $this->review_id, 'patient_id' => $this->patient_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'subject', $this->subject])->andFilterWhere(['like', 'body', $this->body])->andFilterWhere(['like', 'contact', $this->contact]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Review::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(['review_id' => $this->review_id, 'restaurant_id' => $this->restaurant_id, 'product_id' => $this->product_id]); $query->andFilterWhere(['like', 'review', $this->review]); return $dataProvider; }
/** * Display item */ public function actionArticle() { // form $model = new ContactForm(); // id product $ware = $_GET['ware']; // get data review if ($model->load(Yii::$app->request->post())) { // get data form $reviewData = Yii::$app->request->post("ContactForm"); // get name and body $reviewName = $reviewData['name']; $reviewBody = $reviewData['body']; // get current date $reviewDate = date("Y") . '-' . date("m") . '-' . date("d"); // moderation $reviewModeration = 'no'; // insert review $review = new Review(['review_date' => $reviewDate, 'review_name' => $reviewName, 'product_id' => $ware, 'review' => $reviewBody, 'review_moderation' => $reviewModeration]); $review->save(); Yii::$app->session->setFlash('success', 'После успешной модерации отзыв будет опубликован.'); } // count review product $comment = Review::find()->where(['=', 'product_id', $ware])->andWhere(['=', 'review_moderation', 'yes'])->all(); $amount = count($comment); // find product $article = Product::find()->where(['=', 'id_product', $ware])->all(); // current section foreach ($article as $vlArticle) { $curSection = $vlArticle->section_id; } // find section $section = Section::find()->where(['=', 'id_section', $curSection])->all(); // current catalog foreach ($section as $vlSection) { $curCatalog = $vlSection->catalog_id; } // find catalog $catalog = Catalog::find()->where(['=', 'id_catalog', $curCatalog])->all(); return $this->render('article', ['article' => $article, 'section' => $section, 'catalog' => $catalog, 'model' => $model, 'amount' => $amount, 'comment' => $comment]); }
/** * Get avg score */ public function getReviewScore() { return round(Review::find()->where(['writer_id' => $this->getPrimaryKey()])->average('score'), 1, PHP_ROUND_HALF_UP); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { // $review = \App\Models\Review::find($id); $review->delete(); return redirect("reviews"); }
public function getSubReview($id) { $review = Review::find($id); if ($review) { $sub_reviews = $review->hasSubReviews; if ($sub_reviews) { foreach ($sub_reviews as $sub_review) { $sub_review->mozier; } return $sub_reviews; } } else { return $this->notFoundResponse(); } }
public function actionDeleteReview() { /*if(!Yii::$app->user->can('admin')){ Yii::$app->session->setFlash('error','Нет доступа!'); return $this->redirect('/'); }*/ $review = Review::find()->where(['id' => Yii::$app->request->get('id')])->one(); $review->delete(); }
protected function findModel($id) { Yii::$app->response->format = Response::FORMAT_JSON; if (($model = Review::find()->where(['review_id' => $id])->one()) !== null) { return $model; } else { echo json_encode(array('status' => 0, 'error_code' => Codes::$BAD_REQUEST, 'message' => StatusCodeMessage::$BAD_REQUEST), JSON_PRETTY_PRINT); exit; // throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Lists all Review models. * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => Review::find()]); return $this->render('index', ['dataProvider' => $dataProvider]); }