/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { //filtrado segun el usuario $direccion = \yii::$app->user->Identity->id_direccion; if (Yii::$app->user->identity->isAdmin()) { $query = BienesNCodigoBien::find(); } else { $query = BienesNCodigoBien::find()->where(['id_direccion' => $direccion]); } $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_codigo' => $this->id_codigo, 'identificacion' => $this->identificacion, 'valor_unidad' => $this->valor_unidad, 'justiprecio' => $this->justiprecio]); $query->andFilterWhere(['like', 'descripcion', $this->descripcion])->andFilterWhere(['like', 'TEXT(ano_adquisicion)', $this->ano_adquisicion])->andFilterWhere(['like', 'ubicacion', $this->ubicacion])->andFilterWhere(['like', 'tipo_adquisicion', $this->tipo_adquisicion])->andFilterWhere(['like', 'n_documento', $this->n_documento]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getIdCodigo() { return $this->hasOne(BienesNCodigoBien::className(), ['id_codigo' => 'id_codigo', 'id_direccion' => 'id_localidad']); }
/** * Finds the BienesNCodigoBien model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id_codigo * @param integer $id_localidad * @return BienesNCodigoBien the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id_codigo) { if (($model = BienesNCodigoBien::findOne(['id_codigo' => $id_codigo])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getBienesNCodigoBiens() { return $this->hasMany(BienesNCodigoBien::className(), ['id_codigo' => 'id_codigo']); }