1
|
|
|
<?php |
|
|
|
|
2
|
|
|
namespace App\Model\Table; |
|
|
|
|
3
|
|
|
|
4
|
|
|
use Cake\ORM\Query; |
|
|
|
|
5
|
|
|
use Cake\ORM\RulesChecker; |
|
|
|
|
6
|
|
|
use Cake\ORM\Table; |
7
|
|
|
use Cake\Validation\Validator; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Contacts Model |
11
|
|
|
* |
12
|
|
|
* @method \App\Model\Entity\Contact get($primaryKey, $options = []) |
13
|
|
|
* @method \App\Model\Entity\Contact newEntity($data = null, array $options = []) |
14
|
|
|
* @method \App\Model\Entity\Contact[] newEntities(array $data, array $options = []) |
15
|
|
|
* @method \App\Model\Entity\Contact|bool save(\Cake\Datasource\EntityInterface $entity, $options = []) |
16
|
|
|
* @method \App\Model\Entity\Contact patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = []) |
17
|
|
|
* @method \App\Model\Entity\Contact[] patchEntities($entities, array $data, array $options = []) |
18
|
|
|
* @method \App\Model\Entity\Contact findOrCreate($search, callable $callback = null, $options = []) |
19
|
|
|
* |
20
|
|
|
* @mixin \Cake\ORM\Behavior\TimestampBehavior |
21
|
|
|
*/ |
|
|
|
|
22
|
|
|
class ContactsTable extends Table |
23
|
|
|
{ |
|
|
|
|
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Initialize method |
27
|
|
|
* |
28
|
|
|
* @param array $config The configuration for the Table. |
|
|
|
|
29
|
|
|
* @return void |
|
|
|
|
30
|
|
|
*/ |
31
|
|
|
public function initialize(array $config) : void |
|
|
|
|
32
|
|
|
{ |
|
|
|
|
33
|
|
|
parent::initialize($config); |
34
|
|
|
|
35
|
|
|
$this->setTable('contacts'); |
36
|
|
|
$this->setDisplayField('name'); |
37
|
|
|
$this->setPrimaryKey('id'); |
38
|
|
|
|
39
|
|
|
$this->addBehavior('Timestamp'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Default validation rules. |
44
|
|
|
* |
45
|
|
|
* @param \Cake\Validation\Validator $validator Validator instance. |
|
|
|
|
46
|
|
|
* @return \Cake\Validation\Validator |
|
|
|
|
47
|
|
|
*/ |
48
|
|
|
public function validationDefault(Validator $validator) : Validator |
|
|
|
|
49
|
|
|
{ |
|
|
|
|
50
|
|
|
$validator |
51
|
|
|
->integer('id') |
|
|
|
|
52
|
|
|
->allowEmpty('id', 'create'); |
|
|
|
|
53
|
|
|
|
54
|
|
|
$validator |
55
|
|
|
->scalar('name') |
|
|
|
|
56
|
|
|
->maxLength('name', 255) |
|
|
|
|
57
|
|
|
->requirePresence('name', 'create') |
|
|
|
|
58
|
|
|
->notEmpty('name'); |
|
|
|
|
59
|
|
|
|
60
|
|
|
$validator |
61
|
|
|
->scalar('description') |
|
|
|
|
62
|
|
|
->allowEmpty('description'); |
|
|
|
|
63
|
|
|
|
64
|
|
|
$validator |
65
|
|
|
->scalar('phone') |
|
|
|
|
66
|
|
|
->maxLength('phone', 255) |
|
|
|
|
67
|
|
|
->allowEmpty('phone'); |
|
|
|
|
68
|
|
|
|
69
|
|
|
$validator |
70
|
|
|
->scalar('mobile') |
|
|
|
|
71
|
|
|
->maxLength('mobile', 255) |
|
|
|
|
72
|
|
|
->allowEmpty('mobile'); |
|
|
|
|
73
|
|
|
|
74
|
|
|
$validator |
75
|
|
|
->scalar('email_primary') |
|
|
|
|
76
|
|
|
->maxLength('email_primary', 255) |
|
|
|
|
77
|
|
|
->allowEmpty('email_primary'); |
|
|
|
|
78
|
|
|
|
79
|
|
|
$validator |
80
|
|
|
->date('birth_date') |
|
|
|
|
81
|
|
|
->allowEmpty('birth_date'); |
|
|
|
|
82
|
|
|
|
83
|
|
|
$validator |
84
|
|
|
->scalar('surname') |
|
|
|
|
85
|
|
|
->maxLength('surname', 255) |
|
|
|
|
86
|
|
|
->allowEmpty('surname'); |
|
|
|
|
87
|
|
|
|
88
|
|
|
return $validator; |
89
|
|
|
} |
|
|
|
|
90
|
|
|
} |
91
|
|
|
|