/** * 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) { $query = Preventivas::find(); } else { $query = Preventivas::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_preventica' => $this->id_preventica, 'id_equipo' => $this->id_equipo, 'fecha_inicio' => $this->fecha_inicio, 'dias' => $this->dias, 'estado' => $this->estado]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getPreventivas() { return $this->hasMany(Preventivas::className(), ['id_equipo' => 'id_equipo']); }
/** * Finds the Preventivas model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Preventivas the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Preventivas::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }