|
1
|
|
|
<?php |
|
2
|
|
|
namespace Redaxscript\Model; |
|
3
|
|
|
|
|
4
|
|
|
use function array_filter; |
|
5
|
|
|
use function implode; |
|
6
|
|
|
use function is_array; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* parent class to provide the article model |
|
10
|
|
|
* |
|
11
|
|
|
* @since 3.3.0 |
|
12
|
|
|
* |
|
13
|
|
|
* @package Redaxscript |
|
14
|
|
|
* @category Model |
|
15
|
|
|
* @author Henry Ruhs |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
class Article extends ContentAbstract |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* name of the table |
|
22
|
|
|
* |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
protected $_table = 'articles'; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* get the article by alias |
|
30
|
|
|
* |
|
31
|
|
|
* @since 4.0.0 |
|
32
|
|
|
* |
|
33
|
|
|
* @param string $articleAlias alias of the article |
|
34
|
|
|
* |
|
35
|
|
|
* @return object|null |
|
36
|
|
|
*/ |
|
37
|
|
|
|
|
38
|
2 |
|
public function getByAlias(string $articleAlias = null) : ?object |
|
39
|
|
|
{ |
|
40
|
2 |
|
return $this->query()->where('alias', $articleAlias)->findOne() ? : null; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* count the articles by category and language |
|
45
|
|
|
* |
|
46
|
|
|
* @since 4.0.0 |
|
47
|
|
|
* |
|
48
|
|
|
* @param int $categoryId identifier of the category |
|
49
|
|
|
* @param string $language |
|
50
|
|
|
* |
|
51
|
|
|
* @return int|null |
|
52
|
|
|
*/ |
|
53
|
|
|
|
|
54
|
3 |
|
public function countByCategoryAndLanguage(int $categoryId = null, string $language = null) : ?int |
|
55
|
|
|
{ |
|
56
|
|
|
return $this |
|
57
|
3 |
|
->query() |
|
58
|
3 |
|
->where( |
|
59
|
|
|
[ |
|
60
|
3 |
|
'category' => $categoryId, |
|
61
|
3 |
|
'status' => 1 |
|
62
|
|
|
]) |
|
63
|
3 |
|
->whereLanguageIs($language) |
|
64
|
3 |
|
->count() ? : null; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* get the siblings by category and language and order and step |
|
69
|
|
|
* |
|
70
|
|
|
* @since 4.0.0 |
|
71
|
|
|
* |
|
72
|
|
|
* @param int $categoryId identifier of the category |
|
73
|
|
|
* @param string $language |
|
74
|
|
|
* @param string $orderColumn |
|
75
|
|
|
* @param int $limitStep |
|
76
|
|
|
* |
|
77
|
|
|
* @return object|null |
|
78
|
|
|
*/ |
|
79
|
|
|
|
|
80
|
5 |
|
public function getSiblingByCategoryAndLanguageAndOrderAndStep(int $categoryId = null, string $language = null, string $orderColumn = 'rank', int $limitStep = null) : ?object |
|
81
|
|
|
{ |
|
82
|
5 |
|
$categoryModel = new Category(); |
|
83
|
|
|
$query = $this |
|
84
|
5 |
|
->query() |
|
85
|
5 |
|
->whereIn('category', $categoryModel->getSiblingArrayById($categoryId)) |
|
86
|
5 |
|
->where('status', 1) |
|
87
|
5 |
|
->whereLanguageIs($language) |
|
88
|
5 |
|
->orderBySetting($orderColumn); |
|
89
|
5 |
|
if ($limitStep) |
|
|
|
|
|
|
90
|
|
|
{ |
|
91
|
1 |
|
$query->limitBySetting($limitStep); |
|
92
|
|
|
} |
|
93
|
5 |
|
return $query->findMany() ? : null; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* get the article route by id |
|
98
|
|
|
* |
|
99
|
|
|
* @since 3.3.0 |
|
100
|
|
|
* |
|
101
|
|
|
* @param int $articleId identifier of the article |
|
102
|
|
|
* |
|
103
|
|
|
* @return string|null |
|
104
|
|
|
*/ |
|
105
|
|
|
|
|
106
|
6 |
|
public function getRouteById(int $articleId = null) : ?string |
|
107
|
|
|
{ |
|
108
|
6 |
|
if ($articleId) |
|
|
|
|
|
|
109
|
|
|
{ |
|
110
|
|
|
$routeArray = $this |
|
111
|
5 |
|
->query() |
|
112
|
5 |
|
->tableAlias('article') |
|
113
|
5 |
|
->leftJoinPrefix('categories', 'article.category = category.id', 'category') |
|
114
|
5 |
|
->leftJoinPrefix('categories', 'category.parent = parent.id', 'parent') |
|
115
|
5 |
|
->select('parent.alias', 'parentAlias') |
|
116
|
5 |
|
->select('category.alias', 'categoryAlias') |
|
117
|
5 |
|
->select('article.alias', 'articleAlias') |
|
118
|
5 |
|
->where('article.id', $articleId) |
|
119
|
5 |
|
->findArray(); |
|
120
|
|
|
|
|
121
|
|
|
/* handle route */ |
|
122
|
|
|
|
|
123
|
5 |
|
if (is_array($routeArray[0])) |
|
124
|
|
|
{ |
|
125
|
5 |
|
return implode('/', array_filter($routeArray[0])); |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
1 |
|
return null; |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: