Usuario.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 $correo
  10. * @property string $nombre
  11. * @property int|null $idRol
  12. * @property string|null $genero
  13. * @property string|null $facebook
  14. * @property bool|null $facebookVerificado
  15. * @property string|null $twitter
  16. * @property bool|null $twitterVerificado
  17. * @property string|null $instagram
  18. * @property bool|null $instagramVerificado
  19. * @property string|null $creado
  20. * @property string|null $modificado
  21. * @property string|null $eliminado
  22. *
  23. * @property Rol $rol
  24. */
  25. class Usuario extends \yii\db\ActiveRecord {
  26. public const ACTIVO = 1;
  27. public const INACTIVO = 0;
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public static function tableName() {
  32. return 'Usuario';
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function rules() {
  38. return [
  39. [['correo', 'nombre'], 'required'],
  40. [['idRol'], 'default', 'value' => null],
  41. [['idRol'], 'integer'],
  42. [['facebookVerificado', 'twitterVerificado', 'instagramVerificado'], 'boolean'],
  43. [['creado', 'modificado', 'eliminado'], 'safe'],
  44. [['uid'], 'string', 'max' => 50],
  45. [['correo', 'nombre', 'genero', 'facebook', 'twitter', 'instagram'], 'string', 'max' => 100],
  46. [['uid'], 'unique'],
  47. [['idRol'], 'exist', 'skipOnError' => true, 'targetClass' => Rol::className(), 'targetAttribute' => ['idRol' => 'id']],
  48. ];
  49. }
  50. /**
  51. * {@inheritdoc}
  52. */
  53. public function attributeLabels() {
  54. return [
  55. 'id' => 'ID',
  56. 'uid' => 'Uid',
  57. 'correo' => 'Correo',
  58. 'nombre' => 'Nombre',
  59. 'idRol' => 'Id Rol',
  60. 'genero' => 'Genero',
  61. 'facebook' => 'Facebook',
  62. 'facebookVerificado' => 'Facebook Verificado',
  63. 'twitter' => 'Twitter',
  64. 'twitterVerificado' => 'Twitter Verificado',
  65. 'instagram' => 'Instagram',
  66. 'instagramVerificado' => 'Instagram Verificado',
  67. 'creado' => 'Creado',
  68. 'modificado' => 'Modificado',
  69. 'eliminado' => 'Eliminado',
  70. ];
  71. }
  72. public function agregarClave($pwd) {
  73. $this->clave = Yii::$app->getSecurity()->generatePasswordHash($pwd);
  74. }
  75. public function validarClave($pwd) {
  76. return Yii::$app->getSecurity()->validatePassword($pwd, $this->clave);
  77. }
  78. /**
  79. * Gets query for [[rol]].
  80. *
  81. * @return \yii\db\ActiveQuery
  82. */
  83. public function geRol() {
  84. return $this->hasOne(Rol::className(), ['id' => 'idRol']);
  85. }
  86. }