/** * Deletes an existing FinanceCategory model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id) { $financeFinance = Finance::find()->andWhere(['category_id' => $id])->one(); if (null === $financeFinance) { $this->findFinance($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 finance #' . $financeFinance->id . ' before delete.'), 'options' => ['class' => 'alert-error']]); } return $this->redirect(['index']); }
/** * Creates data provider instance with search query applied * @return ActiveDataProvider */ public function search($params) { $query = Finance::find(); if (!\Yii::$app->user->can('administrator')) { $query->forDomain(); } $dataProvider = new ActiveDataProvider(['query' => $query]); 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, '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', 'price', $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 Finance 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) { $currentFinance = Finance::getLocaleInstance($key); $currentFinance->locale = $key; if (Yii::$app->request->get('scenario')) { $currentFinance->on_scenario = Yii::$app->request->get('scenario'); } $finances[$key] = $currentFinance; } //set data from default finance if (Yii::$app->request->get('locale_group_id')) { $defaultDomainFinances = Finance::find()->andFilterWhere(['domain_id' => Yii::getAlias('@defaultDomainId'), 'locale_group_id' => Yii::$app->request->get('locale_group_id')])->all(); foreach ($defaultDomainFinances as $key => $value) { if (!in_array($value->locale, array_keys(Yii::$app->params['availableLocales']))) { continue; } $finances[$value->locale]->slug = $value->slug; $finances[$value->locale]->title = $value->title; $finances[$value->locale]->head = $value->head; $finances[$value->locale]->body = $value->body; $finances[$value->locale]->price = $value->price; $finances[$value->locale]->description = $value->description; $finances[$value->locale]->thumbnail = $value->thumbnail; $finances[$value->locale]->before_body = $value->before_body; $finances[$value->locale]->after_body = $value->after_body; } } $finance = new MultiModel(['models' => $finances]); if ($finance->load(Yii::$app->request->post()) && Finance::multiSave($finance)) { return $this->redirect(['index']); } else { switch (Yii::$app->request->get('scenario')) { case 'extend': $viewName = 'extend'; break; default: $viewName = 'create'; } return $this->render($viewName, ['model' => $finance, 'categories' => FinanceCategory::find()->active()->all(), 'domains' => array_combine(explode(',', Yii::getAlias('@frontendUrls')), explode(',', Yii::getAlias('@frontendUrls')))]); } }
public function afterDelete() { $finance = Finance::find()->andWhere(['locale_group_id' => $this->locale_group_id, 'domain_id' => Yii::$app->user->identity->domain_id])->one(); if ($finance) { $finance->delete(); } return parent::afterDelete(); }