/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Orders::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $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->joinWith('company'); $query->joinWith('affiliate'); //$query->joinWith('fromwhoom'); $query->joinWith('orderStatus'); $query->joinWith('assignedto'); if (Yii::$app->user->identity->user_role_id === 1) { $query->andFilterWhere(array('id' => $this->id, 'inprocess_at' => $this->inprocess_at, 'resolved_at' => $this->resolved_at, 'assignedto_id' => $this->assignedto_id)); } elseif (Yii::$app->user->identity->user_role_id === 2) { $query->andFilterWhere(array('id' => $this->id, 'inprocess_at' => $this->inprocess_at, 'resolved_at' => $this->resolved_at, 'assignedto_id' => Yii::$app->user->identity->getId())); } else { $query->andFilterWhere(array('id' => $this->id, 'inprocess_at' => $this->inprocess_at, 'resolved_at' => $this->resolved_at, 'assignedto_id' => $this->assignedto_id, 'fromwhoom_id' => Yii::$app->user->identity->getId())); } $query->andFilterWhere(['like', 'orders.title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'companies.name', $this->company_id])->andFilterWhere(['like', 'affiliates.name', $this->affiliate_id])->andFilterWhere(['like', 'users.username', $this->assignedto_id])->andFilterWhere(['like', 'order_statuses.title', $this->order_status_id]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getOrders() { return $this->hasMany(Orders::className(), ['order_status_id' => 'id']); }
/** * @return \yii\db\ActiveQuery */ public function getOrders() { return $this->hasMany(Orders::className(), ['affiliate_id' => 'id']); }
/** * @return \yii\db\ActiveQuery */ public function getOrders0() { return $this->hasMany(Orders::className(), ['fromwhoom_id' => 'id']); }
/** * Finds the Orders model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Orders the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Orders::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }