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
|
|
|
* Operations Model |
11
|
|
|
* |
12
|
|
|
* @property \Cake\ORM\Association\BelongsTo $Tickets |
13
|
|
|
* |
14
|
|
|
* @method \App\Model\Entity\Operation get($primaryKey, $options = []) |
15
|
|
|
* @method \App\Model\Entity\Operation newEntity($data = null, array $options = []) |
16
|
|
|
* @method \App\Model\Entity\Operation[] newEntities(array $data, array $options = []) |
17
|
|
|
* @method \App\Model\Entity\Operation|bool save(\Cake\Datasource\EntityInterface $entity, $options = []) |
18
|
|
|
* @method \App\Model\Entity\Operation patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = []) |
19
|
|
|
* @method \App\Model\Entity\Operation[] patchEntities($entities, array $data, array $options = []) |
20
|
|
|
* @method \App\Model\Entity\Operation findOrCreate($search, callable $callback = null, $options = []) |
21
|
|
|
* |
22
|
|
|
* @mixin \Cake\ORM\Behavior\TimestampBehavior |
23
|
|
|
*/ |
|
|
|
|
24
|
|
|
class OperationsTable extends Table |
25
|
|
|
{ |
|
|
|
|
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Initialize method |
29
|
|
|
* |
30
|
|
|
* @param array $config The configuration for the Table. |
|
|
|
|
31
|
|
|
* @return void |
|
|
|
|
32
|
|
|
*/ |
33
|
3 |
|
public function initialize(array $config) : void |
|
|
|
|
34
|
|
|
{ |
|
|
|
|
35
|
3 |
|
parent::initialize($config); |
36
|
|
|
|
37
|
3 |
|
$this->setTable('operations'); |
38
|
3 |
|
$this->setDisplayField('id'); |
39
|
3 |
|
$this->setPrimaryKey('id'); |
40
|
|
|
|
41
|
3 |
|
$this->addBehavior('Timestamp'); |
42
|
|
|
|
43
|
3 |
|
$this->belongsTo('Tickets', [ |
44
|
3 |
|
'foreignKey' => 'ticket_id', |
45
|
|
|
'joinType' => 'INNER' |
|
|
|
|
46
|
|
|
]); |
47
|
3 |
|
} |
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
|
|
|
->allowEmptyFor('id', 'create'); |
|
|
|
|
60
|
|
|
|
61
|
|
|
$validator |
62
|
|
|
->dateTime('start') |
|
|
|
|
63
|
|
|
->requirePresence('start', 'create') |
|
|
|
|
64
|
|
|
->notEmpty('start'); |
|
|
|
|
65
|
|
|
|
66
|
|
|
$validator |
67
|
|
|
->dateTime('end') |
|
|
|
|
68
|
|
|
->requirePresence('end', 'create') |
|
|
|
|
69
|
|
|
->notEmpty('end'); |
|
|
|
|
70
|
|
|
|
71
|
|
|
$validator |
72
|
|
|
->allowEmptyString('description', 'create'); |
|
|
|
|
73
|
|
|
|
74
|
|
|
return $validator; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Returns a rules checker object that will be used for validating |
79
|
|
|
* application integrity. |
|
|
|
|
80
|
|
|
* |
81
|
|
|
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified. |
|
|
|
|
82
|
|
|
* @return \Cake\ORM\RulesChecker |
|
|
|
|
83
|
|
|
*/ |
84
|
|
|
public function buildRules(RulesChecker $rules) : RulesChecker |
|
|
|
|
85
|
|
|
{ |
|
|
|
|
86
|
|
|
$rules->add($rules->existsIn(['ticket_id'], 'Tickets')); |
87
|
|
|
|
88
|
|
|
return $rules; |
89
|
|
|
} |
|
|
|
|
90
|
|
|
} |
91
|
|
|
|