Пример #1
0
 /**
  * Check if model has any reviews and if so - generate link to edit them
  *
  * @param string $objectName
  * @param int $modelId
  * @return array
  */
 private function getReviewEditParams($objectName, $modelId)
 {
     $objectId = array_search($objectName, Object::getSelectArray());
     $reviews = Review::getForObjectModel($modelId, $objectId, 1);
     if (!empty($reviews)) {
         return ["label" => Icon::show("pencil") . Yii::t("app", "Edit reviews") . " (" . count($reviews) . ")", "url" => ["/review/backend-review/index", "SearchModel" => ["object_id" => $objectId, "object_model_id" => $modelId]], "target" => "_blank"];
     } else {
         return [];
     }
 }
 /**
  * @inheritdoc
  */
 public function run()
 {
     if (null === ($form = Form::findById($this->formId)) || null === $this->model || null === $this->model->object) {
         throw new InvalidParamException();
     }
     if ($this->registerCanonical === true) {
         $this->getView()->registerLinkTag(['rel' => 'canonical', 'href' => ObjectRule::canonical($this->additionalParams)], 'canonical');
     }
     $formObject = Object::getForClass(Form::className());
     $groups = PropertyGroup::getForModel($formObject->id, $form->id);
     $models = Review::getForObjectModel($this->model->id, $this->model->object->id, $form->id);
     $review = new Review(['scenario' => 'check']);
     $review->useCaptcha = $this->useCaptcha;
     /** @var $module \app\modules\review\ReviewModule */
     $module = Yii::$app->getModule('review');
     $maxPerPage = $module->maxPerPage;
     $pageSize = $module->pageSize;
     if ($pageSize > $maxPerPage) {
         $pageSize = $maxPerPage;
     }
     $this->additionalParams['review-page'] = Yii::$app->request->get('review-page');
     $this->additionalParams['review-per-page'] = Yii::$app->request->get('review-per-page');
     return $this->render($this->viewFile, ['reviews' => new ArrayDataProvider(['id' => 'review', 'allModels' => $models, 'pagination' => ['pageSize' => $pageSize, 'params' => $this->additionalParams], 'sort' => ['attributes' => ['submission_id'], 'defaultOrder' => ['submission_id' => $this->sort]]]), 'objectModel' => $this->model, 'model' => $form, 'review' => $review, 'groups' => $groups, 'ratingGroupName' => $this->ratingGroupName, 'useCaptcha' => $this->useCaptcha, 'additionalParams' => $this->additionalParams]);
 }