/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { if (Yii::$app->user->identity->rol_id == 2) { # code... $query = Correctivas::find(); } else { $query = Correctivas::find()->joinWith('idEquipo')->where(['id_area' => Yii::$app->user->identity->id_departamento]); } $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->andFilterWhere(['id_correctiva' => $this->id_correctiva, 'id_equipo' => $this->id_equipo, 'fecha_inicio' => $this->fecha_inicio, 'dias' => $this->dias]); $query->andFilterWhere(['like', 'estado', $this->estado])->andFilterWhere(['like', 'diagnostico', $this->diagnostico])->andFilterWhere(['like', 'reparacion', $this->reparacion]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getCorrectivas() { return $this->hasMany(Correctivas::className(), ['id_equipo' => 'id_equipo']); }
/** * Finds the Correctivas model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Correctivas the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Correctivas::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }