/**
  * Deletes an existing FinancePageCategory model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $financePageModel = FinancePage::find()->andWhere(['category_id' => $id])->one();
     if (null === $financePageModel) {
         $this->findModel($id)->delete();
     } else {
         Yii::$app->session->setFlash('alert', ['body' => \Yii::t('backend', 'Can not delete category #' . $id . '. It used in other table. Change category for financePage #' . $financePageModel->id . ' before delete.'), 'options' => ['class' => 'alert-error']]);
     }
     return $this->redirect(['index']);
 }
Example #2
0
 /**
  * Creates data provider instance with search query applied
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = FinancePage::find();
     if (!\Yii::$app->user->can('administrator')) {
         $query->forDomain();
     }
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!empty($params['mid'])) {
         $query->andFilterWhere(['finance_id' => intval($params['mid'])]);
     }
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'slug' => $this->slug, 'author_id' => $this->author_id, 'category_id' => $this->category_id, 'finance_id' => $this->finance_id, 'updater_id' => $this->updater_id, 'status' => $this->status, 'published_at' => $this->published_at, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'domain_id' => $this->domain_id]);
     $query->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'weight', $this->weight])->andFilterWhere(['like', 'body', $this->body])->andFilterWhere(['like', 'before_body', $this->before_body])->andFilterWhere(['like', 'after_body', $this->after_body])->andFilterWhere(['like', 'on_scenario', $this->on_scenario]);
     return $dataProvider;
 }
 /**
  * Creates a new FinancePage model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     foreach (Yii::$app->params['availableLocales'] as $key => $value) {
         $currentModel = FinancePage::getLocaleInstance($key);
         $currentModel->locale = $key;
         if (Yii::$app->request->get('scenario')) {
             $currentModel->on_scenario = Yii::$app->request->get('scenario');
         }
         $models[$key] = $currentModel;
     }
     //set data from default model
     if (Yii::$app->request->get('locale_group_id')) {
         $defaultDomainModels = FinancePage::find()->andFilterWhere(['domain_id' => Yii::getAlias('@defaultDomainId'), 'locale_group_id' => Yii::$app->request->get('locale_group_id')])->all();
         foreach ($defaultDomainModels as $key => $value) {
             if (!in_array($value->locale, array_keys(Yii::$app->params['availableLocales']))) {
                 continue;
             }
             $models[$value->locale]->slug = $value->slug;
             $models[$value->locale]->title = $value->title;
             $models[$value->locale]->head = $value->head;
             $models[$value->locale]->body = $value->body;
             $models[$value->locale]->description = $value->description;
             $models[$value->locale]->before_body = $value->before_body;
             $models[$value->locale]->after_body = $value->after_body;
         }
     }
     $model = new MultiModel(['models' => $models]);
     if ($model->load(Yii::$app->request->post()) && FinancePage::multiSave($model)) {
         return $this->redirect(['index', 'mid' => $model->getModel(Yii::$app->language)->finance_id]);
     } else {
         switch (Yii::$app->request->get('scenario')) {
             case 'extend':
                 $viewName = 'extend';
                 break;
             default:
                 $viewName = 'create';
         }
         return $this->render($viewName, ['model' => $model, 'categories' => FinancePageCategory::find()->active()->all(), 'domains' => array_combine(explode(',', Yii::getAlias('@frontendUrls')), explode(',', Yii::getAlias('@frontendUrls')))]);
     }
 }
Example #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getFirstFinancePage()
 {
     return FinancePage::find()->firstFinancePage($this->id);
     //return $this->hasOne(FinanceCategory::className(), ['id' => 'category_id']);
 }
Example #5
0
 public function afterDelete()
 {
     $model = FinancePage::find()->andWhere(['locale_group_id' => $this->locale_group_id, 'domain_id' => Yii::$app->user->identity->domain_id])->one();
     if ($model) {
         $model->delete();
     }
     return parent::afterDelete();
 }
Example #6
0
 /**
  * Deletes an existing Finance model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     //$this->findFinance($id)->delete();
     $financePageFinance = FinancePage::find()->andWhere(['finance_id' => $id])->one();
     if (null === $financePageFinance) {
         $this->findFinance($id)->delete();
     } else {
         Yii::$app->session->setFlash('alert', ['body' => \Yii::t('backend', 'Can not delete finance #' . $id . '. It used in other table. Delete financePage page #' . $financePageFinance->id . ' first.'), 'options' => ['class' => 'alert-error']]);
     }
     return $this->redirect(['index']);
 }