public function search($params) { $query = Domicilio::find()->joinWith(['perfil', 'perfil.alumno'])->joinWith('pais')->joinWith('provincia')->joinWith('ciudad')->andWhere(['alumno.id' => $params['alumno_id']]); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->getSort()->attributes = array_merge($dataProvider->getSort()->attributes, ['pais_nombre' => ['asc' => ['pais.nombre' => SORT_ASC], 'desc' => ['pais.nombre' => SORT_DESC], 'label' => Yii::t('app', 'País')], 'provincia_nombre' => ['asc' => ['provincia.nombre' => SORT_ASC], 'desc' => ['provincia.nombre' => SORT_DESC], 'label' => Yii::t('app', 'Provincia')], 'ciudad_nombre' => ['asc' => ['ciudad.nombre' => SORT_ASC], 'desc' => ['ciudad.nombre' => SORT_DESC], 'label' => Yii::t('app', 'Ciudad')]]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'domicilio.principal' => $this->principal]); $query->andFilterWhere(['like', 'direccion', $this->direccion])->andFilterWhere(['like', 'cp', $this->cp])->andFilterWhere(['like', 'pais.nombre', $this->pais_nombre])->andFilterWhere(['like', 'provincia.nombre', $this->provincia_nombre])->andFilterWhere(['like', 'ciudad.nombre', $this->ciudad_nombre]); return $dataProvider; }
/** * */ public function validarDomicilioPrincipalPerfilUnique($attribute, $params) { if ((bool) $this->{$attribute} !== true) { // Si `$principal` no es `true`, no hace falta validar return; } $q = Domicilio::find()->joinWith('perfil')->andWhere(['perfil.id' => $this->perfil->id, 'domicilio.principal' => true]); if ($this->id !== null) { // Se está editando, chequear que no sea el id del objeto actual $q->andWhere('domicilio.id != :domicilio_id', [':domicilio_id' => $this->id]); } if ($q->count() > 0) { $this->addError($attribute, Yii::t('app', $params['mensajeError'])); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Domicilio::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->andFilterWhere(['iddomicilio' => $this->iddomicilio, 'numcasa' => $this->numcasa, 'calle', $this->calle, 'piso' => $this->piso, 'dpto', $this->dpto, 'barrio', $this->barrio, 'depto', $this->depto, 'telefono', $this->telefono, 'idlocalidad' => $this->idlocalidad, 'iddistancia' => $this->iddistancia, 'codpost' => $this->codpost, 'codareaT' => $this->codareaT, 'codareaC' => $this->codareaC, 'celular' => $this->celular, 'convive' => $this->convive]); $query->andFilterWhere(['=', 'idalumno', $this->idalumno]); $dataProvider = new ActiveDataProvider(['query' => $query]); if ($this->idalumno != '') { return $dataProvider; } else { return true; } }
/** * Finds the SedeDomicilio model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $establecimiento_id * @param integer $sede_id * @param integer $id * @return SedeDomicilio the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($establecimiento_id, $sede_id, $id) { $model = Domicilio::find()->joinWith('sede')->where(['sede.establecimiento_id' => $establecimiento_id, 'sede.id' => $sede_id, 'domicilio.id' => $id])->one(); if ($model !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Finds the Domicilio model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $alumno_id * @param integer $id * @return Domicilio the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($alumno_id, $id) { $model = Domicilio::find()->joinWith(['perfil', 'perfil.alumno'])->where(['alumno.id' => $alumno_id, 'domicilio.id' => $id])->one(); if ($model !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }