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
|
|
|
* Organizations Model |
11
|
|
|
* |
12
|
|
|
* @property \App\Model\Table\UsersTable|\Cake\ORM\Association\BelongsTo $Users |
13
|
|
|
* |
14
|
|
|
* @method \App\Model\Entity\Organization get($primaryKey, $options = []) |
15
|
|
|
* @method \App\Model\Entity\Organization newEntity($data = null, array $options = []) |
16
|
|
|
* @method \App\Model\Entity\Organization[] newEntities(array $data, array $options = []) |
17
|
|
|
* @method \App\Model\Entity\Organization|bool save(\Cake\Datasource\EntityInterface $entity, $options = []) |
18
|
|
|
* @method \App\Model\Entity\Organization patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = []) |
19
|
|
|
* @method \App\Model\Entity\Organization[] patchEntities($entities, array $data, array $options = []) |
20
|
|
|
* @method \App\Model\Entity\Organization findOrCreate($search, callable $callback = null, $options = []) |
21
|
|
|
* |
22
|
|
|
* @mixin \Cake\ORM\Behavior\TimestampBehavior |
23
|
|
|
*/ |
|
|
|
|
24
|
|
|
class OrganizationsTable extends Table |
25
|
|
|
{ |
|
|
|
|
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Initialize method |
29
|
|
|
* |
30
|
|
|
* @param array $config The configuration for the Table. |
|
|
|
|
31
|
|
|
* @return void |
|
|
|
|
32
|
|
|
*/ |
33
|
|
|
public function initialize(array $config) : void |
|
|
|
|
34
|
|
|
{ |
|
|
|
|
35
|
|
|
parent::initialize($config); |
36
|
|
|
|
37
|
|
|
$this->setTable('organizations'); |
38
|
|
|
$this->setDisplayField('name'); |
39
|
|
|
$this->setPrimaryKey('id'); |
40
|
|
|
|
41
|
|
|
$this->addBehavior('Timestamp'); |
42
|
|
|
|
43
|
|
|
$this->belongsTo('Users', [ |
44
|
|
|
'foreignKey' => 'user_id', |
45
|
|
|
'joinType' => 'INNER' |
|
|
|
|
46
|
|
|
]); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Default validation rules. |
51
|
|
|
* |
52
|
|
|
* @param \Cake\Validation\Validator $validator Validator instance. |
|
|
|
|
53
|
|
|
* @return \Cake\Validation\Validator |
|
|
|
|
54
|
|
|
*/ |
55
|
|
|
public function validationDefault(Validator $validator) : Validator |
|
|
|
|
56
|
|
|
{ |
|
|
|
|
57
|
|
|
$validator |
58
|
|
|
->integer('id') |
|
|
|
|
59
|
|
|
->allowEmpty('id', 'create'); |
|
|
|
|
60
|
|
|
|
61
|
|
|
$validator |
62
|
|
|
->scalar('name') |
|
|
|
|
63
|
|
|
->maxLength('name', 255) |
|
|
|
|
64
|
|
|
->requirePresence('name', 'create') |
|
|
|
|
65
|
|
|
->notEmpty('name'); |
|
|
|
|
66
|
|
|
|
67
|
|
|
return $validator; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Returns a rules checker object that will be used for validating |
72
|
|
|
* application integrity. |
|
|
|
|
73
|
|
|
* |
74
|
|
|
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified. |
|
|
|
|
75
|
|
|
* @return \Cake\ORM\RulesChecker |
|
|
|
|
76
|
|
|
*/ |
77
|
|
|
public function buildRules(RulesChecker $rules) : RulesChecker |
|
|
|
|
78
|
|
|
{ |
|
|
|
|
79
|
|
|
$rules->add($rules->existsIn(['user_id'], 'Users')); |
80
|
|
|
|
81
|
|
|
return $rules; |
82
|
|
|
} |
|
|
|
|
83
|
|
|
} |
84
|
|
|
|