public function actionIndex() { $searchModelConfig = ['defaultOrder' => ['id' => SORT_DESC], 'model' => Review::className(), 'relations' => ['submission.form' => ['name']], 'additionalConditions' => [['parent_id' => 0]]]; $searchModel = new SearchModel($searchModelConfig); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', ['dataProvider' => $dataProvider, 'searchModel' => $searchModel]); }
public function bootstrap($app) { $app->on(Application::EVENT_BEFORE_ACTION, function () use($app) { if ($app->requestedAction->controller instanceof BackendReviewController) { /** * Этот кусок отвечает за добавление пустого submission к отзыву, * когда отзыв создается в админке */ Event::on(Review::className(), ActiveRecord::EVENT_INIT, [ReviewsBehavior::className(), 'handleInit']); BackendEntityEditFormEvent::on(View::className(), BackendReviewController::BACKEND_REVIEW_EDIT_FORM, [$this, 'renderEditForm']); } }); }
/** * Получает отзывы по конкретной инстанции модели * @var $models \app\modules\review\models\Review[] * @return array */ public static function getForObjectModel($object_model_id, $object_id, $formId, $sort = SORT_ASC) { $cacheKey = 'Reviews: ' . (int) $object_model_id . ':' . (int) $formId . ':' . (int) $sort; $models = Yii::$app->cache->get($cacheKey); if (false === $models) { $models = Review::find()->with(['submission' => function ($query) use($formId) { /** @var ActiveQuery $query */ $query->andWhere('spam != :spam', [':spam' => 1]); $query->andWhere(['is_deleted' => 0]); $query->andWhere(['form_id' => $formId]); }])->where(['object_model_id' => $object_model_id, 'object_id' => $object_id, 'status' => self::STATUS_APPROVED])->all(); if (false !== empty($models)) { Yii::$app->cache->set($cacheKey, $models, 86400, new TagDependency(['tags' => [ActiveRecordHelper::getCommonTag(Review::className())]])); } } return $models; }
/** * Получает отзывы по конкретной инстанции модели * @var $models \app\modules\review\models\Review[] * @return array */ public static function getForObjectModel($object_model_id, $object_id, $formId, $sort = SORT_ASC) { $cacheKey = 'Reviews: ' . (int) $object_model_id . ':' . (int) $formId . ':' . (int) $sort; $models = Yii::$app->cache->get($cacheKey); if (false === $models) { $models = Review::find()->with('submission')->where(['object_model_id' => $object_model_id, 'object_id' => $object_id, 'status' => self::STATUS_APPROVED])->all(); if (false !== empty($models)) { Yii::$app->cache->set($cacheKey, $models, 86400, new TagDependency(['tags' => [ActiveRecordHelper::getCommonTag(Review::className())]])); } } return $models; }