예제 #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Clientes::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(['id' => $this->id, 'id_provincia' => $this->id_provincia, 'id_pais' => $this->id_pais, 'fecha_registro' => $this->fecha_registro, 'fecha_conexion' => $this->fecha_conexion, 'fecha_modif' => $this->fecha_modif, 'id_estado' => $this->id_estado, 'role' => $this->role]);
     $query->andFilterWhere(['like', 'nombre_usuario', $this->nombre_usuario])->andFilterWhere(['like', 'contrasena', $this->contrasena])->andFilterWhere(['like', 'nombre', $this->nombre])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'estado_civil', $this->estado_civil])->andFilterWhere(['like', 'direccion', $this->direccion])->andFilterWhere(['like', 'numero_oficina', $this->numero_oficina])->andFilterWhere(['like', 'ciudad', $this->ciudad])->andFilterWhere(['like', 'provincia', $this->provincia])->andFilterWhere(['like', 'codigo_postal', $this->codigo_postal])->andFilterWhere(['like', 'numero_casa', $this->numero_casa])->andFilterWhere(['like', 'numero_trabajo', $this->numero_trabajo])->andFilterWhere(['like', 'numero_movil', $this->numero_movil])->andFilterWhere(['like', 'cargo_trabajo', $this->cargo_trabajo])->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])->andFilterWhere(['like', 'auth_key', $this->auth_key]);
     return $dataProvider;
 }
예제 #2
0
 /**
  * @inheritdoc
  */
 public static function findOneCustom($condition, $checkRole = null)
 {
     // FIND ROLE
     $rolePrevious = 0;
     $roleSession = $rolePrevious;
     $roleCookie = $rolePrevious;
     $model = null;
     // SET Role: by MANUALLY. Default: at user requested time
     if (!is_null($checkRole)) {
         $rolePrevious = $checkRole;
         Yii::$app->session->set('user.role', $rolePrevious);
     }
     // Check Role: by PHP session. Default: at every loading page
     if (Yii::$app->session->has('user.role')) {
         $rolePrevious = intval(Yii::$app->session->get('user.role'));
         $roleSession = $rolePrevious;
     } elseif (Yii::$app->getRequest()->getCookies()->has('user_role')) {
         $rolePrevious = intval(Yii::$app->getRequest()->getCookies()->getValue('user_role'));
         $roleCookie = $rolePrevious;
         Yii::$app->session->set('user.role', $rolePrevious);
     }
     // FIND USER BY SELECTED ROLE
     if ($rolePrevious) {
         $user = null;
         if ($rolePrevious >= static::ROLE_ADMIN) {
             $user = Users::findOne($condition);
         } elseif ($rolePrevious >= static::ROLE_CLIENTES) {
             $user = Clientes::findOne($condition);
         }
         if ($user) {
             $model = new Identity();
             $model->data = $user->attributes;
             $model->data['id'] = $user->getPrimaryKey();
             // IF ALREADY LOGGED - RESTORE current user logged in ROLE
             if ($rolePrevious != $model->role) {
                 // UPDATE: Role: PHP Session: at runtime
                 if ($roleSession) {
                     Yii::$app->session->set('user.role', $model->role);
                 }
                 // UPDATE: Role: COOKIE: at runtime
                 if ($roleCookie) {
                     Yii::$app->getResponse()->getCookies()->add(new \yii\web\Cookie(['name' => 'user_role', 'value' => (string) $model->role, 'expire' => time() + 3600 * 24 * 30]));
                 }
             }
         }
     }
     // RETURN a searched user found or null if not
     return $model;
 }
예제 #3
0
 /**
  * Finds the Clientes model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Clientes the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Clientes::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }