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 category model |
||
10 | * |
||
11 | * @since 3.3.0 |
||
12 | * |
||
13 | * @package Redaxscript |
||
14 | * @category Model |
||
15 | * @author Henry Ruhs |
||
16 | */ |
||
17 | |||
18 | class Category extends ContentAbstract |
||
19 | { |
||
20 | /** |
||
21 | * name of the table |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | |||
26 | protected $_table = 'categories'; |
||
27 | |||
28 | /** |
||
29 | * get the category by alias |
||
30 | * |
||
31 | * @since 4.0.0 |
||
32 | * |
||
33 | * @param string $categoryAlias alias of the category |
||
34 | * |
||
35 | * @return object|null |
||
36 | */ |
||
37 | |||
38 | 2 | public function getByAlias(string $categoryAlias = null) : ?object |
|
39 | { |
||
40 | 2 | $category = $this->query()->where('alias', $categoryAlias)->findOne(); |
|
41 | 2 | return $category ? : null; |
|
42 | } |
||
43 | |||
44 | /** |
||
45 | * get the category route by id |
||
46 | * |
||
47 | * @since 3.3.0 |
||
48 | * |
||
49 | * @param int $categoryId identifier of the category |
||
50 | * |
||
51 | * @return string|null |
||
52 | */ |
||
53 | |||
54 | 3 | public function getRouteById(int $categoryId = null) : ?string |
|
55 | { |
||
56 | 3 | if ($categoryId) |
|
0 ignored issues
–
show
|
|||
57 | { |
||
58 | $routeArray = $this |
||
59 | 2 | ->query() |
|
60 | 2 | ->tableAlias('category') |
|
61 | 2 | ->leftJoinPrefix('categories', 'category.parent = parent.id', 'parent') |
|
62 | 2 | ->select('parent.alias', 'parentAlias') |
|
63 | 2 | ->select('category.alias', 'categoryAlias') |
|
64 | 2 | ->where('category.id', $categoryId) |
|
65 | 2 | ->findArray(); |
|
66 | |||
67 | /* handle route */ |
||
68 | |||
69 | 2 | if (is_array($routeArray[0])) |
|
70 | { |
||
71 | 2 | return implode('/', array_filter($routeArray[0])); |
|
72 | } |
||
73 | } |
||
74 | 1 | return null; |
|
75 | } |
||
76 | } |
||
77 |
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: