/** * 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]); $query->andFilterWhere(['like', 'first_name', $this->first_name])->andFilterWhere(['like', 'last_name', $this->last_name])->andFilterWhere(['like', 'body', $this->body])->andFilterWhere(['like', 'status', $this->status]); return $dataProvider; }
public static function badges($modelName) { $count = 0; switch ($modelName) { case 'Order': $count = Order::find()->where(['status' => Order::STATUS_NEW])->count(); break; case 'Call': $count = Call::find()->where(['status' => Call::STATUS_NEW])->count(); break; case 'Review': $count = Review::find()->where(['status' => Review::STATUS_NEW])->count(); break; default: $count = 0; break; } $options = ['class' => 'label-danger label-as-badge']; if ($count) { return Html::tag('span', $count, $options); } $options = ['class' => 'label-info label-as-badge']; return Html::tag('span', $count, $options); }
public static function badgeAllCount($modelName) { $count = 0; switch ($modelName) { case 'Order': $count = Order::find()->count(); break; case 'Call': $count = Call::find()->count(); break; case 'Review': $count = Review::find()->count(); break; default: $count = 0; break; } $options = ['class' => 'badge']; if ($count) { return Html::tag('span', $count, $options); } return Html::tag('span', $count, $options); }
public function actionReviewCreate() { $model = new Review(); $products = Product::find()->where(['top' => Product::STATUS_TOP, 'category_id' => 1])->all(); if ($model->load(Yii::$app->request->post()) && $model->save()) { $model->sendEmail('Новый Отзыв', 'review'); Yii::$app->session->addFlash('success', 'Спасибо за Ваш отзыв! Отзыв проходит модерацию.'); return $this->goHome(); } else { return $this->render('index', ['review' => $model, 'products' => $products]); } }
/** * Finds the Review model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Review the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Review::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }