1
|
|
|
<?php |
2
|
|
|
namespace Redaxscript\Admin\Model; |
3
|
|
|
|
4
|
|
|
use Redaxscript\Model as BaseModel; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* parent class to provide the admin article model |
8
|
|
|
* |
9
|
|
|
* @since 4.0.0 |
10
|
|
|
* |
11
|
|
|
* @package Redaxscript |
12
|
|
|
* @category Model |
13
|
|
|
* @author Henry Ruhs |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
class Article extends BaseModel\Article |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* is unique by id and alias |
20
|
|
|
* |
21
|
|
|
* @since 4.0.0 |
22
|
|
|
* |
23
|
|
|
* @param int $articleId identifier of the article |
24
|
|
|
* @param string $articleAlias alias of the article |
25
|
|
|
* |
26
|
|
|
* @return bool |
27
|
|
|
*/ |
28
|
|
|
|
29
|
|
|
public function isUniqueByIdAndAlias(int $articleId = null, string $articleAlias = null) : bool |
30
|
|
|
{ |
31
|
|
|
$categoryModel = new Category(); |
32
|
|
|
return !$categoryModel->getByAlias($articleAlias)->id && (!$this->getByAlias($articleAlias)->id || $this->getByAlias($articleAlias)->id === $this->getById($articleId)->id); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* create the article by array |
37
|
|
|
* |
38
|
|
|
* @since 4.0.0 |
39
|
|
|
* |
40
|
|
|
* @param array $createArray array of the create |
41
|
|
|
* |
42
|
|
|
* @return bool |
43
|
|
|
*/ |
44
|
|
|
|
45
|
|
|
public function createByArray(array $createArray = []) : bool |
46
|
|
|
{ |
47
|
|
|
return $this |
48
|
|
|
->query() |
49
|
|
|
->create() |
50
|
|
|
->set($createArray) |
51
|
|
|
->save(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* update the article by id and array |
56
|
|
|
* |
57
|
|
|
* @since 4.0.0 |
58
|
|
|
* |
59
|
|
|
* @param int $articleId identifier of the article |
60
|
|
|
* @param array $updateArray array of the update |
61
|
|
|
* |
62
|
|
|
* @return bool |
63
|
|
|
*/ |
64
|
|
|
|
65
|
|
|
public function updateByIdAndArray(int $articleId = null, array $updateArray = []) : bool |
66
|
|
|
{ |
67
|
|
|
return $this |
68
|
|
|
->query() |
69
|
|
|
->whereIdIs($articleId) |
70
|
|
|
->findOne() |
71
|
|
|
->set($updateArray) |
72
|
|
|
->save(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* publish the article by id |
77
|
|
|
* |
78
|
|
|
* @since 4.0.0 |
79
|
|
|
* |
80
|
|
|
* @param int $articleId identifier of the article |
81
|
|
|
* |
82
|
|
|
* @return bool |
83
|
|
|
*/ |
84
|
|
|
|
85
|
|
|
public function publishById(int $articleId = null) : bool |
86
|
|
|
{ |
87
|
|
|
return (bool)$this |
88
|
|
|
->query() |
89
|
|
|
->whereAnyIs( |
90
|
|
|
[ |
91
|
|
|
[ |
92
|
|
|
'id' => $articleId |
93
|
|
|
], |
94
|
|
|
[ |
95
|
|
|
'sibling' => $articleId |
96
|
|
|
] |
97
|
|
|
]) |
98
|
|
|
->findMany() |
99
|
|
|
->set('status', 1) |
100
|
|
|
->save(); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* publish the article by category |
105
|
|
|
* |
106
|
|
|
* @since 4.0.0 |
107
|
|
|
* |
108
|
|
|
* @param int $categoryId identifier of the category |
109
|
|
|
* |
110
|
|
|
* @return bool |
111
|
|
|
*/ |
112
|
|
|
|
113
|
|
|
public function publishByCategory(int $categoryId = null) : bool |
114
|
|
|
{ |
115
|
|
|
return (bool)$this |
116
|
|
|
->query() |
117
|
|
|
->where('category', $categoryId) |
118
|
|
|
->findMany() |
119
|
|
|
->set('status', 1) |
120
|
|
|
->save(); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* unpublish the article by id |
125
|
|
|
* |
126
|
|
|
* @since 4.0.0 |
127
|
|
|
* |
128
|
|
|
* @param int $articleId identifier of the article |
129
|
|
|
* |
130
|
|
|
* @return bool |
131
|
|
|
*/ |
132
|
|
|
|
133
|
|
|
public function unpublishById(int $articleId = null) : bool |
134
|
|
|
{ |
135
|
|
|
return (bool)$this |
136
|
|
|
->query() |
137
|
|
|
->whereAnyIs( |
138
|
|
|
[ |
139
|
|
|
[ |
140
|
|
|
'id' => $articleId |
141
|
|
|
], |
142
|
|
|
[ |
143
|
|
|
'sibling' => $articleId |
144
|
|
|
] |
145
|
|
|
]) |
146
|
|
|
->findMany() |
147
|
|
|
->set('status', 0) |
148
|
|
|
->save(); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* unpublish the article by category |
153
|
|
|
* |
154
|
|
|
* @since 4.0.0 |
155
|
|
|
* |
156
|
|
|
* @param int $categoryId identifier of the category |
157
|
|
|
* |
158
|
|
|
* @return bool |
159
|
|
|
*/ |
160
|
|
|
|
161
|
|
|
public function unpublishByCategory(int $categoryId = null) : bool |
162
|
|
|
{ |
163
|
|
|
return (bool)$this |
164
|
|
|
->query() |
165
|
|
|
->where('category', $categoryId) |
166
|
|
|
->findMany() |
167
|
|
|
->set('status', 0) |
168
|
|
|
->save(); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* delete the article by id |
173
|
|
|
* |
174
|
|
|
* @since 4.0.0 |
175
|
|
|
* |
176
|
|
|
* @param int $articleId identifier of the article |
177
|
|
|
* |
178
|
|
|
* @return bool |
179
|
|
|
*/ |
180
|
|
|
|
181
|
|
|
public function deleteById(int $articleId = null) : bool |
182
|
|
|
{ |
183
|
|
|
return $this |
184
|
|
|
->query() |
185
|
|
|
->whereAnyIs( |
186
|
|
|
[ |
187
|
|
|
[ |
188
|
|
|
'id' => $articleId |
189
|
|
|
], |
190
|
|
|
[ |
191
|
|
|
'sibling' => $articleId |
192
|
|
|
] |
193
|
|
|
]) |
194
|
|
|
->deleteMany(); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* delete the article by category |
199
|
|
|
* |
200
|
|
|
* @since 4.0.0 |
201
|
|
|
* |
202
|
|
|
* @param int $categoryId identifier of the category |
203
|
|
|
* |
204
|
|
|
* @return bool |
205
|
|
|
*/ |
206
|
|
|
|
207
|
|
|
public function deleteByCategory(int $categoryId = null) : bool |
208
|
|
|
{ |
209
|
|
|
return $this |
210
|
|
|
->query() |
211
|
|
|
->where('category', $categoryId) |
212
|
|
|
->deleteMany(); |
213
|
|
|
} |
214
|
|
|
} |
215
|
|
|
|