Usuario.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace app\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "Usuario".
  6. *
  7. * @property int $id
  8. * @property string|null $uid
  9. * @property string $email
  10. * @property string $nombre
  11. * @property string|null $telefono
  12. * @property string|null $facebook
  13. * @property bool|null $facebookVerificado
  14. * @property string|null $instagram
  15. * @property bool|null $instagramVerificado
  16. * @property string|null $twitter
  17. * @property bool|null $twitterVerificado
  18. * @property string|null $genero H: Hombre - M: Mujer
  19. * @property string|null $verificado
  20. * @property string|null $creado
  21. * @property string|null $modificado
  22. * @property string|null $eliminado
  23. *
  24. * @property Dependencia[] $dependencias
  25. * @property Grupo[] $grupos
  26. * @property UsuarioDependencia[] $usuariosDependencias
  27. * @property UsuarioGrupo[] $usuarioGrupos
  28. */
  29. class Usuario extends \yii\db\ActiveRecord {
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public static function tableName() {
  34. return 'Usuario';
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function rules() {
  40. return [
  41. [['email', 'nombre'], 'required'],
  42. [['facebookVerificado', 'instagramVerificado', 'twitterVerificado'], 'boolean'],
  43. [['verificado', 'creado', 'modificado', 'eliminado'], 'safe'],
  44. [['uid', 'genero'], 'string', 'max' => 50],
  45. [['email', 'nombre', 'facebook', 'instagram', 'twitter'], 'string', 'max' => 100],
  46. [['telefono'], 'string', 'max' => 10],
  47. [['uid'], 'unique'],
  48. ];
  49. }
  50. /**
  51. * {@inheritdoc}
  52. */
  53. public function attributeLabels() {
  54. return [
  55. 'id' => 'ID',
  56. 'uid' => 'Uid',
  57. 'email' => 'Email',
  58. 'nombre' => 'Nombre',
  59. 'telefono' => 'Teléfono',
  60. 'facebook' => 'Facebook',
  61. 'facebookVerificado' => 'Facebook Verificado',
  62. 'instagram' => 'Instagram',
  63. 'instagramVerificado' => 'Instagram Verificado',
  64. 'twitter' => 'Twitter',
  65. 'twitterVerificado' => 'Twitter Verificado',
  66. 'genero' => 'Género',
  67. 'verificado' => 'Verificado',
  68. 'creado' => 'Creado',
  69. 'modificado' => 'Modificado',
  70. 'eliminado' => 'Eliminado',
  71. ];
  72. }
  73. /**
  74. * Gets query for [[dependencias]].
  75. *
  76. * @return \yii\db\ActiveQuery
  77. */
  78. public function getDependencias() {
  79. return $this->hasMany(Dependencia::className(), ['id' => 'idDependencia'])->viaTable('UsuarioDependencia', ['idUsuario' => 'id']);
  80. }
  81. /**
  82. * Gets query for [[grupos]].
  83. *
  84. * @return \yii\db\ActiveQuery
  85. */
  86. public function getGrupos() {
  87. return $this->hasMany(Grupo::className(), ['id' => 'idGrupo'])->viaTable('UsuarioGrupo', ['idUsuario' => 'id']);
  88. }
  89. /**
  90. * Gets query for [[usuariosDependencias]].
  91. *
  92. * @return \yii\db\ActiveQuery
  93. */
  94. public function getUsuariosDependencias() {
  95. return $this->hasMany(UsuarioDependencia::className(), ['idUsuario' => 'id']);
  96. }
  97. /**
  98. * Gets query for [[usuariosGrupos]].
  99. *
  100. * @return \yii\db\ActiveQuery
  101. */
  102. public function getUsuariosGrupos() {
  103. return $this->hasMany(UsuarioGrupo::className(), ['idUsuario' => 'id']);
  104. }
  105. public function agregarClave($pwd) {
  106. $this->clave = Yii::$app->getSecurity()->generatePasswordHash($pwd);
  107. }
  108. public function validarClave($pwd) {
  109. return Yii::$app->getSecurity()->validatePassword($pwd, $this->clave);
  110. }
  111. }