@@ -12,9 +12,13 @@ |
||
12 | 12 | |
13 | 13 | public static function get(string $table) { |
14 | 14 | |
15 | - if (!isset(static::$classes[$table])) throw new Exception\General(static::$error_message); |
|
15 | + if (!isset(static::$classes[$table])) { |
|
16 | + throw new Exception\General(static::$error_message); |
|
17 | + } |
|
16 | 18 | |
17 | - if (isset(static::$cache[$table])) return static::$cache[$table]; |
|
19 | + if (isset(static::$cache[$table])) { |
|
20 | + return static::$cache[$table]; |
|
21 | + } |
|
18 | 22 | |
19 | 23 | # ------------------------ |
20 | 24 |
@@ -12,13 +12,13 @@ discard block |
||
12 | 12 | |
13 | 13 | return ("SELECT SQL_CALC_FOUND_ROWS " . $this->getSelection() . " ") . |
14 | 14 | |
15 | - ("FROM " . static::$table . " ent ") . |
|
15 | + ("FROM " . static::$table . " ent ") . |
|
16 | 16 | |
17 | 17 | (('' !== ($condition = $this->getCondition($config))) ? ("WHERE " . $condition . " ") : "") . |
18 | 18 | |
19 | 19 | ("ORDER BY " . $this->getOrderBy($order_by) . " ") . |
20 | 20 | |
21 | - (($index > 0) ? ("LIMIT " . ((($index - 1) * $display) . ", " . $display)) : ""); |
|
21 | + (($index > 0) ? ("LIMIT " . ((($index - 1) * $display) . ", " . $display)) : ""); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | # Get nesting select query |
@@ -27,9 +27,9 @@ discard block |
||
27 | 27 | |
28 | 28 | return ("SELECT SQL_CALC_FOUND_ROWS " . $this->getSelection() . ", COUNT(chd.descendant) as children ") . |
29 | 29 | |
30 | - ("FROM " . static::$table . " ent ") . |
|
30 | + ("FROM " . static::$table . " ent ") . |
|
31 | 31 | |
32 | - ("LEFT JOIN " . static::$table_relations . " chd ON chd.ancestor = ent.id AND chd.depth = 1 ") . |
|
32 | + ("LEFT JOIN " . static::$table_relations . " chd ON chd.ancestor = ent.id AND chd.depth = 1 ") . |
|
33 | 33 | |
34 | 34 | ("LEFT JOIN " . static::$table_relations . " rel ON rel.descendant = ent.id AND rel.depth = 1 ") . |
35 | 35 | |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | |
40 | 40 | ("GROUP BY ent.id ORDER BY " . $this->getOrderBy($order_by) . " ") . |
41 | 41 | |
42 | - (($index > 0) ? ("LIMIT " . ((($index - 1) * $display) . ", " . $display)) : ""); |
|
42 | + (($index > 0) ? ("LIMIT " . ((($index - 1) * $display) . ", " . $display)) : ""); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | # Get default count query |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | |
49 | 49 | return ("SELECT COUNT(ent.id) as count FROM " . static::$table . " ent ") . |
50 | 50 | |
51 | - (('' !== ($condition = $this->getCondition($config))) ? ("WHERE " . $condition) : ""); |
|
51 | + (('' !== ($condition = $this->getCondition($config))) ? ("WHERE " . $condition) : ""); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | # Get nesting count query |
@@ -57,11 +57,11 @@ discard block |
||
57 | 57 | |
58 | 58 | return ("SELECT COUNT(ent.id) as count FROM " . static::$table . " ent ") . |
59 | 59 | |
60 | - ("LEFT JOIN " . static::$table_relations . " rel ON rel.descendant = ent.id AND rel.depth = 1 ") . |
|
60 | + ("LEFT JOIN " . static::$table_relations . " rel ON rel.descendant = ent.id AND rel.depth = 1 ") . |
|
61 | 61 | |
62 | - ("WHERE COALESCE(rel.ancestor, 0) = " . $parent_id . " ") . |
|
62 | + ("WHERE COALESCE(rel.ancestor, 0) = " . $parent_id . " ") . |
|
63 | 63 | |
64 | - (('' !== ($condition = $this->getCondition($config))) ? ("AND " . $condition) : ""); |
|
64 | + (('' !== ($condition = $this->getCondition($config))) ? ("AND " . $condition) : ""); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | # Select entries from DB |
@@ -10,58 +10,58 @@ discard block |
||
10 | 10 | |
11 | 11 | private function getDefaultSelectQuery(array $config, array $order_by, int $index, int $display) { |
12 | 12 | |
13 | - return ("SELECT SQL_CALC_FOUND_ROWS " . $this->getSelection() . " ") . |
|
13 | + return ("SELECT SQL_CALC_FOUND_ROWS ".$this->getSelection()." "). |
|
14 | 14 | |
15 | - ("FROM " . static::$table . " ent ") . |
|
15 | + ("FROM ".static::$table." ent "). |
|
16 | 16 | |
17 | - (('' !== ($condition = $this->getCondition($config))) ? ("WHERE " . $condition . " ") : "") . |
|
17 | + (('' !== ($condition = $this->getCondition($config))) ? ("WHERE ".$condition." ") : ""). |
|
18 | 18 | |
19 | - ("ORDER BY " . $this->getOrderBy($order_by) . " ") . |
|
19 | + ("ORDER BY ".$this->getOrderBy($order_by)." "). |
|
20 | 20 | |
21 | - (($index > 0) ? ("LIMIT " . ((($index - 1) * $display) . ", " . $display)) : ""); |
|
21 | + (($index > 0) ? ("LIMIT ".((($index - 1) * $display).", ".$display)) : ""); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | # Get nesting select query |
25 | 25 | |
26 | 26 | private function getNestingSelectQuery(int $parent_id, array $config, array $order_by, int $index, int $display) { |
27 | 27 | |
28 | - return ("SELECT SQL_CALC_FOUND_ROWS " . $this->getSelection() . ", COUNT(chd.descendant) as children ") . |
|
28 | + return ("SELECT SQL_CALC_FOUND_ROWS ".$this->getSelection().", COUNT(chd.descendant) as children "). |
|
29 | 29 | |
30 | - ("FROM " . static::$table . " ent ") . |
|
30 | + ("FROM ".static::$table." ent "). |
|
31 | 31 | |
32 | - ("LEFT JOIN " . static::$table_relations . " chd ON chd.ancestor = ent.id AND chd.depth = 1 ") . |
|
32 | + ("LEFT JOIN ".static::$table_relations." chd ON chd.ancestor = ent.id AND chd.depth = 1 "). |
|
33 | 33 | |
34 | - ("LEFT JOIN " . static::$table_relations . " rel ON rel.descendant = ent.id AND rel.depth = 1 ") . |
|
34 | + ("LEFT JOIN ".static::$table_relations." rel ON rel.descendant = ent.id AND rel.depth = 1 "). |
|
35 | 35 | |
36 | - ("WHERE COALESCE(rel.ancestor, 0) = " . $parent_id . " ") . |
|
36 | + ("WHERE COALESCE(rel.ancestor, 0) = ".$parent_id." "). |
|
37 | 37 | |
38 | - (('' !== ($condition = $this->getCondition($config))) ? ("AND " . $condition . " ") : "") . |
|
38 | + (('' !== ($condition = $this->getCondition($config))) ? ("AND ".$condition." ") : ""). |
|
39 | 39 | |
40 | - ("GROUP BY ent.id ORDER BY " . $this->getOrderBy($order_by) . " ") . |
|
40 | + ("GROUP BY ent.id ORDER BY ".$this->getOrderBy($order_by)." "). |
|
41 | 41 | |
42 | - (($index > 0) ? ("LIMIT " . ((($index - 1) * $display) . ", " . $display)) : ""); |
|
42 | + (($index > 0) ? ("LIMIT ".((($index - 1) * $display).", ".$display)) : ""); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | # Get default count query |
46 | 46 | |
47 | 47 | private function getDefaultCountQuery(array $config) { |
48 | 48 | |
49 | - return ("SELECT COUNT(ent.id) as count FROM " . static::$table . " ent ") . |
|
49 | + return ("SELECT COUNT(ent.id) as count FROM ".static::$table." ent "). |
|
50 | 50 | |
51 | - (('' !== ($condition = $this->getCondition($config))) ? ("WHERE " . $condition) : ""); |
|
51 | + (('' !== ($condition = $this->getCondition($config))) ? ("WHERE ".$condition) : ""); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | # Get nesting count query |
55 | 55 | |
56 | 56 | private function getNestingCountQuery(int $parent_id, array $config) { |
57 | 57 | |
58 | - return ("SELECT COUNT(ent.id) as count FROM " . static::$table . " ent ") . |
|
58 | + return ("SELECT COUNT(ent.id) as count FROM ".static::$table." ent "). |
|
59 | 59 | |
60 | - ("LEFT JOIN " . static::$table_relations . " rel ON rel.descendant = ent.id AND rel.depth = 1 ") . |
|
60 | + ("LEFT JOIN ".static::$table_relations." rel ON rel.descendant = ent.id AND rel.depth = 1 "). |
|
61 | 61 | |
62 | - ("WHERE COALESCE(rel.ancestor, 0) = " . $parent_id . " ") . |
|
62 | + ("WHERE COALESCE(rel.ancestor, 0) = ".$parent_id." "). |
|
63 | 63 | |
64 | - (('' !== ($condition = $this->getCondition($config))) ? ("AND " . $condition) : ""); |
|
64 | + (('' !== ($condition = $this->getCondition($config))) ? ("AND ".$condition) : ""); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | # Select entries from DB |
@@ -74,9 +74,7 @@ discard block |
||
74 | 74 | |
75 | 75 | # Select entities |
76 | 76 | |
77 | - $query = ((null === $parent_id) ? $this->getDefaultSelectQuery($config, $order_by, $index, $display) : |
|
78 | - |
|
79 | - $this->getNestingSelectQuery($parent_id, $config, $order_by, $index, $display)); |
|
77 | + $query = ((null === $parent_id) ? $this->getDefaultSelectQuery($config, $order_by, $index, $display) : $this->getNestingSelectQuery($parent_id, $config, $order_by, $index, $display)); |
|
80 | 78 | |
81 | 79 | if (!(DB::send($query) && DB::last()->status)) return false; |
82 | 80 | |
@@ -113,9 +111,7 @@ discard block |
||
113 | 111 | |
114 | 112 | # Count entities |
115 | 113 | |
116 | - $query = ((null === $parent_id) ? $this->getDefaultCountQuery($config) : |
|
117 | - |
|
118 | - $this->getNestingCountQuery($parent_id, $config)); |
|
114 | + $query = ((null === $parent_id) ? $this->getDefaultCountQuery($config) : $this->getNestingCountQuery($parent_id, $config)); |
|
119 | 115 | |
120 | 116 | if (!(DB::send($query) && DB::last()->status)) return false; |
121 | 117 |
@@ -68,9 +68,13 @@ discard block |
||
68 | 68 | |
69 | 69 | private function select(int $parent_id = null, array $config = [], array $order_by = [], int $index = 0, int $display = 0) { |
70 | 70 | |
71 | - if (!((null === $parent_id) || ($parent_id >= 0))) return false; |
|
71 | + if (!((null === $parent_id) || ($parent_id >= 0))) { |
|
72 | + return false; |
|
73 | + } |
|
72 | 74 | |
73 | - if (!(($index >= 0) && ($display >= 0))) return false; |
|
75 | + if (!(($index >= 0) && ($display >= 0))) { |
|
76 | + return false; |
|
77 | + } |
|
74 | 78 | |
75 | 79 | # Select entities |
76 | 80 | |
@@ -78,7 +82,9 @@ discard block |
||
78 | 82 | |
79 | 83 | $this->getNestingSelectQuery($parent_id, $config, $order_by, $index, $display)); |
80 | 84 | |
81 | - if (!(DB::send($query) && DB::last()->status)) return false; |
|
85 | + if (!(DB::send($query) && DB::last()->status)) { |
|
86 | + return false; |
|
87 | + } |
|
82 | 88 | |
83 | 89 | # Process results |
84 | 90 | |
@@ -90,7 +96,9 @@ discard block |
||
90 | 96 | |
91 | 97 | $items['list'][$entity->id] = ['entity' => $entity]; |
92 | 98 | |
93 | - if (null !== $parent_id) $items['list'][$entity->id]['children'] = intval($data['children']); |
|
99 | + if (null !== $parent_id) { |
|
100 | + $items['list'][$entity->id]['children'] = intval($data['children']); |
|
101 | + } |
|
94 | 102 | } |
95 | 103 | |
96 | 104 | # Count total |
@@ -109,7 +117,9 @@ discard block |
||
109 | 117 | |
110 | 118 | private function count(int $parent_id = null, array $config = []) { |
111 | 119 | |
112 | - if (!((null === $parent_id) || ($parent_id >= 0))) return false; |
|
120 | + if (!((null === $parent_id) || ($parent_id >= 0))) { |
|
121 | + return false; |
|
122 | + } |
|
113 | 123 | |
114 | 124 | # Count entities |
115 | 125 | |
@@ -117,7 +127,9 @@ discard block |
||
117 | 127 | |
118 | 128 | $this->getNestingCountQuery($parent_id, $config)); |
119 | 129 | |
120 | - if (!(DB::send($query) && DB::last()->status)) return false; |
|
130 | + if (!(DB::send($query) && DB::last()->status)) { |
|
131 | + return false; |
|
132 | + } |
|
121 | 133 | |
122 | 134 | # ------------------------ |
123 | 135 | |
@@ -142,7 +154,9 @@ discard block |
||
142 | 154 | |
143 | 155 | public function children(int $parent_id = 0, array $config = [], array $order_by = [], int $index = 0, int $display = 0) { |
144 | 156 | |
145 | - if (!static::$nesting) return false; |
|
157 | + if (!static::$nesting) { |
|
158 | + return false; |
|
159 | + } |
|
146 | 160 | |
147 | 161 | return $this->select(...func_get_args()); |
148 | 162 | } |
@@ -151,7 +165,9 @@ discard block |
||
151 | 165 | |
152 | 166 | public function childrenCount(int $parent_id = 0, array $config = []) { |
153 | 167 | |
154 | - if (!static::$nesting) return false; |
|
168 | + if (!static::$nesting) { |
|
169 | + return false; |
|
170 | + } |
|
155 | 171 | |
156 | 172 | return $this->count(...func_get_args()); |
157 | 173 | } |
@@ -20,15 +20,15 @@ discard block |
||
20 | 20 | |
21 | 21 | # Set create button |
22 | 22 | |
23 | - if (count($this->path) < CONFIG_ENTITIZER_MAX_DEPTH) $parent->block('create')->id = $this->parent->id; |
|
24 | - |
|
25 | - else { $parent->block('create')->disable(); $parent->block('create_disabled')->enable(); } |
|
23 | + if (count($this->path) < CONFIG_ENTITIZER_MAX_DEPTH) { |
|
24 | + $parent->block('create')->id = $this->parent->id; |
|
25 | + } else { $parent->block('create')->disable(); $parent->block('create_disabled')->enable(); } |
|
26 | 26 | |
27 | 27 | # Set edit button |
28 | 28 | |
29 | - if (0 !== $this->parent->id) $parent->block('edit')->id = $this->parent->id; |
|
30 | - |
|
31 | - else { $parent->block('edit')->disable(); $parent->block('edit_disabled')->enable(); } |
|
29 | + if (0 !== $this->parent->id) { |
|
30 | + $parent->block('edit')->id = $this->parent->id; |
|
31 | + } else { $parent->block('edit')->disable(); $parent->block('edit_disabled')->enable(); } |
|
32 | 32 | |
33 | 33 | # Add parent additional data |
34 | 34 | |
@@ -43,7 +43,9 @@ discard block |
||
43 | 43 | |
44 | 44 | foreach ($this->items['list'] as $item) { |
45 | 45 | |
46 | - if ((null !== $this->entity) && ($item['entity']->id === $this->entity->id)) continue; |
|
46 | + if ((null !== $this->entity) && ($item['entity']->id === $this->entity->id)) { |
|
47 | + continue; |
|
48 | + } |
|
47 | 49 | |
48 | 50 | $items->add($view = View::get(!$ajax ? static::$view_item : static::$view_ajax_item)); |
49 | 51 | |
@@ -101,21 +103,29 @@ discard block |
||
101 | 103 | |
102 | 104 | # Set path |
103 | 105 | |
104 | - if (static::$nesting) $contents->path = $this->path; |
|
106 | + if (static::$nesting) { |
|
107 | + $contents->path = $this->path; |
|
108 | + } |
|
105 | 109 | |
106 | 110 | # Process parent block |
107 | 111 | |
108 | - if (static::$nesting && !$ajax) $this->processParent($contents->block('parent')); |
|
112 | + if (static::$nesting && !$ajax) { |
|
113 | + $this->processParent($contents->block('parent')); |
|
114 | + } |
|
109 | 115 | |
110 | 116 | # Set items |
111 | 117 | |
112 | 118 | $items = $this->getItemsBlock($ajax); |
113 | 119 | |
114 | - if ($items->count() > 0) $contents->items = $items; |
|
120 | + if ($items->count() > 0) { |
|
121 | + $contents->items = $items; |
|
122 | + } |
|
115 | 123 | |
116 | 124 | # Set pagination |
117 | 125 | |
118 | - if (!$ajax) $contents->pagination = $this->getPaginationBlock(); |
|
126 | + if (!$ajax) { |
|
127 | + $contents->pagination = $this->getPaginationBlock(); |
|
128 | + } |
|
119 | 129 | |
120 | 130 | # ------------------------ |
121 | 131 | |
@@ -140,15 +150,21 @@ discard block |
||
140 | 150 | |
141 | 151 | # Get path and depth |
142 | 152 | |
143 | - if (false !== ($path = $this->parent->path())) $this->path = $path; |
|
153 | + if (false !== ($path = $this->parent->path())) { |
|
154 | + $this->path = $path; |
|
155 | + } |
|
144 | 156 | |
145 | - if ((0 !== $this->entity->id) && (false !== ($depth = $this->entity->subtreeDepth()))) $this->depth = $depth; |
|
157 | + if ((0 !== $this->entity->id) && (false !== ($depth = $this->entity->subtreeDepth()))) { |
|
158 | + $this->depth = $depth; |
|
159 | + } |
|
146 | 160 | |
147 | 161 | # Get items list |
148 | 162 | |
149 | 163 | $lister = (static::$nesting ? 'children' : 'items'); |
150 | 164 | |
151 | - if (false !== ($items = $this->parent->$lister())) $this->items = $items; |
|
165 | + if (false !== ($items = $this->parent->$lister())) { |
|
166 | + $this->items = $items; |
|
167 | + } |
|
152 | 168 | |
153 | 169 | # ------------------------ |
154 | 170 | |
@@ -159,7 +175,9 @@ discard block |
||
159 | 175 | |
160 | 176 | public function handle() { |
161 | 177 | |
162 | - if (Request::isAjax()) return $this->handleAjax(); |
|
178 | + if (Request::isAjax()) { |
|
179 | + return $this->handleAjax(); |
|
180 | + } |
|
163 | 181 | |
164 | 182 | $this->index = Number::format(Request::get('index'), 1, 999999); |
165 | 183 | |
@@ -171,13 +189,17 @@ discard block |
||
171 | 189 | |
172 | 190 | # Get path |
173 | 191 | |
174 | - if (false !== ($path = $this->parent->path())) $this->path = $path; |
|
192 | + if (false !== ($path = $this->parent->path())) { |
|
193 | + $this->path = $path; |
|
194 | + } |
|
175 | 195 | |
176 | 196 | # Get items list |
177 | 197 | |
178 | 198 | $lister = (static::$nesting ? 'children' : 'items'); $index = $this->index; $display = static::$display; |
179 | 199 | |
180 | - if (false !== ($items = $this->parent->$lister([], [], $index, $display))) $this->items = $items; |
|
200 | + if (false !== ($items = $this->parent->$lister([], [], $index, $display))) { |
|
201 | + $this->items = $items; |
|
202 | + } |
|
181 | 203 | |
182 | 204 | # ------------------------ |
183 | 205 |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | |
13 | 13 | return (0 !== $parent_id) ? (("JOIN " . static::$table_relations . " rel ") . |
14 | 14 | |
15 | - ("ON rel.ancestor = " . $parent_id . " AND rel.descendant = ent.id AND rel.depth >= 1")) : |
|
15 | + ("ON rel.ancestor = " . $parent_id . " AND rel.descendant = ent.id AND rel.depth >= 1")) : |
|
16 | 16 | |
17 | 17 | ("JOIN " . static::$table_relations . " rel ON rel.descendant = ent.id"); |
18 | 18 | } |
@@ -23,13 +23,13 @@ discard block |
||
23 | 23 | |
24 | 24 | return ("SELECT " . $this->getSelection() . ", COALESCE(par.ancestor, 0) as parent_id ") . |
25 | 25 | |
26 | - ("FROM " . static::$table . " ent " . $this->getQueryJoin($parent_id) . " ") . |
|
26 | + ("FROM " . static::$table . " ent " . $this->getQueryJoin($parent_id) . " ") . |
|
27 | 27 | |
28 | - ("LEFT JOIN " . static::$table_relations . " par ON par.descendant = ent.id AND par.depth = 1 ") . |
|
28 | + ("LEFT JOIN " . static::$table_relations . " par ON par.descendant = ent.id AND par.depth = 1 ") . |
|
29 | 29 | |
30 | - (('' !== ($condition = $this->getCondition($config))) ? ("WHERE " . $condition . " ") : "") . |
|
30 | + (('' !== ($condition = $this->getCondition($config))) ? ("WHERE " . $condition . " ") : "") . |
|
31 | 31 | |
32 | - ("GROUP BY ent.id ORDER BY rel.depth ASC, " . $this->getOrderBy($order_by)); |
|
32 | + ("GROUP BY ent.id ORDER BY rel.depth ASC, " . $this->getOrderBy($order_by)); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | # Get count query |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | |
39 | 39 | return ("SELECT COUNT(DISTINCT ent.id) as count FROM " . static::$table . " ent ") . |
40 | 40 | |
41 | - $this->getQueryJoin($parent_id); |
|
41 | + $this->getQueryJoin($parent_id); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | # Get depth query |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | |
48 | 48 | $query = ("SELECT COUNT(DISTINCT rel.depth) as depth FROM " . static::$table . " ent ") . |
49 | 49 | |
50 | - $this->getQueryJoin($parent_id); |
|
50 | + $this->getQueryJoin($parent_id); |
|
51 | 51 | |
52 | 52 | # ------------------------ |
53 | 53 | |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | |
129 | 129 | $query = ("SELECT " . $this->getSelection() . " FROM " . static::$table . " ent ") . |
130 | 130 | |
131 | - ("JOIN " . static::$table_relations . " rel ON rel.ancestor = ent.id ") . |
|
131 | + ("JOIN " . static::$table_relations . " rel ON rel.ancestor = ent.id ") . |
|
132 | 132 | |
133 | 133 | ("WHERE rel.descendant = " . $parent_id . " ORDER BY rel.depth DESC"); |
134 | 134 |
@@ -10,33 +10,31 @@ discard block |
||
10 | 10 | |
11 | 11 | protected function getQueryJoin(int $parent_id) { |
12 | 12 | |
13 | - return (0 !== $parent_id) ? (("JOIN " . static::$table_relations . " rel ") . |
|
13 | + return (0 !== $parent_id) ? (("JOIN ".static::$table_relations." rel "). |
|
14 | 14 | |
15 | - ("ON rel.ancestor = " . $parent_id . " AND rel.descendant = ent.id AND rel.depth >= 1")) : |
|
16 | - |
|
17 | - ("JOIN " . static::$table_relations . " rel ON rel.descendant = ent.id"); |
|
15 | + ("ON rel.ancestor = ".$parent_id." AND rel.descendant = ent.id AND rel.depth >= 1")) : ("JOIN ".static::$table_relations." rel ON rel.descendant = ent.id"); |
|
18 | 16 | } |
19 | 17 | |
20 | 18 | # Get select query |
21 | 19 | |
22 | 20 | private function getSelectQuery(int $parent_id, array $config, array $order_by) { |
23 | 21 | |
24 | - return ("SELECT " . $this->getSelection() . ", COALESCE(par.ancestor, 0) as parent_id ") . |
|
22 | + return ("SELECT ".$this->getSelection().", COALESCE(par.ancestor, 0) as parent_id "). |
|
25 | 23 | |
26 | - ("FROM " . static::$table . " ent " . $this->getQueryJoin($parent_id) . " ") . |
|
24 | + ("FROM ".static::$table." ent ".$this->getQueryJoin($parent_id)." "). |
|
27 | 25 | |
28 | - ("LEFT JOIN " . static::$table_relations . " par ON par.descendant = ent.id AND par.depth = 1 ") . |
|
26 | + ("LEFT JOIN ".static::$table_relations." par ON par.descendant = ent.id AND par.depth = 1 "). |
|
29 | 27 | |
30 | - (('' !== ($condition = $this->getCondition($config))) ? ("WHERE " . $condition . " ") : "") . |
|
28 | + (('' !== ($condition = $this->getCondition($config))) ? ("WHERE ".$condition." ") : ""). |
|
31 | 29 | |
32 | - ("GROUP BY ent.id ORDER BY rel.depth ASC, " . $this->getOrderBy($order_by)); |
|
30 | + ("GROUP BY ent.id ORDER BY rel.depth ASC, ".$this->getOrderBy($order_by)); |
|
33 | 31 | } |
34 | 32 | |
35 | 33 | # Get count query |
36 | 34 | |
37 | 35 | private function getCountQuery(int $parent_id) { |
38 | 36 | |
39 | - return ("SELECT COUNT(DISTINCT ent.id) as count FROM " . static::$table . " ent ") . |
|
37 | + return ("SELECT COUNT(DISTINCT ent.id) as count FROM ".static::$table." ent "). |
|
40 | 38 | |
41 | 39 | $this->getQueryJoin($parent_id); |
42 | 40 | } |
@@ -45,7 +43,7 @@ discard block |
||
45 | 43 | |
46 | 44 | private function getDepthQuery(int $parent_id) { |
47 | 45 | |
48 | - $query = ("SELECT COUNT(DISTINCT rel.depth) as depth FROM " . static::$table . " ent ") . |
|
46 | + $query = ("SELECT COUNT(DISTINCT rel.depth) as depth FROM ".static::$table." ent "). |
|
49 | 47 | |
50 | 48 | $this->getQueryJoin($parent_id); |
51 | 49 | |
@@ -126,11 +124,11 @@ discard block |
||
126 | 124 | |
127 | 125 | # Process query |
128 | 126 | |
129 | - $query = ("SELECT " . $this->getSelection() . " FROM " . static::$table . " ent ") . |
|
127 | + $query = ("SELECT ".$this->getSelection()." FROM ".static::$table." ent "). |
|
130 | 128 | |
131 | - ("JOIN " . static::$table_relations . " rel ON rel.ancestor = ent.id ") . |
|
129 | + ("JOIN ".static::$table_relations." rel ON rel.ancestor = ent.id "). |
|
132 | 130 | |
133 | - ("WHERE rel.descendant = " . $parent_id . " ORDER BY rel.depth DESC"); |
|
131 | + ("WHERE rel.descendant = ".$parent_id." ORDER BY rel.depth DESC"); |
|
134 | 132 | |
135 | 133 | # Select path |
136 | 134 |
@@ -58,13 +58,17 @@ discard block |
||
58 | 58 | |
59 | 59 | public function subtree(int $parent_id = 0, array $config = [], array $order_by = []) { |
60 | 60 | |
61 | - if (!(static::$nesting && ($parent_id >= 0))) return false; |
|
61 | + if (!(static::$nesting && ($parent_id >= 0))) { |
|
62 | + return false; |
|
63 | + } |
|
62 | 64 | |
63 | 65 | # Select entities |
64 | 66 | |
65 | 67 | $query = $this->getSelectQuery($parent_id, $config, $order_by); |
66 | 68 | |
67 | - if (!(DB::send($query) && DB::last()->status)) return false; |
|
69 | + if (!(DB::send($query) && DB::last()->status)) { |
|
70 | + return false; |
|
71 | + } |
|
68 | 72 | |
69 | 73 | # Process results |
70 | 74 | |
@@ -88,13 +92,17 @@ discard block |
||
88 | 92 | |
89 | 93 | public function subtreeCount(int $parent_id = 0) { |
90 | 94 | |
91 | - if (!(static::$nesting && ($parent_id >= 0))) return false; |
|
95 | + if (!(static::$nesting && ($parent_id >= 0))) { |
|
96 | + return false; |
|
97 | + } |
|
92 | 98 | |
93 | 99 | # Get count |
94 | 100 | |
95 | 101 | $query = $this->getCountQuery($parent_id); |
96 | 102 | |
97 | - if (!(DB::send($query) && DB::last()->status)) return false; |
|
103 | + if (!(DB::send($query) && DB::last()->status)) { |
|
104 | + return false; |
|
105 | + } |
|
98 | 106 | |
99 | 107 | # ------------------------ |
100 | 108 | |
@@ -105,13 +113,17 @@ discard block |
||
105 | 113 | |
106 | 114 | public function subtreeDepth(int $parent_id = 0) { |
107 | 115 | |
108 | - if (!(static::$nesting && ($parent_id >= 0))) return false; |
|
116 | + if (!(static::$nesting && ($parent_id >= 0))) { |
|
117 | + return false; |
|
118 | + } |
|
109 | 119 | |
110 | 120 | # Get depth |
111 | 121 | |
112 | 122 | $query = $this->getDepthQuery($parent_id); |
113 | 123 | |
114 | - if (!(DB::send($query) && DB::last()->status)) return false; |
|
124 | + if (!(DB::send($query) && DB::last()->status)) { |
|
125 | + return false; |
|
126 | + } |
|
115 | 127 | |
116 | 128 | # ------------------------ |
117 | 129 | |
@@ -122,7 +134,9 @@ discard block |
||
122 | 134 | |
123 | 135 | public function path(int $parent_id = 0) { |
124 | 136 | |
125 | - if (!(static::$nesting && ($parent_id >= 0))) return false; |
|
137 | + if (!(static::$nesting && ($parent_id >= 0))) { |
|
138 | + return false; |
|
139 | + } |
|
126 | 140 | |
127 | 141 | # Process query |
128 | 142 | |
@@ -134,13 +148,17 @@ discard block |
||
134 | 148 | |
135 | 149 | # Select path |
136 | 150 | |
137 | - if (!(DB::send($query) && DB::last()->status)) return false; |
|
151 | + if (!(DB::send($query) && DB::last()->status)) { |
|
152 | + return false; |
|
153 | + } |
|
138 | 154 | |
139 | 155 | # Process results |
140 | 156 | |
141 | 157 | $path = []; |
142 | 158 | |
143 | - while (null !== ($data = DB::last()->row())) $path[] = Entitizer::create(static::$table, $data)->data(); |
|
159 | + while (null !== ($data = DB::last()->row())) { |
|
160 | + $path[] = Entitizer::create(static::$table, $data)->data(); |
|
161 | + } |
|
144 | 162 | |
145 | 163 | # ------------------------ |
146 | 164 |
@@ -14,19 +14,19 @@ |
||
14 | 14 | |
15 | 15 | # Add params |
16 | 16 | |
17 | - $this->params->textual ('code', true, 40, true, ''); |
|
18 | - $this->params->textual ('ip', true, 255, false, ''); |
|
19 | - $this->params->integer ('time', false, 10, true, 0); |
|
17 | + $this->params->textual('code', true, 40, true, ''); |
|
18 | + $this->params->textual('ip', true, 255, false, ''); |
|
19 | + $this->params->integer('time', false, 10, true, 0); |
|
20 | 20 | |
21 | 21 | # Add indexes |
22 | 22 | |
23 | - $this->indexes->add ('code', 'UNIQUE'); |
|
24 | - $this->indexes->add ('ip'); |
|
25 | - $this->indexes->add ('time'); |
|
23 | + $this->indexes->add('code', 'UNIQUE'); |
|
24 | + $this->indexes->add('ip'); |
|
25 | + $this->indexes->add('time'); |
|
26 | 26 | |
27 | 27 | # Add foreign keys |
28 | 28 | |
29 | - $this->foreigns->add ('id', TABLE_USERS, 'id', 'CASCADE', 'RESTRICT'); |
|
29 | + $this->foreigns->add('id', TABLE_USERS, 'id', 'CASCADE', 'RESTRICT'); |
|
30 | 30 | } |
31 | 31 | } |
32 | 32 | } |
@@ -14,19 +14,19 @@ |
||
14 | 14 | |
15 | 15 | # Add params |
16 | 16 | |
17 | - $this->params->textual ('code', true, 40, true, ''); |
|
18 | - $this->params->textual ('ip', true, 255, false, ''); |
|
19 | - $this->params->integer ('time', false, 10, true, 0); |
|
17 | + $this->params->textual('code', true, 40, true, ''); |
|
18 | + $this->params->textual('ip', true, 255, false, ''); |
|
19 | + $this->params->integer('time', false, 10, true, 0); |
|
20 | 20 | |
21 | 21 | # Add indexes |
22 | 22 | |
23 | - $this->indexes->add ('code', 'UNIQUE'); |
|
24 | - $this->indexes->add ('ip'); |
|
25 | - $this->indexes->add ('time'); |
|
23 | + $this->indexes->add('code', 'UNIQUE'); |
|
24 | + $this->indexes->add('ip'); |
|
25 | + $this->indexes->add('time'); |
|
26 | 26 | |
27 | 27 | # Add foreign keys |
28 | 28 | |
29 | - $this->foreigns->add ('id', TABLE_USERS, 'id', 'CASCADE', 'RESTRICT'); |
|
29 | + $this->foreigns->add('id', TABLE_USERS, 'id', 'CASCADE', 'RESTRICT'); |
|
30 | 30 | } |
31 | 31 | } |
32 | 32 | } |
@@ -14,29 +14,29 @@ |
||
14 | 14 | |
15 | 15 | # Add params |
16 | 16 | |
17 | - $this->params->integer ('visibility', true, 1, true, VISIBILITY_DRAFT); |
|
18 | - $this->params->integer ('access', true, 1, true, ACCESS_PUBLIC); |
|
19 | - $this->params->boolean ('locked', true); |
|
20 | - $this->params->textual ('slug', true, 255, false, ''); |
|
21 | - $this->params->textual ('name', true, 255, false, ''); |
|
22 | - $this->params->textual ('title', true, 255, false, ''); |
|
23 | - $this->params->textual ('contents', false, 0, false, ''); |
|
24 | - $this->params->textual ('description', false, 0, false, ''); |
|
25 | - $this->params->textual ('keywords', false, 0, false, ''); |
|
26 | - $this->params->boolean ('robots_index', false); |
|
27 | - $this->params->boolean ('robots_follow', false); |
|
28 | - $this->params->integer ('time_created', false, 10, true, 0); |
|
29 | - $this->params->integer ('time_modified', false, 10, true, 0); |
|
17 | + $this->params->integer('visibility', true, 1, true, VISIBILITY_DRAFT); |
|
18 | + $this->params->integer('access', true, 1, true, ACCESS_PUBLIC); |
|
19 | + $this->params->boolean('locked', true); |
|
20 | + $this->params->textual('slug', true, 255, false, ''); |
|
21 | + $this->params->textual('name', true, 255, false, ''); |
|
22 | + $this->params->textual('title', true, 255, false, ''); |
|
23 | + $this->params->textual('contents', false, 0, false, ''); |
|
24 | + $this->params->textual('description', false, 0, false, ''); |
|
25 | + $this->params->textual('keywords', false, 0, false, ''); |
|
26 | + $this->params->boolean('robots_index', false); |
|
27 | + $this->params->boolean('robots_follow', false); |
|
28 | + $this->params->integer('time_created', false, 10, true, 0); |
|
29 | + $this->params->integer('time_modified', false, 10, true, 0); |
|
30 | 30 | |
31 | 31 | # Add indexes |
32 | 32 | |
33 | - $this->indexes->add ('visibility'); |
|
34 | - $this->indexes->add ('access'); |
|
35 | - $this->indexes->add ('slug'); |
|
36 | - $this->indexes->add ('name'); |
|
37 | - $this->indexes->add ('title'); |
|
38 | - $this->indexes->add ('time_created'); |
|
39 | - $this->indexes->add ('time_modified'); |
|
33 | + $this->indexes->add('visibility'); |
|
34 | + $this->indexes->add('access'); |
|
35 | + $this->indexes->add('slug'); |
|
36 | + $this->indexes->add('name'); |
|
37 | + $this->indexes->add('title'); |
|
38 | + $this->indexes->add('time_created'); |
|
39 | + $this->indexes->add('time_modified'); |
|
40 | 40 | } |
41 | 41 | } |
42 | 42 | } |
@@ -14,16 +14,16 @@ |
||
14 | 14 | |
15 | 15 | # Add params |
16 | 16 | |
17 | - $this->params->boolean ('active', false); |
|
18 | - $this->params->textual ('name', true, 255, false, ''); |
|
19 | - $this->params->textual ('title', true, 255, false, ''); |
|
20 | - $this->params->textual ('contents', false, 0, false, ''); |
|
17 | + $this->params->boolean('active', false); |
|
18 | + $this->params->textual('name', true, 255, false, ''); |
|
19 | + $this->params->textual('title', true, 255, false, ''); |
|
20 | + $this->params->textual('contents', false, 0, false, ''); |
|
21 | 21 | |
22 | 22 | # Add indexes |
23 | 23 | |
24 | - $this->indexes->add ('active'); |
|
25 | - $this->indexes->add ('name', 'UNIQUE'); |
|
26 | - $this->indexes->add ('title'); |
|
24 | + $this->indexes->add('active'); |
|
25 | + $this->indexes->add('name', 'UNIQUE'); |
|
26 | + $this->indexes->add('title'); |
|
27 | 27 | } |
28 | 28 | } |
29 | 29 | } |
@@ -14,16 +14,16 @@ |
||
14 | 14 | |
15 | 15 | # Add params |
16 | 16 | |
17 | - $this->params->boolean ('active', false); |
|
18 | - $this->params->integer ('position', true, 2, true, 0); |
|
19 | - $this->params->textual ('slug', true, 255, false, ''); |
|
20 | - $this->params->textual ('text', true, 255, false, ''); |
|
21 | - $this->params->integer ('target', true, 1, true, TARGET_SELF); |
|
17 | + $this->params->boolean('active', false); |
|
18 | + $this->params->integer('position', true, 2, true, 0); |
|
19 | + $this->params->textual('slug', true, 255, false, ''); |
|
20 | + $this->params->textual('text', true, 255, false, ''); |
|
21 | + $this->params->integer('target', true, 1, true, TARGET_SELF); |
|
22 | 22 | |
23 | 23 | # Add indexes |
24 | 24 | |
25 | - $this->indexes->add ('active'); |
|
26 | - $this->indexes->add ('position'); |
|
25 | + $this->indexes->add('active'); |
|
26 | + $this->indexes->add('position'); |
|
27 | 27 | } |
28 | 28 | } |
29 | 29 | } |