Usuario.php 3.3 KB

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