/** * Creates data provider instance with search query applied * @return ActiveDataProvider */ public function search($params) { $query = Price::find(); if (!\Yii::$app->user->can('administrator')) { $query->forDomain(); } $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['{{price}}.id' => $this->id, '{{price}}.model' => $this->model, '{{price}}.version' => $this->version, '{{price}}.version_code' => $this->version_code, '{{price}}.body_type' => $this->body_type, '{{price}}.price' => $this->price, '{{price}}.status' => $this->status, '{{price}}.created_at' => $this->created_at, '{{price}}.updated_at' => $this->updated_at, '{{price}}.domain_id' => $this->domain_id]); // 'id' => Schema::TYPE_PK, // 'model' => Schema::TYPE_STRING . '(512)', // 'version' => Schema::TYPE_STRING . '(512)', // 'version_code' => Schema::TYPE_STRING . '(512)', // 'body_type' => Schema::TYPE_STRING . '(512)', // 'price' => Schema::TYPE_STRING . '(512)', // 'status' => Schema::TYPE_SMALLINT . ' NOT NULL DEFAULT 0', // 'created_at' => Schema::TYPE_INTEGER, // 'updated_at' => Schema::TYPE_INTEGER, // 'weight' => Schema::TYPE_SMALLINT, // 'locale' => Schema::TYPE_STRING, // 'locale_group_id' => Schema::TYPE_INTEGER, // 'domain_id' => Schema::TYPE_INTEGER, $query->andFilterWhere(['like', '{{model}}.model', $this->model])->andFilterWhere(['like', '{{model}}.version', $this->version])->andFilterWhere(['like', '{{model}}.price', $this->title])->andFilterWhere(['like', '{{model}}.version_code', $this->version_code])->andFilterWhere(['like', '{{model}}.weight', $this->weight])->andFilterWhere(['like', '{{model}}.body_type', $this->body_type]); if (!empty($params['PriceSearch']['cid'])) { $query->onlyCategory($params['PriceSearch']['cid']); } return $dataProvider; }
/** * Deletes an existing Model model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id) { //$this->findModel($id)->delete(); $infoModel = Price::find()->andWhere(['model_id' => $id])->one(); if (null === $infoModel) { $this->findModel($id)->delete(); } else { Yii::$app->session->setFlash('alert', ['body' => \Yii::t('backend', 'Can not delete model #' . $id . '. It used in other table. Delete info page #' . $infoModel->id . ' first.'), 'options' => ['class' => 'alert-error']]); } return $this->redirect(['index']); }
public function afterDelete() { $about = Price::find()->andWhere(['locale_group_id' => $this->locale_group_id, 'domain_id' => Yii::$app->user->identity->domain_id])->one(); if ($about) { $about->delete(); } return parent::afterDelete(); }