@@ -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 | |
@@ -21,13 +21,13 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | return ("SELECT SQL_CALC_FOUND_ROWS " . $this->getSelection() . " ") . |
| 23 | 23 | |
| 24 | - ("FROM " . static::$table . " ent ") . |
|
| 24 | + ("FROM " . static::$table . " ent ") . |
|
| 25 | 25 | |
| 26 | 26 | (('' !== ($condition = $this->getCondition($config))) ? ("WHERE " . $condition . " ") : "") . |
| 27 | 27 | |
| 28 | 28 | ("ORDER BY " . $this->getOrderBy($order_by) . " ") . |
| 29 | 29 | |
| 30 | - (($index > 0) ? ("LIMIT " . ((($index - 1) * $display) . ", " . $display)) : ""); |
|
| 30 | + (($index > 0) ? ("LIMIT " . ((($index - 1) * $display) . ", " . $display)) : ""); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
@@ -38,9 +38,9 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | return ("SELECT SQL_CALC_FOUND_ROWS " . $this->getSelection() . ", COUNT(chd.descendant) as children ") . |
| 40 | 40 | |
| 41 | - ("FROM " . static::$table . " ent ") . |
|
| 41 | + ("FROM " . static::$table . " ent ") . |
|
| 42 | 42 | |
| 43 | - ("LEFT JOIN " . static::$table_relations . " chd ON chd.ancestor = ent.id AND chd.depth = 1 ") . |
|
| 43 | + ("LEFT JOIN " . static::$table_relations . " chd ON chd.ancestor = ent.id AND chd.depth = 1 ") . |
|
| 44 | 44 | |
| 45 | 45 | ("LEFT JOIN " . static::$table_relations . " rel ON rel.descendant = ent.id AND rel.depth = 1 ") . |
| 46 | 46 | |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | ("GROUP BY ent.id ORDER BY " . $this->getOrderBy($order_by) . " ") . |
| 52 | 52 | |
| 53 | - (($index > 0) ? ("LIMIT " . ((($index - 1) * $display) . ", " . $display)) : ""); |
|
| 53 | + (($index > 0) ? ("LIMIT " . ((($index - 1) * $display) . ", " . $display)) : ""); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | |
| 62 | 62 | return ("SELECT COUNT(ent.id) as count FROM " . static::$table . " ent ") . |
| 63 | 63 | |
| 64 | - (('' !== ($condition = $this->getCondition($config))) ? ("WHERE " . $condition) : ""); |
|
| 64 | + (('' !== ($condition = $this->getCondition($config))) ? ("WHERE " . $condition) : ""); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -72,11 +72,11 @@ discard block |
||
| 72 | 72 | |
| 73 | 73 | return ("SELECT COUNT(ent.id) as count FROM " . static::$table . " ent ") . |
| 74 | 74 | |
| 75 | - ("LEFT JOIN " . static::$table_relations . " rel ON rel.descendant = ent.id AND rel.depth = 1 ") . |
|
| 75 | + ("LEFT JOIN " . static::$table_relations . " rel ON rel.descendant = ent.id AND rel.depth = 1 ") . |
|
| 76 | 76 | |
| 77 | - ("WHERE COALESCE(rel.ancestor, 0) = " . $parent_id . " ") . |
|
| 77 | + ("WHERE COALESCE(rel.ancestor, 0) = " . $parent_id . " ") . |
|
| 78 | 78 | |
| 79 | - (('' !== ($condition = $this->getCondition($config))) ? ("AND " . $condition) : ""); |
|
| 79 | + (('' !== ($condition = $this->getCondition($config))) ? ("AND " . $condition) : ""); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** |
@@ -19,15 +19,15 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | private function getBasicSelectQuery(array $config, array $order_by, int $index, int $display) : string { |
| 21 | 21 | |
| 22 | - return ("SELECT SQL_CALC_FOUND_ROWS " . $this->getSelection() . " ") . |
|
| 22 | + return ("SELECT SQL_CALC_FOUND_ROWS ".$this->getSelection()." "). |
|
| 23 | 23 | |
| 24 | - ("FROM " . static::$table . " ent ") . |
|
| 24 | + ("FROM ".static::$table." ent "). |
|
| 25 | 25 | |
| 26 | - (('' !== ($condition = $this->getCondition($config))) ? ("WHERE " . $condition . " ") : "") . |
|
| 26 | + (('' !== ($condition = $this->getCondition($config))) ? ("WHERE ".$condition." ") : ""). |
|
| 27 | 27 | |
| 28 | - ("ORDER BY " . $this->getOrderBy($order_by) . " ") . |
|
| 28 | + ("ORDER BY ".$this->getOrderBy($order_by)." "). |
|
| 29 | 29 | |
| 30 | - (($index > 0) ? ("LIMIT " . ((($index - 1) * $display) . ", " . $display)) : ""); |
|
| 30 | + (($index > 0) ? ("LIMIT ".((($index - 1) * $display).", ".$display)) : ""); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
@@ -36,21 +36,21 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | private function getNestingSelectQuery(int $parent_id, array $config, array $order_by, int $index, int $display) : string { |
| 38 | 38 | |
| 39 | - return ("SELECT SQL_CALC_FOUND_ROWS " . $this->getSelection() . ", COUNT(chd.descendant) as children ") . |
|
| 39 | + return ("SELECT SQL_CALC_FOUND_ROWS ".$this->getSelection().", COUNT(chd.descendant) as children "). |
|
| 40 | 40 | |
| 41 | - ("FROM " . static::$table . " ent ") . |
|
| 41 | + ("FROM ".static::$table." ent "). |
|
| 42 | 42 | |
| 43 | - ("LEFT JOIN " . static::$table_relations . " chd ON chd.ancestor = ent.id AND chd.depth = 1 ") . |
|
| 43 | + ("LEFT JOIN ".static::$table_relations." chd ON chd.ancestor = ent.id AND chd.depth = 1 "). |
|
| 44 | 44 | |
| 45 | - ("LEFT JOIN " . static::$table_relations . " rel ON rel.descendant = ent.id AND rel.depth = 1 ") . |
|
| 45 | + ("LEFT JOIN ".static::$table_relations." rel ON rel.descendant = ent.id AND rel.depth = 1 "). |
|
| 46 | 46 | |
| 47 | - ("WHERE COALESCE(rel.ancestor, 0) = " . $parent_id . " ") . |
|
| 47 | + ("WHERE COALESCE(rel.ancestor, 0) = ".$parent_id." "). |
|
| 48 | 48 | |
| 49 | - (('' !== ($condition = $this->getCondition($config))) ? ("AND " . $condition . " ") : "") . |
|
| 49 | + (('' !== ($condition = $this->getCondition($config))) ? ("AND ".$condition." ") : ""). |
|
| 50 | 50 | |
| 51 | - ("GROUP BY ent.id ORDER BY " . $this->getOrderBy($order_by) . " ") . |
|
| 51 | + ("GROUP BY ent.id ORDER BY ".$this->getOrderBy($order_by)." "). |
|
| 52 | 52 | |
| 53 | - (($index > 0) ? ("LIMIT " . ((($index - 1) * $display) . ", " . $display)) : ""); |
|
| 53 | + (($index > 0) ? ("LIMIT ".((($index - 1) * $display).", ".$display)) : ""); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
@@ -59,9 +59,9 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | private function getBasicCountQuery(array $config) : string { |
| 61 | 61 | |
| 62 | - return ("SELECT COUNT(ent.id) as count FROM " . static::$table . " ent ") . |
|
| 62 | + return ("SELECT COUNT(ent.id) as count FROM ".static::$table." ent "). |
|
| 63 | 63 | |
| 64 | - (('' !== ($condition = $this->getCondition($config))) ? ("WHERE " . $condition) : ""); |
|
| 64 | + (('' !== ($condition = $this->getCondition($config))) ? ("WHERE ".$condition) : ""); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -70,13 +70,13 @@ discard block |
||
| 70 | 70 | |
| 71 | 71 | private function getNestingCountQuery(int $parent_id, array $config) : string { |
| 72 | 72 | |
| 73 | - return ("SELECT COUNT(ent.id) as count FROM " . static::$table . " ent ") . |
|
| 73 | + return ("SELECT COUNT(ent.id) as count FROM ".static::$table." ent "). |
|
| 74 | 74 | |
| 75 | - ("LEFT JOIN " . static::$table_relations . " rel ON rel.descendant = ent.id AND rel.depth = 1 ") . |
|
| 75 | + ("LEFT JOIN ".static::$table_relations." rel ON rel.descendant = ent.id AND rel.depth = 1 "). |
|
| 76 | 76 | |
| 77 | - ("WHERE COALESCE(rel.ancestor, 0) = " . $parent_id . " ") . |
|
| 77 | + ("WHERE COALESCE(rel.ancestor, 0) = ".$parent_id." "). |
|
| 78 | 78 | |
| 79 | - (('' !== ($condition = $this->getCondition($config))) ? ("AND " . $condition) : ""); |
|
| 79 | + (('' !== ($condition = $this->getCondition($config))) ? ("AND ".$condition) : ""); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** |
@@ -93,9 +93,7 @@ discard block |
||
| 93 | 93 | |
| 94 | 94 | # Select entities |
| 95 | 95 | |
| 96 | - $query = ((null === $parent_id) ? $this->getBasicSelectQuery($config, $order_by, $index, $display) : |
|
| 97 | - |
|
| 98 | - $this->getNestingSelectQuery($parent_id, $config, $order_by, $index, $display)); |
|
| 96 | + $query = ((null === $parent_id) ? $this->getBasicSelectQuery($config, $order_by, $index, $display) : $this->getNestingSelectQuery($parent_id, $config, $order_by, $index, $display)); |
|
| 99 | 97 | |
| 100 | 98 | if (!(DB::send($query) && DB::getLast()->status)) return false; |
| 101 | 99 | |
@@ -136,9 +134,7 @@ discard block |
||
| 136 | 134 | |
| 137 | 135 | # Count entities |
| 138 | 136 | |
| 139 | - $query = ((null === $parent_id) ? $this->getBasicCountQuery($config) : |
|
| 140 | - |
|
| 141 | - $this->getNestingCountQuery($parent_id, $config)); |
|
| 137 | + $query = ((null === $parent_id) ? $this->getBasicCountQuery($config) : $this->getNestingCountQuery($parent_id, $config)); |
|
| 142 | 138 | |
| 143 | 139 | if (!(DB::send($query) && DB::getLast()->status)) return false; |
| 144 | 140 | |
@@ -87,9 +87,13 @@ discard block |
||
| 87 | 87 | |
| 88 | 88 | private function select(int $parent_id = null, array $config = [], array $order_by = [], int $index = 0, int $display = 0) { |
| 89 | 89 | |
| 90 | - if (!((null === $parent_id) || ($parent_id >= 0))) return false; |
|
| 90 | + if (!((null === $parent_id) || ($parent_id >= 0))) { |
|
| 91 | + return false; |
|
| 92 | + } |
|
| 91 | 93 | |
| 92 | - if (!(($index >= 0) && ($display >= 0))) return false; |
|
| 94 | + if (!(($index >= 0) && ($display >= 0))) { |
|
| 95 | + return false; |
|
| 96 | + } |
|
| 93 | 97 | |
| 94 | 98 | # Select entities |
| 95 | 99 | |
@@ -97,7 +101,9 @@ discard block |
||
| 97 | 101 | |
| 98 | 102 | $this->getNestingSelectQuery($parent_id, $config, $order_by, $index, $display)); |
| 99 | 103 | |
| 100 | - if (!(DB::send($query) && DB::getLast()->status)) return false; |
|
| 104 | + if (!(DB::send($query) && DB::getLast()->status)) { |
|
| 105 | + return false; |
|
| 106 | + } |
|
| 101 | 107 | |
| 102 | 108 | # Process results |
| 103 | 109 | |
@@ -109,7 +115,9 @@ discard block |
||
| 109 | 115 | |
| 110 | 116 | $items['list'][$dataset->id]['dataset'] = $dataset; |
| 111 | 117 | |
| 112 | - if (null !== $parent_id) $items['list'][$dataset->id]['children'] = intval($data['children']); |
|
| 118 | + if (null !== $parent_id) { |
|
| 119 | + $items['list'][$dataset->id]['children'] = intval($data['children']); |
|
| 120 | + } |
|
| 113 | 121 | } |
| 114 | 122 | |
| 115 | 123 | # Count total |
@@ -132,7 +140,9 @@ discard block |
||
| 132 | 140 | |
| 133 | 141 | private function count(int $parent_id = null, array $config = []) { |
| 134 | 142 | |
| 135 | - if (!((null === $parent_id) || ($parent_id >= 0))) return false; |
|
| 143 | + if (!((null === $parent_id) || ($parent_id >= 0))) { |
|
| 144 | + return false; |
|
| 145 | + } |
|
| 136 | 146 | |
| 137 | 147 | # Count entities |
| 138 | 148 | |
@@ -140,7 +150,9 @@ discard block |
||
| 140 | 150 | |
| 141 | 151 | $this->getNestingCountQuery($parent_id, $config)); |
| 142 | 152 | |
| 143 | - if (!(DB::send($query) && DB::getLast()->status)) return false; |
|
| 153 | + if (!(DB::send($query) && DB::getLast()->status)) { |
|
| 154 | + return false; |
|
| 155 | + } |
|
| 144 | 156 | |
| 145 | 157 | # ------------------------ |
| 146 | 158 | |
@@ -190,7 +202,9 @@ discard block |
||
| 190 | 202 | |
| 191 | 203 | public function getChildren(int $parent_id = 0, array $config = [], array $order_by = [], int $index = 0, int $display = 0) { |
| 192 | 204 | |
| 193 | - if (!static::$nesting) return false; |
|
| 205 | + if (!static::$nesting) { |
|
| 206 | + return false; |
|
| 207 | + } |
|
| 194 | 208 | |
| 195 | 209 | return $this->select($parent_id, $config, $order_by, $index, $display); |
| 196 | 210 | } |
@@ -206,7 +220,9 @@ discard block |
||
| 206 | 220 | |
| 207 | 221 | public function getChildrenCount(int $parent_id = 0, array $config = []) { |
| 208 | 222 | |
| 209 | - if (!static::$nesting) return false; |
|
| 223 | + if (!static::$nesting) { |
|
| 224 | + return false; |
|
| 225 | + } |
|
| 210 | 226 | |
| 211 | 227 | return $this->count($parent_id, $config); |
| 212 | 228 | } |
@@ -37,9 +37,9 @@ |
||
| 37 | 37 | |
| 38 | 38 | protected function processEntityParent(Template\Block $parent) { |
| 39 | 39 | |
| 40 | - if ((0 !== $this->parent->id) && $this->parent->active) $parent->getBlock('browse')->link = $this->parent->link; |
|
| 41 | - |
|
| 42 | - else { $parent->getBlock('browse')->disable(); $parent->getBlock('browse_disabled')->enable(); } |
|
| 40 | + if ((0 !== $this->parent->id) && $this->parent->active) { |
|
| 41 | + $parent->getBlock('browse')->link = $this->parent->link; |
|
| 42 | + } else { $parent->getBlock('browse')->disable(); $parent->getBlock('browse_disabled')->enable(); } |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | /** |