|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Page\Model; |
|
4
|
|
|
|
|
5
|
|
|
use Application\Cache\Keys; |
|
6
|
|
|
use Application\Mvc\Model\Model; |
|
7
|
|
|
use Phalcon\Validation; |
|
8
|
|
|
use Phalcon\Validation\Validator\Uniqueness as UniquenessValidator; |
|
9
|
|
|
use Application\Localization\Transliterator; |
|
10
|
|
|
|
|
11
|
|
|
class Page extends Model |
|
12
|
|
|
{ |
|
13
|
|
|
|
|
14
|
|
|
public function getSource() |
|
15
|
|
|
{ |
|
16
|
|
|
return "page"; |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
private $id; |
|
20
|
|
|
private $slug; |
|
21
|
|
|
private $created_at; |
|
22
|
|
|
private $updated_at; |
|
23
|
|
|
|
|
24
|
|
|
protected $title; // translate |
|
25
|
|
|
protected $text; // translate |
|
26
|
|
|
protected $meta_title; // translate |
|
27
|
|
|
protected $meta_description; // translate |
|
28
|
|
|
protected $meta_keywords; // translate |
|
29
|
|
|
|
|
30
|
|
|
protected $translateModel = 'Page\Model\Translate\PageTranslate'; // translate |
|
31
|
|
|
protected $translateFields = [ |
|
32
|
|
|
'title', |
|
33
|
|
|
'meta_title', |
|
34
|
|
|
'meta_description', |
|
35
|
|
|
'meta_keywords', |
|
36
|
|
|
'text' |
|
37
|
|
|
]; |
|
38
|
|
|
|
|
39
|
|
|
public function initialize() |
|
40
|
|
|
{ |
|
41
|
|
|
$this->hasMany("id", $this->translateModel, "foreign_id"); // translate |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function beforeCreate() |
|
45
|
|
|
{ |
|
46
|
|
|
$this->created_at = date("Y-m-d H:i:s"); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function beforeUpdate() |
|
50
|
|
|
{ |
|
51
|
|
|
$this->updated_at = date("Y-m-d H:i:s"); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function afterUpdate() |
|
55
|
|
|
{ |
|
56
|
|
|
$this->cacheManager->delete([ |
|
|
|
|
|
|
57
|
|
|
Keys::PAGE, |
|
58
|
|
|
$this->slug, |
|
59
|
|
|
self::$lang |
|
60
|
|
|
]); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function updateFields($data) |
|
64
|
|
|
{ |
|
65
|
|
|
if (!$this->getSlug()) { |
|
66
|
|
|
$this->setSlug(Transliterator::slugify($data['title'])); |
|
67
|
|
|
} |
|
68
|
|
|
if (!$this->getMetaTitle()) { |
|
69
|
|
|
$this->setMetaTitle($data['title']); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
View Code Duplication |
public function validation() |
|
74
|
|
|
{ |
|
75
|
|
|
$validator = new Validation(); |
|
76
|
|
|
$validator->add('slug', new UniquenessValidator( |
|
77
|
|
|
[ |
|
78
|
|
|
"model" => $this, |
|
79
|
|
|
"message" => $this->getDi()->get('helper')->translate("Page with slug is already exists") |
|
80
|
|
|
] |
|
81
|
|
|
)); |
|
82
|
|
|
return $this->validate($validator); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
View Code Duplication |
public static function findCachedBySlug($slug) |
|
86
|
|
|
{ |
|
87
|
|
|
$query = "slug = '$slug'"; |
|
88
|
|
|
$key = HOST_HASH . md5("Page::findFirst($query)"); |
|
89
|
|
|
$page = self::findFirst([$query, 'cache' => ['key' => $key, 'lifetime' => 60]]); |
|
90
|
|
|
return $page; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @param mixed $created_at |
|
95
|
|
|
* @return $this |
|
96
|
|
|
*/ |
|
97
|
|
|
public function setCreatedAt($created_at) |
|
98
|
|
|
{ |
|
99
|
|
|
$this->created_at = $created_at; |
|
100
|
|
|
return $this; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @return mixed |
|
105
|
|
|
*/ |
|
106
|
|
|
public function getCreatedAt() |
|
107
|
|
|
{ |
|
108
|
|
|
return $this->created_at; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @param mixed $id |
|
113
|
|
|
* @return $this |
|
114
|
|
|
*/ |
|
115
|
|
|
public function setId($id) |
|
116
|
|
|
{ |
|
117
|
|
|
$this->id = $id; |
|
118
|
|
|
return $this; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @return mixed |
|
123
|
|
|
*/ |
|
124
|
|
|
public function getId() |
|
125
|
|
|
{ |
|
126
|
|
|
return $this->id; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* @param mixed $meta_description |
|
131
|
|
|
* @return $this |
|
132
|
|
|
*/ |
|
133
|
|
|
public function setMetaDescription($meta_description) |
|
134
|
|
|
{ |
|
135
|
|
|
$this->setMLVariable('meta_description', $meta_description); |
|
136
|
|
|
return $this; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* @return mixed |
|
141
|
|
|
*/ |
|
142
|
|
|
public function getMetaDescription() |
|
143
|
|
|
{ |
|
144
|
|
|
return $this->getMLVariable('meta_description'); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* @param mixed $meta_keywords |
|
149
|
|
|
* @return $this |
|
150
|
|
|
*/ |
|
151
|
|
|
public function setMetaKeywords($meta_keywords) |
|
152
|
|
|
{ |
|
153
|
|
|
$this->setMLVariable('meta_keywords', $meta_keywords); |
|
154
|
|
|
return $this; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* @return mixed |
|
159
|
|
|
*/ |
|
160
|
|
|
public function getMetaKeywords() |
|
161
|
|
|
{ |
|
162
|
|
|
return $this->getMLVariable('meta_keywords'); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* @param mixed $meta_title |
|
167
|
|
|
* @return $this |
|
168
|
|
|
*/ |
|
169
|
|
|
public function setMetaTitle($meta_title) |
|
170
|
|
|
{ |
|
171
|
|
|
$this->setMLVariable('meta_title', $meta_title); |
|
172
|
|
|
return $this; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
/** |
|
176
|
|
|
* @return mixed |
|
177
|
|
|
*/ |
|
178
|
|
|
public function getMetaTitle() |
|
179
|
|
|
{ |
|
180
|
|
|
return $this->getMLVariable('meta_title'); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* @param mixed $slug |
|
185
|
|
|
* @return $this |
|
186
|
|
|
*/ |
|
187
|
|
|
public function setSlug($slug) |
|
188
|
|
|
{ |
|
189
|
|
|
$this->slug = $slug; |
|
190
|
|
|
return $this; |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
/** |
|
194
|
|
|
* @return mixed |
|
195
|
|
|
*/ |
|
196
|
|
|
public function getSlug() |
|
197
|
|
|
{ |
|
198
|
|
|
return $this->slug; |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
/** |
|
202
|
|
|
* @param mixed $text |
|
203
|
|
|
* @return $this |
|
204
|
|
|
*/ |
|
205
|
|
|
public function setText($text) |
|
206
|
|
|
{ |
|
207
|
|
|
$this->setMLVariable('text', $text); |
|
208
|
|
|
return $this; |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* @return mixed |
|
213
|
|
|
*/ |
|
214
|
|
|
public function getText() |
|
215
|
|
|
{ |
|
216
|
|
|
return $this->getMLVariable('text'); |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
/** |
|
220
|
|
|
* @param mixed $title |
|
221
|
|
|
* @return $this |
|
222
|
|
|
*/ |
|
223
|
|
|
public function setTitle($title) |
|
224
|
|
|
{ |
|
225
|
|
|
$this->setMLVariable('title', $title); |
|
226
|
|
|
return $this; |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
/** |
|
230
|
|
|
* @return mixed |
|
231
|
|
|
*/ |
|
232
|
|
|
public function getTitle() |
|
233
|
|
|
{ |
|
234
|
|
|
return $this->getMLVariable('title'); |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
/** |
|
238
|
|
|
* @param $updated_at |
|
239
|
|
|
* @return $this |
|
240
|
|
|
*/ |
|
241
|
|
|
public function setUpdatedAt($updated_at) |
|
242
|
|
|
{ |
|
243
|
|
|
$this->updated_at = $updated_at; |
|
244
|
|
|
return $this; |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
/** |
|
248
|
|
|
* @return mixed |
|
249
|
|
|
*/ |
|
250
|
|
|
public function getUpdatedAt() |
|
251
|
|
|
{ |
|
252
|
|
|
return $this->updated_at; |
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
} |
|
256
|
|
|
|
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.