@@ -2,7 +2,10 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace Modules\Entitizer\Lister { |
| 4 | 4 | |
| 5 | - use Modules\Auth, Modules\Entitizer, Utils\Range, Template; |
|
| 5 | + use Modules\Auth; |
|
| 6 | + use Modules\Entitizer; |
|
| 7 | + use Utils\Range; |
|
| 8 | + use Template; |
|
| 6 | 9 | |
| 7 | 10 | class Users extends Entitizer\Utils\Lister { |
| 8 | 11 | |
@@ -36,7 +36,9 @@ |
||
| 36 | 36 | |
| 37 | 37 | $view->rank = Lister\Rank::get($user->rank); |
| 38 | 38 | |
| 39 | - if ($user->id === Auth::user()->id) $view->block('remove')->class = 'disabled'; |
|
| 39 | + if ($user->id === Auth::user()->id) { |
|
| 40 | + $view->block('remove')->class = 'disabled'; |
|
| 41 | + } |
|
| 40 | 42 | } |
| 41 | 43 | } |
| 42 | 44 | } |
@@ -2,7 +2,8 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace Modules\Entitizer\Listview { |
| 4 | 4 | |
| 5 | - use Modules\Entitizer, Template; |
|
| 5 | + use Modules\Entitizer; |
|
| 6 | + use Template; |
|
| 6 | 7 | |
| 7 | 8 | class Variables extends Entitizer\Utils\Listview { |
| 8 | 9 | |
@@ -2,7 +2,8 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace Modules\Entitizer\Listview { |
| 4 | 4 | |
| 5 | - use Modules\Entitizer, Template; |
|
| 5 | + use Modules\Entitizer; |
|
| 6 | + use Template; |
|
| 6 | 7 | |
| 7 | 8 | class Variables extends Entitizer\Utils\Listview { |
| 8 | 9 | |
@@ -2,7 +2,8 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace Modules\Entitizer\Utils { |
| 4 | 4 | |
| 5 | - use Modules\Entitizer, DB; |
|
| 5 | + use Modules\Entitizer; |
|
| 6 | + use DB; |
|
| 6 | 7 | |
| 7 | 8 | abstract class Entity extends Entitizer { |
| 8 | 9 | |
@@ -24,11 +24,11 @@ |
||
| 24 | 24 | |
| 25 | 25 | $query = ("SELECT " . implode(', ', $selection) .", rel.ancestor as parent_id ") . |
| 26 | 26 | |
| 27 | - ("FROM " . static::$table . " ent ") . |
|
| 27 | + ("FROM " . static::$table . " ent ") . |
|
| 28 | 28 | |
| 29 | - ("LEFT JOIN " . static::$table_relations . " rel ON rel.descendant = ent.id AND rel.depth = 1 ") . |
|
| 29 | + ("LEFT JOIN " . static::$table_relations . " rel ON rel.descendant = ent.id AND rel.depth = 1 ") . |
|
| 30 | 30 | |
| 31 | - ("WHERE ent." . $name . " = '" . addslashes($value) . "' LIMIT 1"); |
|
| 31 | + ("WHERE ent." . $name . " = '" . addslashes($value) . "' LIMIT 1"); |
|
| 32 | 32 | |
| 33 | 33 | # ------------------------ |
| 34 | 34 | |
@@ -18,17 +18,17 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | $selection = array_keys($this->definition->params()); |
| 20 | 20 | |
| 21 | - foreach ($selection as $key => $field) $selection[$key] = ('ent.' . $field); |
|
| 21 | + foreach ($selection as $key => $field) $selection[$key] = ('ent.'.$field); |
|
| 22 | 22 | |
| 23 | 23 | # Process query |
| 24 | 24 | |
| 25 | - $query = ("SELECT " . implode(', ', $selection) .", rel.ancestor as parent_id ") . |
|
| 25 | + $query = ("SELECT ".implode(', ', $selection).", rel.ancestor as parent_id "). |
|
| 26 | 26 | |
| 27 | - ("FROM " . static::$table . " ent ") . |
|
| 27 | + ("FROM ".static::$table." ent "). |
|
| 28 | 28 | |
| 29 | - ("LEFT JOIN " . static::$table_relations . " rel ON rel.descendant = ent.id AND rel.depth = 1 ") . |
|
| 29 | + ("LEFT JOIN ".static::$table_relations." rel ON rel.descendant = ent.id AND rel.depth = 1 "). |
|
| 30 | 30 | |
| 31 | - ("WHERE ent." . $name . " = '" . addslashes($value) . "' LIMIT 1"); |
|
| 31 | + ("WHERE ent.".$name." = '".addslashes($value)."' LIMIT 1"); |
|
| 32 | 32 | |
| 33 | 33 | # ------------------------ |
| 34 | 34 | |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | |
| 134 | 134 | # Select entity from DB |
| 135 | 135 | |
| 136 | - $condition = ($name . " = '" . addslashes($value) . "' AND id != " . $this->id); |
|
| 136 | + $condition = ($name." = '".addslashes($value)."' AND id != ".$this->id); |
|
| 137 | 137 | |
| 138 | 138 | DB::select(static::$table, 'id', $condition, null, 1); |
| 139 | 139 | |
@@ -27,7 +27,9 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | $selection = array_keys($this->definition->params()); |
| 29 | 29 | |
| 30 | - foreach ($selection as $key => $field) $selection[$key] = ('ent.' . $field); |
|
| 30 | + foreach ($selection as $key => $field) { |
|
| 31 | + $selection[$key] = ('ent.' . $field); |
|
| 32 | + } |
|
| 31 | 33 | |
| 32 | 34 | # Process query |
| 33 | 35 | |
@@ -87,13 +89,19 @@ discard block |
||
| 87 | 89 | |
| 88 | 90 | public function init($value, string $name = 'id') { |
| 89 | 91 | |
| 90 | - if (0 !== $this->id) return false; |
|
| 92 | + if (0 !== $this->id) { |
|
| 93 | + return false; |
|
| 94 | + } |
|
| 91 | 95 | |
| 92 | 96 | # Get initiation index |
| 93 | 97 | |
| 94 | - if (false === ($index = $this->definition->index($name))) return false; |
|
| 98 | + if (false === ($index = $this->definition->index($name))) { |
|
| 99 | + return false; |
|
| 100 | + } |
|
| 95 | 101 | |
| 96 | - if (($index->type !== 'PRIMARY') && ($index->type !== 'UNIQUE')) return false; |
|
| 102 | + if (($index->type !== 'PRIMARY') && ($index->type !== 'UNIQUE')) { |
|
| 103 | + return false; |
|
| 104 | + } |
|
| 97 | 105 | |
| 98 | 106 | # Process name & value |
| 99 | 107 | |
@@ -101,7 +109,11 @@ discard block |
||
| 101 | 109 | |
| 102 | 110 | # Select entity from DB |
| 103 | 111 | |
| 104 | - if (!static::$nesting) $this->selectDefault($name, $value); else $this->selectNesting($name, $value); |
|
| 112 | + if (!static::$nesting) { |
|
| 113 | + $this->selectDefault($name, $value); |
|
| 114 | + } else { |
|
| 115 | + $this->selectNesting($name, $value); |
|
| 116 | + } |
|
| 105 | 117 | |
| 106 | 118 | # ------------------------ |
| 107 | 119 | |
@@ -114,9 +126,13 @@ discard block |
||
| 114 | 126 | |
| 115 | 127 | # Get initiation index |
| 116 | 128 | |
| 117 | - if (false === ($index = $this->definition->index($name))) return false; |
|
| 129 | + if (false === ($index = $this->definition->index($name))) { |
|
| 130 | + return false; |
|
| 131 | + } |
|
| 118 | 132 | |
| 119 | - if ($index->type !== 'UNIQUE') return false; |
|
| 133 | + if ($index->type !== 'UNIQUE') { |
|
| 134 | + return false; |
|
| 135 | + } |
|
| 120 | 136 | |
| 121 | 137 | # Process name & value |
| 122 | 138 | |
@@ -2,7 +2,8 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace Modules\Entitizer\Utils { |
| 4 | 4 | |
| 5 | - use Modules\Entitizer, DB; |
|
| 5 | + use Modules\Entitizer; |
|
| 6 | + use DB; |
|
| 6 | 7 | |
| 7 | 8 | abstract class Entity extends Entitizer { |
| 8 | 9 | |
@@ -27,13 +27,13 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | $query = ("DELETE rla FROM " . static::$table_relations . " rla ") . |
| 29 | 29 | |
| 30 | - ("JOIN " . static::$table_relations . " rlb ON rlb.descendant = rla.descendant ") . |
|
| 30 | + ("JOIN " . static::$table_relations . " rlb ON rlb.descendant = rla.descendant ") . |
|
| 31 | 31 | |
| 32 | - ("LEFT JOIN " . static::$table_relations . " rlx ") . |
|
| 32 | + ("LEFT JOIN " . static::$table_relations . " rlx ") . |
|
| 33 | 33 | |
| 34 | - ("ON rlx.ancestor = rlb.ancestor AND rlx.descendant = rla.ancestor ") . |
|
| 34 | + ("ON rlx.ancestor = rlb.ancestor AND rlx.descendant = rla.ancestor ") . |
|
| 35 | 35 | |
| 36 | - ("WHERE rlb.ancestor = " . $this->id . " AND rlx.ancestor IS NULL"); |
|
| 36 | + ("WHERE rlb.ancestor = " . $this->id . " AND rlx.ancestor IS NULL"); |
|
| 37 | 37 | |
| 38 | 38 | if (!(DB::send($query) && DB::last()->status)) return false; |
| 39 | 39 | |
@@ -52,13 +52,13 @@ discard block |
||
| 52 | 52 | |
| 53 | 53 | $query = ("INSERT INTO " . static::$table_relations . " (ancestor, descendant, depth) ") . |
| 54 | 54 | |
| 55 | - ("SELECT sup.ancestor, sub.descendant, sup.depth + sub.depth + 1 ") . |
|
| 55 | + ("SELECT sup.ancestor, sub.descendant, sup.depth + sub.depth + 1 ") . |
|
| 56 | 56 | |
| 57 | - ("FROM " . static::$table_relations . " sup ") . |
|
| 57 | + ("FROM " . static::$table_relations . " sup ") . |
|
| 58 | 58 | |
| 59 | - ("JOIN " . static::$table_relations . " sub ") . |
|
| 59 | + ("JOIN " . static::$table_relations . " sub ") . |
|
| 60 | 60 | |
| 61 | - ("WHERE sub.ancestor = " . $this->id . " AND sup.descendant = " . $parent_id); |
|
| 61 | + ("WHERE sub.ancestor = " . $this->id . " AND sup.descendant = " . $parent_id); |
|
| 62 | 62 | |
| 63 | 63 | if (!(DB::send($query) && DB::last()->status)) return false; |
| 64 | 64 | |
@@ -25,15 +25,15 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | private function disconnectSubtree() { |
| 27 | 27 | |
| 28 | - $query = ("DELETE rla FROM " . static::$table_relations . " rla ") . |
|
| 28 | + $query = ("DELETE rla FROM ".static::$table_relations." rla "). |
|
| 29 | 29 | |
| 30 | - ("JOIN " . static::$table_relations . " rlb ON rlb.descendant = rla.descendant ") . |
|
| 30 | + ("JOIN ".static::$table_relations." rlb ON rlb.descendant = rla.descendant "). |
|
| 31 | 31 | |
| 32 | - ("LEFT JOIN " . static::$table_relations . " rlx ") . |
|
| 32 | + ("LEFT JOIN ".static::$table_relations." rlx "). |
|
| 33 | 33 | |
| 34 | - ("ON rlx.ancestor = rlb.ancestor AND rlx.descendant = rla.ancestor ") . |
|
| 34 | + ("ON rlx.ancestor = rlb.ancestor AND rlx.descendant = rla.ancestor "). |
|
| 35 | 35 | |
| 36 | - ("WHERE rlb.ancestor = " . $this->id . " AND rlx.ancestor IS NULL"); |
|
| 36 | + ("WHERE rlb.ancestor = ".$this->id." AND rlx.ancestor IS NULL"); |
|
| 37 | 37 | |
| 38 | 38 | if (!(DB::send($query) && DB::last()->status)) return false; |
| 39 | 39 | |
@@ -50,15 +50,15 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | private function connectSubtree(int $parent_id) { |
| 52 | 52 | |
| 53 | - $query = ("INSERT INTO " . static::$table_relations . " (ancestor, descendant, depth) ") . |
|
| 53 | + $query = ("INSERT INTO ".static::$table_relations." (ancestor, descendant, depth) "). |
|
| 54 | 54 | |
| 55 | - ("SELECT sup.ancestor, sub.descendant, sup.depth + sub.depth + 1 ") . |
|
| 55 | + ("SELECT sup.ancestor, sub.descendant, sup.depth + sub.depth + 1 "). |
|
| 56 | 56 | |
| 57 | - ("FROM " . static::$table_relations . " sup ") . |
|
| 57 | + ("FROM ".static::$table_relations." sup "). |
|
| 58 | 58 | |
| 59 | - ("JOIN " . static::$table_relations . " sub ") . |
|
| 59 | + ("JOIN ".static::$table_relations." sub "). |
|
| 60 | 60 | |
| 61 | - ("WHERE sub.ancestor = " . $this->id . " AND sup.descendant = " . $parent_id); |
|
| 61 | + ("WHERE sub.ancestor = ".$this->id." AND sup.descendant = ".$parent_id); |
|
| 62 | 62 | |
| 63 | 63 | if (!(DB::send($query) && DB::last()->status)) return false; |
| 64 | 64 | |
@@ -35,7 +35,9 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | ("WHERE rlb.ancestor = " . $this->id . " AND rlx.ancestor IS NULL"); |
| 37 | 37 | |
| 38 | - if (!(DB::send($query) && DB::last()->status)) return false; |
|
| 38 | + if (!(DB::send($query) && DB::last()->status)) { |
|
| 39 | + return false; |
|
| 40 | + } |
|
| 39 | 41 | |
| 40 | 42 | # Set path |
| 41 | 43 | |
@@ -60,7 +62,9 @@ discard block |
||
| 60 | 62 | |
| 61 | 63 | ("WHERE sub.ancestor = " . $this->id . " AND sup.descendant = " . $parent_id); |
| 62 | 64 | |
| 63 | - if (!(DB::send($query) && (DB::last()->rows > 0))) return false; |
|
| 65 | + if (!(DB::send($query) && (DB::last()->rows > 0))) { |
|
| 66 | + return false; |
|
| 67 | + } |
|
| 64 | 68 | |
| 65 | 69 | # Set path |
| 66 | 70 | |
@@ -75,27 +79,37 @@ discard block |
||
| 75 | 79 | |
| 76 | 80 | public function create(array $data) { |
| 77 | 81 | |
| 78 | - if (0 !== $this->id) return false; |
|
| 82 | + if (0 !== $this->id) { |
|
| 83 | + return false; |
|
| 84 | + } |
|
| 79 | 85 | |
| 80 | 86 | $data = $this->dataset->cast($data); |
| 81 | 87 | |
| 82 | - if (static::$auto_increment && isset($data['id'])) $data['id'] = 0; |
|
| 88 | + if (static::$auto_increment && isset($data['id'])) { |
|
| 89 | + $data['id'] = 0; |
|
| 90 | + } |
|
| 83 | 91 | |
| 84 | 92 | # Insert entity |
| 85 | 93 | |
| 86 | 94 | DB::insert(static::$table, $data); |
| 87 | 95 | |
| 88 | - if (!(DB::last() && DB::last()->status)) return false; |
|
| 96 | + if (!(DB::last() && DB::last()->status)) { |
|
| 97 | + return false; |
|
| 98 | + } |
|
| 89 | 99 | |
| 90 | 100 | # Update data |
| 91 | 101 | |
| 92 | - if (static::$auto_increment) $data['id'] = DB::last()->id; |
|
| 102 | + if (static::$auto_increment) { |
|
| 103 | + $data['id'] = DB::last()->id; |
|
| 104 | + } |
|
| 93 | 105 | |
| 94 | 106 | $this->dataset->update($data); |
| 95 | 107 | |
| 96 | 108 | # Init subtreee |
| 97 | 109 | |
| 98 | - if (static::$nesting) $this->initSubtree(); |
|
| 110 | + if (static::$nesting) { |
|
| 111 | + $this->initSubtree(); |
|
| 112 | + } |
|
| 99 | 113 | |
| 100 | 114 | # Cache entity |
| 101 | 115 | |
@@ -110,17 +124,23 @@ discard block |
||
| 110 | 124 | |
| 111 | 125 | public function edit(array $data) { |
| 112 | 126 | |
| 113 | - if (0 === $this->id) return false; |
|
| 127 | + if (0 === $this->id) { |
|
| 128 | + return false; |
|
| 129 | + } |
|
| 114 | 130 | |
| 115 | 131 | $data = $this->dataset->cast($data); |
| 116 | 132 | |
| 117 | - if (isset($data['id'])) unset($data['id']); |
|
| 133 | + if (isset($data['id'])) { |
|
| 134 | + unset($data['id']); |
|
| 135 | + } |
|
| 118 | 136 | |
| 119 | 137 | # Update entity |
| 120 | 138 | |
| 121 | 139 | DB::update(static::$table, $data, ['id' => $this->id]); |
| 122 | 140 | |
| 123 | - if (!(DB::last() && DB::last()->status)) return false; |
|
| 141 | + if (!(DB::last() && DB::last()->status)) { |
|
| 142 | + return false; |
|
| 143 | + } |
|
| 124 | 144 | |
| 125 | 145 | # Update data |
| 126 | 146 | |
@@ -128,7 +148,9 @@ discard block |
||
| 128 | 148 | |
| 129 | 149 | # Init subtreee |
| 130 | 150 | |
| 131 | - if (static::$nesting) $this->initSubtree(); |
|
| 151 | + if (static::$nesting) { |
|
| 152 | + $this->initSubtree(); |
|
| 153 | + } |
|
| 132 | 154 | |
| 133 | 155 | # ------------------------ |
| 134 | 156 | |
@@ -139,30 +161,44 @@ discard block |
||
| 139 | 161 | |
| 140 | 162 | public function move(int $parent_id) { |
| 141 | 163 | |
| 142 | - if (0 === $this->id) return false; |
|
| 164 | + if (0 === $this->id) { |
|
| 165 | + return false; |
|
| 166 | + } |
|
| 143 | 167 | |
| 144 | 168 | # Re-connect entity if not in tree |
| 145 | 169 | |
| 146 | - if (!$this->initSubtree()) return false; |
|
| 170 | + if (!$this->initSubtree()) { |
|
| 171 | + return false; |
|
| 172 | + } |
|
| 147 | 173 | |
| 148 | 174 | # Create parent entity |
| 149 | 175 | |
| 150 | 176 | if (0 !== ($parent = Entitizer::get(static::$table, $parent_id))->id) { |
| 151 | 177 | |
| 152 | - if (false === ($path = $parent->path())) return false; |
|
| 178 | + if (false === ($path = $parent->path())) { |
|
| 179 | + return false; |
|
| 180 | + } |
|
| 153 | 181 | |
| 154 | - if (false === ($depth = $this->subtreeDepth())) return false; |
|
| 182 | + if (false === ($depth = $this->subtreeDepth())) { |
|
| 183 | + return false; |
|
| 184 | + } |
|
| 155 | 185 | |
| 156 | - if ((count($path) + $depth + 1) > CONFIG_ENTITIZER_MAX_DEPTH) return false; |
|
| 186 | + if ((count($path) + $depth + 1) > CONFIG_ENTITIZER_MAX_DEPTH) { |
|
| 187 | + return false; |
|
| 188 | + } |
|
| 157 | 189 | } |
| 158 | 190 | |
| 159 | 191 | # Disconnect subtree from current position |
| 160 | 192 | |
| 161 | - if (!$this->disconnectSubtree()) return false; |
|
| 193 | + if (!$this->disconnectSubtree()) { |
|
| 194 | + return false; |
|
| 195 | + } |
|
| 162 | 196 | |
| 163 | 197 | # Connect subtree under new position |
| 164 | 198 | |
| 165 | - if (0 !== $parent->id) $this->connectSubtree($parent->id); |
|
| 199 | + if (0 !== $parent->id) { |
|
| 200 | + $this->connectSubtree($parent->id); |
|
| 201 | + } |
|
| 166 | 202 | |
| 167 | 203 | # ------------------------ |
| 168 | 204 | |
@@ -173,19 +209,27 @@ discard block |
||
| 173 | 209 | |
| 174 | 210 | public function remove() { |
| 175 | 211 | |
| 176 | - if (0 === $this->id) return false; |
|
| 212 | + if (0 === $this->id) { |
|
| 213 | + return false; |
|
| 214 | + } |
|
| 177 | 215 | |
| 178 | 216 | # Check if entity is removable |
| 179 | 217 | |
| 180 | - if (static::$super && ($this->id === 1)) return false; |
|
| 218 | + if (static::$super && ($this->id === 1)) { |
|
| 219 | + return false; |
|
| 220 | + } |
|
| 181 | 221 | |
| 182 | - if (static::$nesting && (0 !== $this->subtreeCount())) return false; |
|
| 222 | + if (static::$nesting && (0 !== $this->subtreeCount())) { |
|
| 223 | + return false; |
|
| 224 | + } |
|
| 183 | 225 | |
| 184 | 226 | # Remove entity |
| 185 | 227 | |
| 186 | 228 | DB::delete(static::$table, ['id' => $this->id]); |
| 187 | 229 | |
| 188 | - if (!(DB::last() && DB::last()->status)) return false; |
|
| 230 | + if (!(DB::last() && DB::last()->status)) { |
|
| 231 | + return false; |
|
| 232 | + } |
|
| 189 | 233 | |
| 190 | 234 | # Uncache entity |
| 191 | 235 | |
@@ -2,7 +2,14 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace Modules\Entitizer\Utils { |
| 4 | 4 | |
| 5 | - use Modules\Entitizer, Utils\Pagination, Utils\View, Ajax, Number, Request, Template, Url; |
|
| 5 | + use Modules\Entitizer; |
|
| 6 | + use Utils\Pagination; |
|
| 7 | + use Utils\View; |
|
| 8 | + use Ajax; |
|
| 9 | + use Number; |
|
| 10 | + use Request; |
|
| 11 | + use Template; |
|
| 12 | + use Url; |
|
| 6 | 13 | |
| 7 | 14 | abstract class Listview { |
| 8 | 15 | |
@@ -65,9 +65,9 @@ |
||
| 65 | 65 | |
| 66 | 66 | private function getPaginationBlock() { |
| 67 | 67 | |
| 68 | - $query = (static::$nesting ? ('?parent_id=' . $this->parent->id) : ''); |
|
| 68 | + $query = (static::$nesting ? ('?parent_id='.$this->parent->id) : ''); |
|
| 69 | 69 | |
| 70 | - $url = new Url(INSTALL_PATH . static::$link . $query); |
|
| 70 | + $url = new Url(INSTALL_PATH.static::$link.$query); |
|
| 71 | 71 | |
| 72 | 72 | # ------------------------ |
| 73 | 73 | |
@@ -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['dataset']->id === $this->entity->id)) continue; |
|
| 46 | + if ((null !== $this->entity) && ($item['dataset']->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 | |
@@ -2,8 +2,15 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace Modules\Filemanager\Handler { |
| 4 | 4 | |
| 5 | - use Modules\Filemanager, Utils\Messages, Utils\Pagination, Utils\Uploader, Utils\View; |
|
| 6 | - use Ajax, Arr, Explorer, Language, Number, Request, Template, Url; |
|
| 5 | + use Modules\Filemanager; |
|
| 6 | + use Utils\Pagination; |
|
| 7 | + use Utils\Uploader; |
|
| 8 | + use Utils\View; |
|
| 9 | + use Arr; |
|
| 10 | + use Number; |
|
| 11 | + use Request; |
|
| 12 | + use Template; |
|
| 13 | + use Url; |
|
| 7 | 14 | |
| 8 | 15 | class Listview { |
| 9 | 16 | |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | $dirs = []; $files = []; |
| 17 | 17 | |
| 18 | - $prefix = (('' !== $this->parent->path()) ? ($this->parent->path() . '/') : ''); |
|
| 18 | + $prefix = (('' !== $this->parent->path()) ? ($this->parent->path().'/') : ''); |
|
| 19 | 19 | |
| 20 | 20 | # Read parent directory contents |
| 21 | 21 | |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | if (in_array($name, ['.', '..', '.empty'], true)) continue; |
| 27 | 27 | |
| 28 | - $path = ($prefix . $name); $path_full = ($this->parent->pathFull() . $name); |
|
| 28 | + $path = ($prefix.$name); $path_full = ($this->parent->pathFull().$name); |
|
| 29 | 29 | |
| 30 | 30 | $data = ['name' => $name, 'path' => $path, 'path_full' => $path_full]; |
| 31 | 31 | |
@@ -112,9 +112,9 @@ discard block |
||
| 112 | 112 | |
| 113 | 113 | private function getPaginationBlock() { |
| 114 | 114 | |
| 115 | - $query = (('' !== $this->parent->path()) ? ('?parent=' . $this->parent->path()) : ''); |
|
| 115 | + $query = (('' !== $this->parent->path()) ? ('?parent='.$this->parent->path()) : ''); |
|
| 116 | 116 | |
| 117 | - $url = new Url(INSTALL_PATH . '/admin/content/filemanager' . $query); |
|
| 117 | + $url = new Url(INSTALL_PATH.'/admin/content/filemanager'.$query); |
|
| 118 | 118 | |
| 119 | 119 | # ------------------------ |
| 120 | 120 | |
@@ -137,9 +137,9 @@ discard block |
||
| 137 | 137 | |
| 138 | 138 | # Set link |
| 139 | 139 | |
| 140 | - $query = (('' !== $this->parent->path()) ? ('?parent=' . $this->parent->path()) : ''); |
|
| 140 | + $query = (('' !== $this->parent->path()) ? ('?parent='.$this->parent->path()) : ''); |
|
| 141 | 141 | |
| 142 | - $contents->link = (INSTALL_PATH . '/admin/content/filemanager' . $query); |
|
| 142 | + $contents->link = (INSTALL_PATH.'/admin/content/filemanager'.$query); |
|
| 143 | 143 | |
| 144 | 144 | # Implement form |
| 145 | 145 | |
@@ -180,9 +180,9 @@ discard block |
||
| 180 | 180 | |
| 181 | 181 | if ($upload || $this->form->handle(new Filemanager\Controller\Create($this->parent))) { |
| 182 | 182 | |
| 183 | - $query = (('' !== $this->parent->path()) ? ('?parent=' . $this->parent->path()) : ''); |
|
| 183 | + $query = (('' !== $this->parent->path()) ? ('?parent='.$this->parent->path()) : ''); |
|
| 184 | 184 | |
| 185 | - Request::redirect(INSTALL_PATH . '/admin/content/filemanager' . $query); |
|
| 185 | + Request::redirect(INSTALL_PATH.'/admin/content/filemanager'.$query); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | # Get index |
@@ -23,15 +23,19 @@ discard block |
||
| 23 | 23 | |
| 24 | 24 | while (false !== ($name = readdir($handler))) { |
| 25 | 25 | |
| 26 | - if (in_array($name, ['.', '..', '.empty'], true)) continue; |
|
| 26 | + if (in_array($name, ['.', '..', '.empty'], true)) { |
|
| 27 | + continue; |
|
| 28 | + } |
|
| 27 | 29 | |
| 28 | 30 | $path = ($prefix . $name); $path_full = ($this->parent->pathFull() . $name); |
| 29 | 31 | |
| 30 | 32 | $data = ['name' => $name, 'path' => $path, 'path_full' => $path_full]; |
| 31 | 33 | |
| 32 | - if (@is_dir($path_full)) $dirs[] = array_merge($data, ['type' => FILEMANAGER_TYPE_DIR]); |
|
| 33 | - |
|
| 34 | - else if (@is_file($path_full)) $files[] = array_merge($data, ['type' => FILEMANAGER_TYPE_FILE]); |
|
| 34 | + if (@is_dir($path_full)) { |
|
| 35 | + $dirs[] = array_merge($data, ['type' => FILEMANAGER_TYPE_DIR]); |
|
| 36 | + } else if (@is_file($path_full)) { |
|
| 37 | + $files[] = array_merge($data, ['type' => FILEMANAGER_TYPE_FILE]); |
|
| 38 | + } |
|
| 35 | 39 | } |
| 36 | 40 | |
| 37 | 41 | closedir($handler); |
@@ -98,9 +102,11 @@ discard block |
||
| 98 | 102 | |
| 99 | 103 | foreach ($this->items['list'] as $item) { |
| 100 | 104 | |
| 101 | - if ($item['type'] === FILEMANAGER_TYPE_DIR) $items->add($this->getDirItemBlock($item)); |
|
| 102 | - |
|
| 103 | - else if ($item['type'] === FILEMANAGER_TYPE_FILE) $items->add($this->getFileItemBlock($item)); |
|
| 105 | + if ($item['type'] === FILEMANAGER_TYPE_DIR) { |
|
| 106 | + $items->add($this->getDirItemBlock($item)); |
|
| 107 | + } else if ($item['type'] === FILEMANAGER_TYPE_FILE) { |
|
| 108 | + $items->add($this->getFileItemBlock($item)); |
|
| 109 | + } |
|
| 104 | 110 | } |
| 105 | 111 | |
| 106 | 112 | # ------------------------ |
@@ -149,7 +155,9 @@ discard block |
||
| 149 | 155 | |
| 150 | 156 | $items = $this->getItemsBlock(); |
| 151 | 157 | |
| 152 | - if ($items->count() > 0) $contents->items = $items; |
|
| 158 | + if ($items->count() > 0) { |
|
| 159 | + $contents->items = $items; |
|
| 160 | + } |
|
| 153 | 161 | |
| 154 | 162 | # Set pagination |
| 155 | 163 | |
@@ -10,7 +10,9 @@ |
||
| 10 | 10 | |
| 11 | 11 | protected static function init(string $file_name) { |
| 12 | 12 | |
| 13 | - if (is_array($range = Explorer::php($file_name))) static::$range = $range; |
|
| 13 | + if (is_array($range = Explorer::php($file_name))) { |
|
| 14 | + static::$range = $range; |
|
| 15 | + } |
|
| 14 | 16 | } |
| 15 | 17 | |
| 16 | 18 | # Check if item exists |
@@ -10,7 +10,12 @@ discard block |
||
| 10 | 10 | |
| 11 | 11 | $value = false; |
| 12 | 12 | |
| 13 | - foreach ($path as $item) if (isset($array[$item])) $value = ($array = $array[$item]); else return false; |
|
| 13 | + foreach ($path as $item) { |
|
| 14 | + if (isset($array[$item])) $value = ($array = $array[$item]); |
|
| 15 | + } |
|
| 16 | + else { |
|
| 17 | + return false; |
|
| 18 | + } |
|
| 14 | 19 | |
| 15 | 20 | # ------------------------ |
| 16 | 21 | |
@@ -23,10 +28,12 @@ discard block |
||
| 23 | 28 | |
| 24 | 29 | $result = []; |
| 25 | 30 | |
| 26 | - foreach ($keys as $key) if (is_scalar($key)) { |
|
| 31 | + foreach ($keys as $key) { |
|
| 32 | + if (is_scalar($key)) { |
|
| 27 | 33 | |
| 28 | 34 | $result[$key] = ((isset($array[$key]) && is_scalar($array[$key])) ? $array[$key] : false); |
| 29 | 35 | } |
| 36 | + } |
|
| 30 | 37 | |
| 31 | 38 | # ------------------------ |
| 32 | 39 | |
@@ -39,7 +46,9 @@ discard block |
||
| 39 | 46 | |
| 40 | 47 | $result = []; |
| 41 | 48 | |
| 42 | - foreach ($array as $key => $value) $result[] = [$key_name => $key, $value_name => $value]; |
|
| 49 | + foreach ($array as $key => $value) { |
|
| 50 | + $result[] = [$key_name => $key, $value_name => $value]; |
|
| 51 | + } |
|
| 43 | 52 | |
| 44 | 53 | # ------------------------ |
| 45 | 54 | |
@@ -57,9 +66,15 @@ discard block |
||
| 57 | 66 | |
| 58 | 67 | $result = []; $column = array_map($select_key, $array); |
| 59 | 68 | |
| 60 | - if (!$descending) asort($column); else arsort($column); |
|
| 69 | + if (!$descending) { |
|
| 70 | + asort($column); |
|
| 71 | + } else { |
|
| 72 | + arsort($column); |
|
| 73 | + } |
|
| 61 | 74 | |
| 62 | - foreach (array_keys($column) as $key) $result[$key] = $array[$key]; |
|
| 75 | + foreach (array_keys($column) as $key) { |
|
| 76 | + $result[$key] = $array[$key]; |
|
| 77 | + } |
|
| 63 | 78 | |
| 64 | 79 | # ------------------------ |
| 65 | 80 | |