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 | /** |
||
5 | * parent class to provide the content model |
||
6 | * |
||
7 | * @since 3.3.0 |
||
8 | * |
||
9 | * @package Redaxscript |
||
10 | * @category Model |
||
11 | * @author Henry Ruhs |
||
12 | */ |
||
13 | |||
14 | class Content |
||
15 | { |
||
16 | /** |
||
17 | * get the content table by alias |
||
18 | * |
||
19 | * @since 3.3.0 |
||
20 | * |
||
21 | * @param string $contentAlias alias of the content |
||
22 | * |
||
23 | * @return string|null |
||
24 | */ |
||
25 | |||
26 | public function getTableByAlias(string $contentAlias = null) : ?string |
||
27 | { |
||
28 | if ($contentAlias) |
||
0 ignored issues
–
show
|
|||
29 | { |
||
30 | $categoryModel = new Category(); |
||
31 | if ($categoryModel->getByAlias($contentAlias)->id) |
||
32 | { |
||
33 | return 'categories'; |
||
34 | } |
||
35 | $articleModel = new Article(); |
||
36 | if ($articleModel->getByAlias($contentAlias)->id) |
||
37 | { |
||
38 | return 'articles'; |
||
39 | } |
||
40 | } |
||
41 | return null; |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * get the content by table and id |
||
46 | * |
||
47 | * @since 4.0.0 |
||
48 | * |
||
49 | * @param string $table name of the table |
||
50 | * @param int $contentId identifier of the content |
||
51 | * |
||
52 | * @return object|null |
||
53 | */ |
||
54 | |||
55 | public function getByTableAndId(string $table = null, int $contentId = null) : ?object |
||
56 | { |
||
57 | if ($contentId) |
||
58 | { |
||
59 | if ($table === 'categories') |
||
60 | { |
||
61 | $categoryModel = new Category(); |
||
62 | return $categoryModel->getById($contentId); |
||
63 | } |
||
64 | if ($table === 'articles') |
||
65 | { |
||
66 | $articleModel = new Article(); |
||
67 | return $articleModel->getById($contentId); |
||
68 | } |
||
69 | } |
||
70 | return null; |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * get the content route by table and id |
||
75 | * |
||
76 | * @since 3.3.0 |
||
77 | * |
||
78 | * @param string $table name of the table |
||
79 | * @param int $contentId identifier of the content |
||
80 | * |
||
81 | * @return string|null |
||
82 | */ |
||
83 | |||
84 | public function getRouteByTableAndId(string $table = null, int $contentId = null) : ?string |
||
85 | { |
||
86 | if ($contentId) |
||
87 | { |
||
88 | if ($table === 'categories') |
||
89 | { |
||
90 | $categoryModel = new Category(); |
||
91 | return $categoryModel->getRouteById($contentId); |
||
92 | } |
||
93 | if ($table === 'articles') |
||
94 | { |
||
95 | $articleModel = new Article(); |
||
96 | return $articleModel->getRouteById($contentId); |
||
97 | } |
||
98 | if ($table === 'comments') |
||
99 | { |
||
100 | $commentModel = new Comment(); |
||
101 | return $commentModel->getRouteById($contentId); |
||
102 | } |
||
103 | } |
||
104 | return null; |
||
105 | } |
||
106 | } |
||
107 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: