Commit 0b7fb0e579f37c66067a05c5350f8d074edd1b95
1 parent
77c30f72
test
Showing
1 changed file
with
122 additions
and
0 deletions
Show diff stats
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +use Phalcon\Validation; | ||
| 4 | +use Phalcon\Mvc\Model\Validator\Email as EmailValidator; | ||
| 5 | + | ||
| 6 | +class Users extends \Phalcon\Mvc\Model | ||
| 7 | +{ | ||
| 8 | + | ||
| 9 | + /** | ||
| 10 | + * | ||
| 11 | + * @var integer | ||
| 12 | + * @Primary | ||
| 13 | + * @Identity | ||
| 14 | + * @Column(type="integer", length=32, nullable=false) | ||
| 15 | + */ | ||
| 16 | + public $id; | ||
| 17 | + | ||
| 18 | + /** | ||
| 19 | + * | ||
| 20 | + * @var string | ||
| 21 | + * @Column(type="string", length=255, nullable=true) | ||
| 22 | + */ | ||
| 23 | + public $name; | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * | ||
| 27 | + * @var string | ||
| 28 | + * @Column(type="string", length=255, nullable=true) | ||
| 29 | + */ | ||
| 30 | + public $pass; | ||
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * | ||
| 34 | + * @var string | ||
| 35 | + * @Column(type="string", length=255, nullable=true) | ||
| 36 | + */ | ||
| 37 | + public $email; | ||
| 38 | + | ||
| 39 | + /** | ||
| 40 | + * | ||
| 41 | + * @var string | ||
| 42 | + * @Column(type="string", length=255, nullable=true) | ||
| 43 | + */ | ||
| 44 | + public $role; | ||
| 45 | + | ||
| 46 | + /** | ||
| 47 | + * | ||
| 48 | + * @var string | ||
| 49 | + * @Column(type="string", nullable=true) | ||
| 50 | + */ | ||
| 51 | + public $created_at; | ||
| 52 | + | ||
| 53 | + /** | ||
| 54 | + * | ||
| 55 | + * @var string | ||
| 56 | + * @Column(type="string", nullable=true) | ||
| 57 | + */ | ||
| 58 | + public $updated_at; | ||
| 59 | + | ||
| 60 | + /** | ||
| 61 | + * Validations and business logic | ||
| 62 | + * | ||
| 63 | + * @return boolean | ||
| 64 | + */ | ||
| 65 | + public function validation() | ||
| 66 | + { | ||
| 67 | + $validator = new Validation(); | ||
| 68 | + | ||
| 69 | + $validator->add( | ||
| 70 | + 'email', | ||
| 71 | + new EmailValidator( | ||
| 72 | + [ | ||
| 73 | + 'model' => $this, | ||
| 74 | + 'message' => 'Please enter a correct email address', | ||
| 75 | + ] | ||
| 76 | + ) | ||
| 77 | + ); | ||
| 78 | + | ||
| 79 | + return $this->validate($validator); | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + /** | ||
| 83 | + * Initialize method for model. | ||
| 84 | + */ | ||
| 85 | + public function initialize() | ||
| 86 | + { | ||
| 87 | + $this->setSchema("public"); | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + /** | ||
| 91 | + * Returns table name mapped in the model. | ||
| 92 | + * | ||
| 93 | + * @return string | ||
| 94 | + */ | ||
| 95 | + public function getSource() | ||
| 96 | + { | ||
| 97 | + return 'users'; | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + /** | ||
| 101 | + * Allows to query a set of records that match the specified conditions | ||
| 102 | + * | ||
| 103 | + * @param mixed $parameters | ||
| 104 | + * @return Users[]|Users | ||
| 105 | + */ | ||
| 106 | + public static function find($parameters = null) | ||
| 107 | + { | ||
| 108 | + return parent::find($parameters); | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + /** | ||
| 112 | + * Allows to query the first record that match the specified conditions | ||
| 113 | + * | ||
| 114 | + * @param mixed $parameters | ||
| 115 | + * @return Users | ||
| 116 | + */ | ||
| 117 | + public static function findFirst($parameters = null) | ||
| 118 | + { | ||
| 119 | + return parent::findFirst($parameters); | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | +} |