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
|
|
|
* Useroptions Model |
11
|
|
|
* |
12
|
|
|
* @property \Cake\ORM\Association\BelongsTo $Users |
13
|
|
|
* |
14
|
|
|
* @method \App\Model\Entity\Useroption get($primaryKey, $options = []) |
15
|
|
|
* @method \App\Model\Entity\Useroption newEntity($data = null, array $options = []) |
16
|
|
|
* @method \App\Model\Entity\Useroption[] newEntities(array $data, array $options = []) |
17
|
|
|
* @method \App\Model\Entity\Useroption|bool save(\Cake\Datasource\EntityInterface $entity, $options = []) |
18
|
|
|
* @method \App\Model\Entity\Useroption patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = []) |
19
|
|
|
* @method \App\Model\Entity\Useroption[] patchEntities($entities, array $data, array $options = []) |
20
|
|
|
* @method \App\Model\Entity\Useroption findOrCreate($search, callable $callback = null, $options = []) |
21
|
|
|
* |
22
|
|
|
* @mixin \Cake\ORM\Behavior\TimestampBehavior |
23
|
|
|
*/ |
|
|
|
|
24
|
|
|
class UseroptionsTable 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('useroptions'); |
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
|
|
|
->requirePresence('name', 'create') |
|
|
|
|
63
|
|
|
->notEmpty('name'); |
|
|
|
|
64
|
|
|
|
65
|
|
|
$validator |
66
|
|
|
->requirePresence('value', 'create') |
|
|
|
|
67
|
|
|
->notEmpty('value'); |
|
|
|
|
68
|
|
|
|
69
|
|
|
return $validator; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Returns a rules checker object that will be used for validating |
74
|
|
|
* application integrity. |
|
|
|
|
75
|
|
|
* |
76
|
|
|
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified. |
|
|
|
|
77
|
|
|
* @return \Cake\ORM\RulesChecker |
|
|
|
|
78
|
|
|
*/ |
79
|
|
|
public function buildRules(RulesChecker $rules) : RulesChecker |
|
|
|
|
80
|
|
|
{ |
|
|
|
|
81
|
|
|
$rules->add($rules->existsIn(['user_id'], 'Users')); |
82
|
|
|
|
83
|
|
|
return $rules; |
84
|
|
|
} |
|
|
|
|
85
|
|
|
} |
86
|
|
|
|