1
|
|
|
<?php |
2
|
|
|
namespace App\Model\Table; |
3
|
|
|
|
4
|
|
|
use Cake\ORM\Table; |
5
|
|
|
use Cake\Validation\Validator; |
6
|
|
|
|
7
|
|
|
class ConversationsTable extends Table |
8
|
|
|
{ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Initialize method |
12
|
|
|
* |
13
|
|
|
* @param array $config The configuration for the Table. |
14
|
|
|
* @return void |
15
|
|
|
*/ |
16
|
|
|
public function initialize(array $config) |
17
|
|
|
{ |
18
|
|
|
$this->table('conversations'); |
|
|
|
|
19
|
|
|
$this->displayField('title'); |
|
|
|
|
20
|
|
|
$this->primaryKey('id'); |
|
|
|
|
21
|
|
|
|
22
|
|
|
$this->addBehavior('Timestamp'); |
23
|
|
|
|
24
|
|
|
$this->belongsTo('Users', [ |
25
|
|
|
'foreignKey' => 'user_id' |
26
|
|
|
]); |
27
|
|
|
$this->belongsTo('LastMessage', [ |
28
|
|
|
'className' => 'ConversationsMessages', |
29
|
|
|
'foreignKey' => 'last_message_id' |
30
|
|
|
]); |
31
|
|
|
$this->belongsTo('LastMessageUser', [ |
32
|
|
|
'className' => 'Users', |
33
|
|
|
'foreignKey' => 'last_message_user_id' |
34
|
|
|
]); |
35
|
|
|
$this->hasMany('ConversationsMessages', [ |
36
|
|
|
'foreignKey' => 'conversation_id', |
37
|
|
|
'dependent' => true |
38
|
|
|
]); |
39
|
|
|
$this->hasMany('ConversationsUsers', [ |
40
|
|
|
'className' => 'ConversationsUsers', |
41
|
|
|
'foreignKey' => 'conversation_id', |
42
|
|
|
'dependent' => true |
43
|
|
|
]); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Create validation rules. |
48
|
|
|
* |
49
|
|
|
* @param \Cake\Validation\Validator $validator Validator instance. |
50
|
|
|
* @return \Cake\Validation\Validator |
51
|
|
|
*/ |
52
|
|
View Code Duplication |
public function validationCreate(Validator $validator) |
|
|
|
|
53
|
|
|
{ |
54
|
|
|
$validator |
|
|
|
|
55
|
|
|
->provider('purifier', 'App\Model\Validation\PurifierValidator') |
56
|
|
|
->notEmpty('title', __d('conversations', 'You must specify a title for your conversation.')) |
57
|
|
|
->add('title', 'minLength', [ |
58
|
|
|
'rule' => ['minLength', 5], |
59
|
|
|
'message' => __d('conversations', 'Your title must contain at least {0} characters.', 5) |
60
|
|
|
]) |
61
|
|
|
|
62
|
|
|
->notEmpty('message', __d('conversations', 'You must specify a message for your conversation.')) |
63
|
|
|
->add('message', [ |
64
|
|
|
'purifierMinLength' => [ |
65
|
|
|
'rule' => ['purifierMinLength', 5], |
66
|
|
|
'provider' => 'purifier', |
67
|
|
|
'message' => __d('conversations', 'Your message must contain at least {0} characters.', 5) |
68
|
|
|
] |
69
|
|
|
]); |
70
|
|
|
|
71
|
|
|
return $validator; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Edit validation rules. |
76
|
|
|
* |
77
|
|
|
* @param \Cake\Validation\Validator $validator Validator instance. |
78
|
|
|
* @return \Cake\Validation\Validator |
79
|
|
|
*/ |
80
|
|
View Code Duplication |
public function validationEdit(Validator $validator) |
|
|
|
|
81
|
|
|
{ |
82
|
|
|
$validator |
|
|
|
|
83
|
|
|
->provider('purifier', 'App\Model\Validation\PurifierValidator') |
84
|
|
|
->notEmpty('title', __d('conversations', 'You must specify a title for your conversation.')) |
85
|
|
|
->add('title', 'minLength', [ |
86
|
|
|
'rule' => ['minLength', 5], |
87
|
|
|
'message' => __d('conversations', 'Your title must contain at least {0} characters.', 5) |
88
|
|
|
]) |
89
|
|
|
|
90
|
|
|
->notEmpty('message', __d('conversations', 'You must specify a message for your conversation.')) |
91
|
|
|
->add('message', [ |
92
|
|
|
'purifierMinLength' => [ |
93
|
|
|
'rule' => ['purifierMinLength', 5], |
94
|
|
|
'provider' => 'purifier', |
95
|
|
|
'message' => __d('conversations', 'Your message must contain at least {0} characters.', 5) |
96
|
|
|
] |
97
|
|
|
]); |
98
|
|
|
|
99
|
|
|
return $validator; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.