/** * Creates a new Supplier model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Supplier(); if ($model->load(Yii::$app->request->post())) { $model->loadDefaultValues(); $model->save(); if ($model->save()) { $ensup = new EntpSupplier(); $ensup->supplier_id = $this->id; $ensup->entrepreneur_id = Yii::$app->user->id; $ensup->link('supplier', $model); } Yii::$app->session->setFlash('success', 'ok'); $searchModel = new EntpSupplierSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); //return $this->redirect(['view', 'id' => $model->id, 'profile_user_id' => $model->profile_user_id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $id = Yii::$app->user->id; $query = EntpSupplier::find(); $query->joinWith(['entrepreneur', 'supplier'])->where('entp_supplier.entrepreneur_user_id=' . $id); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->sort->attributes['name'] = ['asc' => ['supplier.name' => SORT_ASC], 'desc' => ['supplier.name' => SORT_DESC]]; $dataProvider->sort->attributes['address'] = ['asc' => ['supplier.address' => SORT_ASC], 'desc' => ['supplier.address' => SORT_DESC]]; $dataProvider->sort->attributes['telephone'] = ['asc' => ['supplier.telephone' => SORT_ASC], 'desc' => ['supplier.telephone' => SORT_DESC]]; $dataProvider->sort->attributes['district'] = ['asc' => ['supplier.district' => SORT_ASC], 'desc' => ['supplier.district' => SORT_DESC]]; $dataProvider->sort->attributes['state'] = ['asc' => ['supplier.state' => SORT_ASC], 'desc' => ['supplier.state' => SORT_DESC]]; $dataProvider->sort->attributes['created_at'] = ['asc' => ['supplier.created_at' => SORT_ASC], 'desc' => ['supplier.created_at' => SORT_DESC]]; $dataProvider->sort->attributes['updated_at'] = ['asc' => ['supplier.updated_at' => SORT_ASC], 'desc' => ['supplier.updated_at' => SORT_DESC]]; $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['entrepreneur_user_id' => $this->entrepreneur_user_id, 'supplier_id' => $this->supplier_id]); $query->andFilterWhere(['like', 'supplier.name', $this->name])->andFilterWhere(['like', 'supplier.telephone', $this->telephone])->andFilterWhere(['like', 'supplier.district', $this->district])->andFilterWhere(['like', 'supplier.state', $this->state])->andFilterWhere(['like', 'supplier.address', $this->address])->andFilterWhere(['like', 'supplier.created_at', $this->created_at])->andFilterWhere(['like', 'supplier.updated_at', $this->updated_at]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getEntpSuppliers() { return $this->hasMany(EntpSupplier::className(), ['entrepreneur_user_id' => 'user_id']); }
/** * @return \yii\db\ActiveQuery */ public function getEntpSuppliers() { return $this->hasMany(EntpSupplier::className(), ['supplier_id' => 'id']); }
/** * Finds the EntpSupplier model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $entrepreneur_id * @param integer $supplier_id * @return EntpSupplier the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($entrepreneur_user_id, $supplier_id) { if (($model = EntpSupplier::findOne(['entrepreneur_user_id' => $entrepreneur_user_id, 'supplier_id' => $supplier_id])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }