These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 | public function countByCategoryAndLanguage(int $categoryId = null, string $language = null) : ?int |
||
55 | { |
||
56 | return $this |
||
57 | ->query() |
||
58 | ->where( |
||
59 | [ |
||
60 | 'category' => $categoryId, |
||
61 | 'status' => 1 |
||
62 | ]) |
||
63 | ->whereLanguageIs($language) |
||
64 | ->count() ? : null; |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * get the articles by category and language and order |
||
69 | * |
||
70 | * @since 4.0.0 |
||
71 | * |
||
72 | * @param int $categoryId identifier of the category |
||
73 | * @param string $language |
||
74 | * @param string $orderColumn |
||
75 | * |
||
76 | * @return object|null |
||
77 | */ |
||
78 | |||
79 | public function getByCategoryAndLanguageAndOrder(int $categoryId = null, string $language = null, string $orderColumn = null) : ?object |
||
80 | { |
||
81 | $categoryModel = new Category(); |
||
82 | return $this |
||
83 | ->query() |
||
84 | ->whereIn('category', $categoryModel->getIdArrayBySibling($categoryId)) |
||
85 | ->where('status', 1) |
||
86 | ->whereLanguageIs($language) |
||
87 | ->orderBySetting($orderColumn) |
||
88 | ->findMany() ? : null; |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * get the articles by category and language and order and step |
||
93 | * |
||
94 | * @since 4.0.0 |
||
95 | * |
||
96 | * @param int $categoryId identifier of the category |
||
97 | * @param string $language |
||
98 | * @param string $orderColumn |
||
99 | * @param int $limitStep |
||
100 | * |
||
101 | * @return object|null |
||
102 | */ |
||
103 | |||
104 | public function getByCategoryAndLanguageAndOrderAndStep(int $categoryId = null, string $language = null, string $orderColumn = null, int $limitStep = null) : ?object |
||
105 | { |
||
106 | $categoryModel = new Category(); |
||
107 | return $this |
||
108 | ->query() |
||
109 | ->whereIn('category', $categoryModel->getIdArrayBySibling($categoryId)) |
||
110 | ->where('status', 1) |
||
111 | ->whereLanguageIs($language) |
||
112 | ->orderBySetting($orderColumn) |
||
113 | ->limitBySetting($limitStep) |
||
114 | ->findMany() ? : null; |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * get the article route by id |
||
119 | * |
||
120 | * @since 3.3.0 |
||
121 | * |
||
122 | * @param int $articleId identifier of the article |
||
123 | * |
||
124 | * @return string|null |
||
125 | */ |
||
126 | |||
127 | public function getRouteById(int $articleId = null) : ?string |
||
128 | { |
||
129 | if ($articleId) |
||
0 ignored issues
–
show
|
|||
130 | { |
||
131 | 4 | $routeArray = $this |
|
132 | ->query() |
||
133 | 4 | ->tableAlias('article') |
|
134 | ->leftJoinPrefix('categories', 'article.category = category.id', 'category') |
||
135 | ->leftJoinPrefix('categories', 'category.parent = parent.id', 'parent') |
||
136 | 3 | ->select('parent.alias', 'parentAlias') |
|
137 | 3 | ->select('category.alias', 'categoryAlias') |
|
138 | 3 | ->select('article.alias', 'articleAlias') |
|
139 | 3 | ->where('article.id', $articleId) |
|
140 | 3 | ->findArray(); |
|
141 | 3 | ||
142 | 3 | /* handle route */ |
|
143 | 3 | ||
144 | 3 | if (is_array($routeArray[0])) |
|
145 | { |
||
146 | return implode('/', array_filter($routeArray[0])); |
||
147 | } |
||
148 | 3 | } |
|
149 | return null; |
||
150 | 3 | } |
|
151 | } |
||
152 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
integer
values, zero is a special case, in particular the following results might be unexpected: