@@ -32,7 +32,7 @@ |
||
| 32 | 32 | |
| 33 | 33 | return ("`" . $this->name . "` " . ($this->short ? ("varchar(" . $this->length . ")") : "text")) . |
| 34 | 34 | |
| 35 | - (($this->binary ? " BINARY" : "") . " NOT NULL DEFAULT '" . $this->default . "'"); |
|
| 35 | + (($this->binary ? " BINARY" : "") . " NOT NULL DEFAULT '" . $this->default . "'"); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | /** |
@@ -30,9 +30,9 @@ |
||
| 30 | 30 | |
| 31 | 31 | public function getStatement() : string { |
| 32 | 32 | |
| 33 | - return ("`" . $this->name . "` " . ($this->short ? ("varchar(" . $this->length . ")") : "text")) . |
|
| 33 | + return ("`".$this->name."` ".($this->short ? ("varchar(".$this->length.")") : "text")). |
|
| 34 | 34 | |
| 35 | - (($this->binary ? " BINARY" : "") . " NOT NULL DEFAULT '" . $this->default . "'"); |
|
| 35 | + (($this->binary ? " BINARY" : "")." NOT NULL DEFAULT '".$this->default."'"); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | /** |
@@ -21,7 +21,9 @@ |
||
| 21 | 21 | |
| 22 | 22 | public function __construct(string $name, bool $short = true, int $length = 0, bool $binary = false, string $default = '') { |
| 23 | 23 | |
| 24 | - foreach (get_defined_vars() as $name => $value) $this->$name = $value; |
|
| 24 | + foreach (get_defined_vars() as $name => $value) { |
|
| 25 | + $this->$name = $value; |
|
| 26 | + } |
|
| 25 | 27 | } |
| 26 | 28 | |
| 27 | 29 | /** |
@@ -30,7 +30,7 @@ |
||
| 30 | 30 | |
| 31 | 31 | public function getStatement() : string { |
| 32 | 32 | |
| 33 | - return ("`" . $this->name . "` int(10) UNSIGNED NOT NULL" . ($this->auto_increment ? " AUTO_INCREMENT" : "")); |
|
| 33 | + return ("`".$this->name."` int(10) UNSIGNED NOT NULL".($this->auto_increment ? " AUTO_INCREMENT" : "")); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
@@ -19,7 +19,9 @@ |
||
| 19 | 19 | |
| 20 | 20 | public function add(string $name, string $table, string $field, string $delete = null, string $update = null) { |
| 21 | 21 | |
| 22 | - if ((false === $this->definition->getParam($name)) || isset($this->list[$name])) return; |
|
| 22 | + if ((false === $this->definition->getParam($name)) || isset($this->list[$name])) { |
|
| 23 | + return; |
|
| 24 | + } |
|
| 23 | 25 | |
| 24 | 26 | $this->list[$name] = new Definition\Item\Foreign($name, $table, $field, $delete, $update); |
| 25 | 27 | } |
@@ -30,7 +30,9 @@ |
||
| 30 | 30 | |
| 31 | 31 | public function add(string $name, string $type = null) { |
| 32 | 32 | |
| 33 | - if ((false === $this->definition->getParam($name)) || isset($this->list[$name])) return; |
|
| 33 | + if ((false === $this->definition->getParam($name)) || isset($this->list[$name])) { |
|
| 34 | + return; |
|
| 35 | + } |
|
| 34 | 36 | |
| 35 | 37 | $this->list[$name] = new Definition\Item\Index($name, $type); |
| 36 | 38 | } |
@@ -28,11 +28,15 @@ |
||
| 28 | 28 | |
| 29 | 29 | private function add(string $type, string $name, array $args) { |
| 30 | 30 | |
| 31 | - if (('' === $name) || isset($this->list[$name])) return; |
|
| 31 | + if (('' === $name) || isset($this->list[$name])) { |
|
| 32 | + return; |
|
| 33 | + } |
|
| 32 | 34 | |
| 33 | 35 | $this->list[$name] = new $this->types[$type](...$args); |
| 34 | 36 | |
| 35 | - if (($type !== 'textual') || $this->list[$name]->short) $this->secure[] = $name; |
|
| 37 | + if (($type !== 'textual') || $this->list[$name]->short) { |
|
| 38 | + $this->secure[] = $name; |
|
| 39 | + } |
|
| 36 | 40 | } |
| 37 | 41 | |
| 38 | 42 | /** |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | $selection = []; |
| 47 | 47 | |
| 48 | - foreach ($this->definition->getParamsSecure() as $field) $selection[] = ('ent.' . $field); |
|
| 48 | + foreach ($this->definition->getParamsSecure() as $field) $selection[] = ('ent.'.$field); |
|
| 49 | 49 | |
| 50 | 50 | # ------------------------ |
| 51 | 51 | |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | $order_by = []; |
| 62 | 62 | |
| 63 | - foreach ($this->castOrderBy($data) as $field => $direction) $order_by[] = ('ent.' . $field . ' ' . $direction); |
|
| 63 | + foreach ($this->castOrderBy($data) as $field => $direction) $order_by[] = ('ent.'.$field.' '.$direction); |
|
| 64 | 64 | |
| 65 | 65 | # ------------------------ |
| 66 | 66 | |
@@ -27,7 +27,9 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | foreach ($data as $field => $direction) { |
| 29 | 29 | |
| 30 | - if (false === ($param = $this->definition->getParam($field))) continue; |
|
| 30 | + if (false === ($param = $this->definition->getParam($field))) { |
|
| 31 | + continue; |
|
| 32 | + } |
|
| 31 | 33 | |
| 32 | 34 | $order_by[$param->name] = ((strtoupper($direction) !== 'DESC') ? 'ASC' : 'DESC'); |
| 33 | 35 | } |
@@ -45,7 +47,9 @@ discard block |
||
| 45 | 47 | |
| 46 | 48 | $selection = []; |
| 47 | 49 | |
| 48 | - foreach ($this->definition->getParamsSecure() as $field) $selection[] = ('ent.' . $field); |
|
| 50 | + foreach ($this->definition->getParamsSecure() as $field) { |
|
| 51 | + $selection[] = ('ent.' . $field); |
|
| 52 | + } |
|
| 49 | 53 | |
| 50 | 54 | # ------------------------ |
| 51 | 55 | |
@@ -60,7 +64,9 @@ discard block |
||
| 60 | 64 | |
| 61 | 65 | $order_by = []; |
| 62 | 66 | |
| 63 | - foreach ($this->castOrderBy($data) as $field => $direction) $order_by[] = ('ent.' . $field . ' ' . $direction); |
|
| 67 | + foreach ($this->castOrderBy($data) as $field => $direction) { |
|
| 68 | + $order_by[] = ('ent.' . $field . ' ' . $direction); |
|
| 69 | + } |
|
| 64 | 70 | |
| 65 | 71 | # ------------------------ |
| 66 | 72 | |
@@ -48,11 +48,11 @@ |
||
| 48 | 48 | |
| 49 | 49 | $query = ("SELECT " . implode(', ', $selection) . ", rel.ancestor as parent_id ") . |
| 50 | 50 | |
| 51 | - ("FROM " . static::$table . " ent ") . |
|
| 51 | + ("FROM " . static::$table . " ent ") . |
|
| 52 | 52 | |
| 53 | - ("LEFT JOIN " . static::$table_relations . " rel ON rel.descendant = ent.id AND rel.depth = 1 ") . |
|
| 53 | + ("LEFT JOIN " . static::$table_relations . " rel ON rel.descendant = ent.id AND rel.depth = 1 ") . |
|
| 54 | 54 | |
| 55 | - ("WHERE ent." . $name . " = '" . addslashes($value) . "' LIMIT 1"); |
|
| 55 | + ("WHERE ent." . $name . " = '" . addslashes($value) . "' LIMIT 1"); |
|
| 56 | 56 | |
| 57 | 57 | # ------------------------ |
| 58 | 58 | |
@@ -42,17 +42,17 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | $selection = array_keys($this->definition->getParams()); |
| 44 | 44 | |
| 45 | - foreach ($selection as $key => $field) $selection[$key] = ('ent.' . $field); |
|
| 45 | + foreach ($selection as $key => $field) $selection[$key] = ('ent.'.$field); |
|
| 46 | 46 | |
| 47 | 47 | # Process query |
| 48 | 48 | |
| 49 | - $query = ("SELECT " . implode(', ', $selection) . ", rel.ancestor as parent_id ") . |
|
| 49 | + $query = ("SELECT ".implode(', ', $selection).", rel.ancestor as parent_id "). |
|
| 50 | 50 | |
| 51 | - ("FROM " . static::$table . " ent ") . |
|
| 51 | + ("FROM ".static::$table." ent "). |
|
| 52 | 52 | |
| 53 | - ("LEFT JOIN " . static::$table_relations . " rel ON rel.descendant = ent.id AND rel.depth = 1 ") . |
|
| 53 | + ("LEFT JOIN ".static::$table_relations." rel ON rel.descendant = ent.id AND rel.depth = 1 "). |
|
| 54 | 54 | |
| 55 | - ("WHERE ent." . $name . " = '" . addslashes($value) . "' LIMIT 1"); |
|
| 55 | + ("WHERE ent.".$name." = '".addslashes($value)."' LIMIT 1"); |
|
| 56 | 56 | |
| 57 | 57 | # ------------------------ |
| 58 | 58 | |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | |
| 155 | 155 | # Select entity from DB |
| 156 | 156 | |
| 157 | - $condition = ($name . " = '" . addslashes($value) . "' AND id != " . $this->id); |
|
| 157 | + $condition = ($name." = '".addslashes($value)."' AND id != ".$this->id); |
|
| 158 | 158 | |
| 159 | 159 | DB::select(static::$table, 'id', $condition, null, 1); |
| 160 | 160 | |
@@ -42,7 +42,9 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | $selection = array_keys($this->definition->getParams()); |
| 44 | 44 | |
| 45 | - foreach ($selection as $key => $field) $selection[$key] = ('ent.' . $field); |
|
| 45 | + foreach ($selection as $key => $field) { |
|
| 46 | + $selection[$key] = ('ent.' . $field); |
|
| 47 | + } |
|
| 46 | 48 | |
| 47 | 49 | # Process query |
| 48 | 50 | |
@@ -112,13 +114,19 @@ discard block |
||
| 112 | 114 | |
| 113 | 115 | public function init($value, string $name = 'id') : bool { |
| 114 | 116 | |
| 115 | - if (0 !== $this->id) return false; |
|
| 117 | + if (0 !== $this->id) { |
|
| 118 | + return false; |
|
| 119 | + } |
|
| 116 | 120 | |
| 117 | 121 | # Get initiation index |
| 118 | 122 | |
| 119 | - if (false === ($index = $this->definition->getIndex($name))) return false; |
|
| 123 | + if (false === ($index = $this->definition->getIndex($name))) { |
|
| 124 | + return false; |
|
| 125 | + } |
|
| 120 | 126 | |
| 121 | - if (($index->type !== 'PRIMARY') && ($index->type !== 'UNIQUE')) return false; |
|
| 127 | + if (($index->type !== 'PRIMARY') && ($index->type !== 'UNIQUE')) { |
|
| 128 | + return false; |
|
| 129 | + } |
|
| 122 | 130 | |
| 123 | 131 | # Process name & value |
| 124 | 132 | |
@@ -126,7 +134,11 @@ discard block |
||
| 126 | 134 | |
| 127 | 135 | # Select entity from DB |
| 128 | 136 | |
| 129 | - if (!static::$nesting) $this->selectBasic($name, $value); else $this->selectNesting($name, $value); |
|
| 137 | + if (!static::$nesting) { |
|
| 138 | + $this->selectBasic($name, $value); |
|
| 139 | + } else { |
|
| 140 | + $this->selectNesting($name, $value); |
|
| 141 | + } |
|
| 130 | 142 | |
| 131 | 143 | # ------------------------ |
| 132 | 144 | |
@@ -144,9 +156,13 @@ discard block |
||
| 144 | 156 | |
| 145 | 157 | # Get initiation index |
| 146 | 158 | |
| 147 | - if (false === ($index = $this->definition->getIndex($name))) return false; |
|
| 159 | + if (false === ($index = $this->definition->getIndex($name))) { |
|
| 160 | + return false; |
|
| 161 | + } |
|
| 148 | 162 | |
| 149 | - if ($index->type !== 'UNIQUE') return false; |
|
| 163 | + if ($index->type !== 'UNIQUE') { |
|
| 164 | + return false; |
|
| 165 | + } |
|
| 150 | 166 | |
| 151 | 167 | # Process name & value |
| 152 | 168 | |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | /** |
| 63 | 63 | * Update the entity dataset with a selected data. Also updates every entity object having an identical id |
| 64 | 64 | * |
| 65 | - * @return true : always true ;) |
|
| 65 | + * @return boolean : always true ;) |
|
| 66 | 66 | */ |
| 67 | 67 | |
| 68 | 68 | protected function setData(array $data) : bool { |
@@ -137,6 +137,7 @@ discard block |
||
| 137 | 137 | * Check whether another entity with a given unique param value exists. |
| 138 | 138 | * This method is useful to find out is it possible to change the entity's unique param value to the given one |
| 139 | 139 | * |
| 140 | + * @param string $value |
|
| 140 | 141 | * @return int|false : the number of entities found (0 or 1) or false on error |
| 141 | 142 | */ |
| 142 | 143 | |
@@ -21,7 +21,9 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | protected function addVirtual(string $name, callable $virtual) { |
| 23 | 23 | |
| 24 | - if (isset($this->params[$name]) || isset($this->virtuals[$name])) return; |
|
| 24 | + if (isset($this->params[$name]) || isset($this->virtuals[$name])) { |
|
| 25 | + return; |
|
| 26 | + } |
|
| 25 | 27 | |
| 26 | 28 | $this->virtuals[$name] = $virtual; |
| 27 | 29 | } |
@@ -34,7 +36,9 @@ discard block |
||
| 34 | 36 | |
| 35 | 37 | $this->params = Entitizer::getDefinition(static::$table)->getParams(); |
| 36 | 38 | |
| 37 | - if (static::$nesting) $this->params['parent_id'] = $this->params['id']; |
|
| 39 | + if (static::$nesting) { |
|
| 40 | + $this->params['parent_id'] = $this->params['id']; |
|
| 41 | + } |
|
| 38 | 42 | |
| 39 | 43 | $this->init(); $this->reset(); |
| 40 | 44 | } |
@@ -49,11 +53,15 @@ discard block |
||
| 49 | 53 | |
| 50 | 54 | # Reset params |
| 51 | 55 | |
| 52 | - foreach ($this->params as $name => $param) $this->data[$name] = $param->cast(null); |
|
| 56 | + foreach ($this->params as $name => $param) { |
|
| 57 | + $this->data[$name] = $param->cast(null); |
|
| 58 | + } |
|
| 53 | 59 | |
| 54 | 60 | # Reset virtuals |
| 55 | 61 | |
| 56 | - foreach ($this->virtuals as $name => $virtual) $this->data[$name] = $virtual($this->data); |
|
| 62 | + foreach ($this->virtuals as $name => $virtual) { |
|
| 63 | + $this->data[$name] = $virtual($this->data); |
|
| 64 | + } |
|
| 57 | 65 | |
| 58 | 66 | # ------------------------ |
| 59 | 67 | |
@@ -72,12 +80,16 @@ discard block |
||
| 72 | 80 | |
| 73 | 81 | foreach ($data as $name => $value) { |
| 74 | 82 | |
| 75 | - if (isset($this->params[$name])) $this->data[$name] = $this->params[$name]->cast($value); |
|
| 83 | + if (isset($this->params[$name])) { |
|
| 84 | + $this->data[$name] = $this->params[$name]->cast($value); |
|
| 85 | + } |
|
| 76 | 86 | } |
| 77 | 87 | |
| 78 | 88 | # Update extras |
| 79 | 89 | |
| 80 | - foreach ($this->virtuals as $name => $virtual) $this->data[$name] = $virtual($this->data); |
|
| 90 | + foreach ($this->virtuals as $name => $virtual) { |
|
| 91 | + $this->data[$name] = $virtual($this->data); |
|
| 92 | + } |
|
| 81 | 93 | |
| 82 | 94 | # ------------------------ |
| 83 | 95 | |
@@ -94,7 +106,9 @@ discard block |
||
| 94 | 106 | |
| 95 | 107 | foreach ($data as $name => $value) { |
| 96 | 108 | |
| 97 | - if (isset($this->params[$name])) $cast[$name] = $this->params[$name]->cast($value); |
|
| 109 | + if (isset($this->params[$name])) { |
|
| 110 | + $cast[$name] = $this->params[$name]->cast($value); |
|
| 111 | + } |
|
| 98 | 112 | } |
| 99 | 113 | |
| 100 | 114 | # ------------------------ |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | return (0 !== $parent_id) ? (("JOIN " . static::$table_relations . " rel ") . |
| 23 | 23 | |
| 24 | - ("ON rel.ancestor = " . $parent_id . " AND rel.descendant = ent.id AND rel.depth >= 1")) : |
|
| 24 | + ("ON rel.ancestor = " . $parent_id . " AND rel.descendant = ent.id AND rel.depth >= 1")) : |
|
| 25 | 25 | |
| 26 | 26 | ("JOIN " . static::$table_relations . " rel ON rel.descendant = ent.id"); |
| 27 | 27 | } |
@@ -34,13 +34,13 @@ discard block |
||
| 34 | 34 | |
| 35 | 35 | return ("SELECT " . $this->getSelection() . ", COALESCE(par.ancestor, 0) as parent_id ") . |
| 36 | 36 | |
| 37 | - ("FROM " . static::$table . " ent " . $this->getQueryJoin($parent_id) . " ") . |
|
| 37 | + ("FROM " . static::$table . " ent " . $this->getQueryJoin($parent_id) . " ") . |
|
| 38 | 38 | |
| 39 | - ("LEFT JOIN " . static::$table_relations . " par ON par.descendant = ent.id AND par.depth = 1 ") . |
|
| 39 | + ("LEFT JOIN " . static::$table_relations . " par ON par.descendant = ent.id AND par.depth = 1 ") . |
|
| 40 | 40 | |
| 41 | - (('' !== ($condition = $this->getCondition($config))) ? ("WHERE " . $condition . " ") : "") . |
|
| 41 | + (('' !== ($condition = $this->getCondition($config))) ? ("WHERE " . $condition . " ") : "") . |
|
| 42 | 42 | |
| 43 | - ("GROUP BY ent.id ORDER BY MAX(rel.depth) ASC, " . $this->getOrderBy($order_by)); |
|
| 43 | + ("GROUP BY ent.id ORDER BY MAX(rel.depth) ASC, " . $this->getOrderBy($order_by)); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /** |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | |
| 52 | 52 | return ("SELECT COUNT(DISTINCT ent.id) as count FROM " . static::$table . " ent ") . |
| 53 | 53 | |
| 54 | - $this->getQueryJoin($parent_id); |
|
| 54 | + $this->getQueryJoin($parent_id); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | |
| 63 | 63 | $query = ("SELECT COUNT(DISTINCT rel.depth) as depth FROM " . static::$table . " ent ") . |
| 64 | 64 | |
| 65 | - $this->getQueryJoin($parent_id); |
|
| 65 | + $this->getQueryJoin($parent_id); |
|
| 66 | 66 | |
| 67 | 67 | # ------------------------ |
| 68 | 68 | |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | |
| 170 | 170 | $query = ("SELECT " . $this->getSelection() . " FROM " . static::$table . " ent ") . |
| 171 | 171 | |
| 172 | - ("JOIN " . static::$table_relations . " rel ON rel.ancestor = ent.id ") . |
|
| 172 | + ("JOIN " . static::$table_relations . " rel ON rel.ancestor = ent.id ") . |
|
| 173 | 173 | |
| 174 | 174 | ("WHERE rel.descendant = " . $parent_id . " ORDER BY rel.depth DESC"); |
| 175 | 175 | |
@@ -19,11 +19,9 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | protected function getQueryJoin(int $parent_id) : string { |
| 21 | 21 | |
| 22 | - return (0 !== $parent_id) ? (("JOIN " . static::$table_relations . " rel ") . |
|
| 22 | + return (0 !== $parent_id) ? (("JOIN ".static::$table_relations." rel "). |
|
| 23 | 23 | |
| 24 | - ("ON rel.ancestor = " . $parent_id . " AND rel.descendant = ent.id AND rel.depth >= 1")) : |
|
| 25 | - |
|
| 26 | - ("JOIN " . static::$table_relations . " rel ON rel.descendant = ent.id"); |
|
| 24 | + ("ON rel.ancestor = ".$parent_id." AND rel.descendant = ent.id AND rel.depth >= 1")) : ("JOIN ".static::$table_relations." rel ON rel.descendant = ent.id"); |
|
| 27 | 25 | } |
| 28 | 26 | |
| 29 | 27 | /** |
@@ -32,15 +30,15 @@ discard block |
||
| 32 | 30 | |
| 33 | 31 | private function getSelectQuery(int $parent_id, array $config, array $order_by) : string { |
| 34 | 32 | |
| 35 | - return ("SELECT " . $this->getSelection() . ", COALESCE(par.ancestor, 0) as parent_id ") . |
|
| 33 | + return ("SELECT ".$this->getSelection().", COALESCE(par.ancestor, 0) as parent_id "). |
|
| 36 | 34 | |
| 37 | - ("FROM " . static::$table . " ent " . $this->getQueryJoin($parent_id) . " ") . |
|
| 35 | + ("FROM ".static::$table." ent ".$this->getQueryJoin($parent_id)." "). |
|
| 38 | 36 | |
| 39 | - ("LEFT JOIN " . static::$table_relations . " par ON par.descendant = ent.id AND par.depth = 1 ") . |
|
| 37 | + ("LEFT JOIN ".static::$table_relations." par ON par.descendant = ent.id AND par.depth = 1 "). |
|
| 40 | 38 | |
| 41 | - (('' !== ($condition = $this->getCondition($config))) ? ("WHERE " . $condition . " ") : "") . |
|
| 39 | + (('' !== ($condition = $this->getCondition($config))) ? ("WHERE ".$condition." ") : ""). |
|
| 42 | 40 | |
| 43 | - ("GROUP BY ent.id ORDER BY MAX(rel.depth) ASC, " . $this->getOrderBy($order_by)); |
|
| 41 | + ("GROUP BY ent.id ORDER BY MAX(rel.depth) ASC, ".$this->getOrderBy($order_by)); |
|
| 44 | 42 | } |
| 45 | 43 | |
| 46 | 44 | /** |
@@ -49,7 +47,7 @@ discard block |
||
| 49 | 47 | |
| 50 | 48 | private function getCountQuery(int $parent_id) : string { |
| 51 | 49 | |
| 52 | - return ("SELECT COUNT(DISTINCT ent.id) as count FROM " . static::$table . " ent ") . |
|
| 50 | + return ("SELECT COUNT(DISTINCT ent.id) as count FROM ".static::$table." ent "). |
|
| 53 | 51 | |
| 54 | 52 | $this->getQueryJoin($parent_id); |
| 55 | 53 | } |
@@ -60,7 +58,7 @@ discard block |
||
| 60 | 58 | |
| 61 | 59 | private function getDepthQuery(int $parent_id) : string { |
| 62 | 60 | |
| 63 | - $query = ("SELECT COUNT(DISTINCT rel.depth) as depth FROM " . static::$table . " ent ") . |
|
| 61 | + $query = ("SELECT COUNT(DISTINCT rel.depth) as depth FROM ".static::$table." ent "). |
|
| 64 | 62 | |
| 65 | 63 | $this->getQueryJoin($parent_id); |
| 66 | 64 | |
@@ -167,11 +165,11 @@ discard block |
||
| 167 | 165 | |
| 168 | 166 | # Process query |
| 169 | 167 | |
| 170 | - $query = ("SELECT " . $this->getSelection() . " FROM " . static::$table . " ent ") . |
|
| 168 | + $query = ("SELECT ".$this->getSelection()." FROM ".static::$table." ent "). |
|
| 171 | 169 | |
| 172 | - ("JOIN " . static::$table_relations . " rel ON rel.ancestor = ent.id ") . |
|
| 170 | + ("JOIN ".static::$table_relations." rel ON rel.ancestor = ent.id "). |
|
| 173 | 171 | |
| 174 | - ("WHERE rel.descendant = " . $parent_id . " ORDER BY rel.depth DESC"); |
|
| 172 | + ("WHERE rel.descendant = ".$parent_id." ORDER BY rel.depth DESC"); |
|
| 175 | 173 | |
| 176 | 174 | # Select path |
| 177 | 175 | |
@@ -81,13 +81,17 @@ discard block |
||
| 81 | 81 | |
| 82 | 82 | public function getSubtree(int $parent_id = 0, array $config = [], array $order_by = []) { |
| 83 | 83 | |
| 84 | - if (!(static::$nesting && ($parent_id >= 0))) return false; |
|
| 84 | + if (!(static::$nesting && ($parent_id >= 0))) { |
|
| 85 | + return false; |
|
| 86 | + } |
|
| 85 | 87 | |
| 86 | 88 | # Select entities |
| 87 | 89 | |
| 88 | 90 | $query = $this->getSelectQuery($parent_id, $config, $order_by); |
| 89 | 91 | |
| 90 | - if (!(DB::send($query) && DB::getLast()->status)) return false; |
|
| 92 | + if (!(DB::send($query) && DB::getLast()->status)) { |
|
| 93 | + return false; |
|
| 94 | + } |
|
| 91 | 95 | |
| 92 | 96 | # Process results |
| 93 | 97 | |
@@ -117,13 +121,17 @@ discard block |
||
| 117 | 121 | |
| 118 | 122 | public function getSubtreeCount(int $parent_id = 0) { |
| 119 | 123 | |
| 120 | - if (!(static::$nesting && ($parent_id >= 0))) return false; |
|
| 124 | + if (!(static::$nesting && ($parent_id >= 0))) { |
|
| 125 | + return false; |
|
| 126 | + } |
|
| 121 | 127 | |
| 122 | 128 | # Get count |
| 123 | 129 | |
| 124 | 130 | $query = $this->getCountQuery($parent_id); |
| 125 | 131 | |
| 126 | - if (!(DB::send($query) && DB::getLast()->status)) return false; |
|
| 132 | + if (!(DB::send($query) && DB::getLast()->status)) { |
|
| 133 | + return false; |
|
| 134 | + } |
|
| 127 | 135 | |
| 128 | 136 | # ------------------------ |
| 129 | 137 | |
@@ -140,13 +148,17 @@ discard block |
||
| 140 | 148 | |
| 141 | 149 | public function getSubtreeDepth(int $parent_id = 0) { |
| 142 | 150 | |
| 143 | - if (!(static::$nesting && ($parent_id >= 0))) return false; |
|
| 151 | + if (!(static::$nesting && ($parent_id >= 0))) { |
|
| 152 | + return false; |
|
| 153 | + } |
|
| 144 | 154 | |
| 145 | 155 | # Get depth |
| 146 | 156 | |
| 147 | 157 | $query = $this->getDepthQuery($parent_id); |
| 148 | 158 | |
| 149 | - if (!(DB::send($query) && DB::getLast()->status)) return false; |
|
| 159 | + if (!(DB::send($query) && DB::getLast()->status)) { |
|
| 160 | + return false; |
|
| 161 | + } |
|
| 150 | 162 | |
| 151 | 163 | # ------------------------ |
| 152 | 164 | |
@@ -163,7 +175,9 @@ discard block |
||
| 163 | 175 | |
| 164 | 176 | public function getPath(int $parent_id = 0) { |
| 165 | 177 | |
| 166 | - if (!(static::$nesting && ($parent_id >= 0))) return false; |
|
| 178 | + if (!(static::$nesting && ($parent_id >= 0))) { |
|
| 179 | + return false; |
|
| 180 | + } |
|
| 167 | 181 | |
| 168 | 182 | # Process query |
| 169 | 183 | |
@@ -175,13 +189,17 @@ discard block |
||
| 175 | 189 | |
| 176 | 190 | # Select path |
| 177 | 191 | |
| 178 | - if (!(DB::send($query) && DB::getLast()->status)) return false; |
|
| 192 | + if (!(DB::send($query) && DB::getLast()->status)) { |
|
| 193 | + return false; |
|
| 194 | + } |
|
| 179 | 195 | |
| 180 | 196 | # Process results |
| 181 | 197 | |
| 182 | 198 | $path = []; |
| 183 | 199 | |
| 184 | - while (null !== ($data = DB::getLast()->getRow())) $path[] = Entitizer::getDataset(static::$table, $data)->getData(); |
|
| 200 | + while (null !== ($data = DB::getLast()->getRow())) { |
|
| 201 | + $path[] = Entitizer::getDataset(static::$table, $data)->getData(); |
|
| 202 | + } |
|
| 185 | 203 | |
| 186 | 204 | # ------------------------ |
| 187 | 205 | |