@@ -107,67 +107,67 @@ discard block |
||
107 | 107 | // DEPRECATED, only exist for unit testing vis-a-vis TightModelSelector |
108 | 108 | public static function query_retrieve($filters = [], $options = []): SelectInterface |
109 | 109 | { |
110 | - $class = get_called_class(); |
|
111 | - $table = $class::table(); |
|
110 | + $class = get_called_class(); |
|
111 | + $table = $class::table(); |
|
112 | 112 | |
113 | - $Query = $table->select(null, $class::table_alias()); |
|
113 | + $Query = $table->select(null, $class::table_alias()); |
|
114 | 114 | |
115 | 115 | |
116 | - if(!isset($options['eager']) || $options['eager'] !== false) |
|
117 | - { |
|
116 | + if(!isset($options['eager']) || $options['eager'] !== false) |
|
117 | + { |
|
118 | 118 | $Query->eager(); |
119 | - } |
|
119 | + } |
|
120 | 120 | |
121 | 121 | |
122 | - foreach($table->columns() as $column_name => $column) |
|
123 | - { |
|
122 | + foreach($table->columns() as $column_name => $column) |
|
123 | + { |
|
124 | 124 | if(isset($filters[$column_name]) && is_string($filters[$column_name])) |
125 | - $Query->aw_eq($column_name, $filters[$column_name]); |
|
126 | - } |
|
125 | + $Query->aw_eq($column_name, $filters[$column_name]); |
|
126 | + } |
|
127 | 127 | |
128 | - if(is_subclass_of($event = new $class(), '\HexMakina\kadro\Models\Interfaces\EventInterface')) |
|
129 | - { |
|
128 | + if(is_subclass_of($event = new $class(), '\HexMakina\kadro\Models\Interfaces\EventInterface')) |
|
129 | + { |
|
130 | 130 | if(!empty($filters['date_start'])) |
131 | - $Query->aw_gte($event->event_field(), $filters['date_start'], $Query->table_label(), ':filter_date_start'); |
|
131 | + $Query->aw_gte($event->event_field(), $filters['date_start'], $Query->table_label(), ':filter_date_start'); |
|
132 | 132 | |
133 | 133 | if(!empty($filters['date_stop'])) |
134 | - $Query->aw_lte($event->event_field(), $filters['date_stop'], $Query->table_label(), ':filter_date_stop'); |
|
134 | + $Query->aw_lte($event->event_field(), $filters['date_stop'], $Query->table_label(), ':filter_date_stop'); |
|
135 | 135 | |
136 | 136 | if(empty($options['order_by'])) |
137 | - $Query->order_by([$event->event_field(), 'DESC']); |
|
138 | - } |
|
137 | + $Query->order_by([$event->event_field(), 'DESC']); |
|
138 | + } |
|
139 | 139 | |
140 | - if(isset($filters['content'])) $Query->aw_filter_content($filters['content']); |
|
140 | + if(isset($filters['content'])) $Query->aw_filter_content($filters['content']); |
|
141 | 141 | |
142 | - if(isset($filters['ids'])) |
|
143 | - { |
|
142 | + if(isset($filters['ids'])) |
|
143 | + { |
|
144 | 144 | if(empty($filters['ids'])) |
145 | - $Query->and_where('1=0'); // TODO: this is a new low.. find another way to cancel query |
|
145 | + $Query->and_where('1=0'); // TODO: this is a new low.. find another way to cancel query |
|
146 | 146 | else $Query->aw_numeric_in('id', $filters['ids'], $Query->table_label()); |
147 | - } |
|
147 | + } |
|
148 | 148 | |
149 | - if(isset($options['order_by'])) // TODO commenting required about the array situation |
|
150 | - { |
|
149 | + if(isset($options['order_by'])) // TODO commenting required about the array situation |
|
150 | + { |
|
151 | 151 | $order_by = $options['order_by']; |
152 | 152 | |
153 | 153 | if(is_string($order_by)) |
154 | - $Query->order_by($order_by); |
|
154 | + $Query->order_by($order_by); |
|
155 | 155 | |
156 | 156 | elseif(is_array($order_by)) |
157 | - foreach($options['order_by'] as $order_by) |
|
158 | - { |
|
157 | + foreach($options['order_by'] as $order_by) |
|
158 | + { |
|
159 | 159 | if(!isset($order_by[2])) |
160 | - array_unshift($order_by, ''); |
|
160 | + array_unshift($order_by, ''); |
|
161 | 161 | |
162 | 162 | list($order_table, $order_field, $order_direction) = $order_by; |
163 | 163 | $Query->order_by([$order_table ?? '', $order_field, $order_direction]); |
164 | - } |
|
165 | - } |
|
164 | + } |
|
165 | + } |
|
166 | 166 | |
167 | - if(isset($options['limit']) && is_array($options['limit'])) |
|
167 | + if(isset($options['limit']) && is_array($options['limit'])) |
|
168 | 168 | $Query->limit($options['limit'][1], $options['limit'][0]); |
169 | 169 | |
170 | - return $Query; |
|
170 | + return $Query; |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | |
192 | 192 | if ($Query->is_success()) { |
193 | 193 | foreach ($Query->ret_obj(get_called_class()) as $rec) { |
194 | - $ret[$rec->get($pk_name)] = $rec; |
|
194 | + $ret[$rec->get($pk_name)] = $rec; |
|
195 | 195 | } |
196 | 196 | } |
197 | 197 |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | public function import($assoc_data) |
46 | 46 | { |
47 | 47 | if (!is_array($assoc_data)) { |
48 | - throw new \Exception(__FUNCTION__ . '(assoc_data) parm is not an array'); |
|
48 | + throw new \Exception(__FUNCTION__.'(assoc_data) parm is not an array'); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | // shove it all up in model, god will sort them out |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | |
73 | 73 | if ($table_name === false) { |
74 | 74 | $calling_class = $reflect->getShortName(); |
75 | - if (defined($const_name = 'TABLE_' . strtoupper($calling_class))) { |
|
75 | + if (defined($const_name = 'TABLE_'.strtoupper($calling_class))) { |
|
76 | 76 | $table_name = constant($const_name); |
77 | 77 | } else { |
78 | 78 | $table_name = strtolower($calling_class); |
@@ -113,50 +113,50 @@ discard block |
||
113 | 113 | $Query = $table->select(null, $class::table_alias()); |
114 | 114 | |
115 | 115 | |
116 | - if(!isset($options['eager']) || $options['eager'] !== false) |
|
116 | + if (!isset($options['eager']) || $options['eager'] !== false) |
|
117 | 117 | { |
118 | 118 | $Query->eager(); |
119 | 119 | } |
120 | 120 | |
121 | 121 | |
122 | - foreach($table->columns() as $column_name => $column) |
|
122 | + foreach ($table->columns() as $column_name => $column) |
|
123 | 123 | { |
124 | - if(isset($filters[$column_name]) && is_string($filters[$column_name])) |
|
124 | + if (isset($filters[$column_name]) && is_string($filters[$column_name])) |
|
125 | 125 | $Query->aw_eq($column_name, $filters[$column_name]); |
126 | 126 | } |
127 | 127 | |
128 | - if(is_subclass_of($event = new $class(), '\HexMakina\kadro\Models\Interfaces\EventInterface')) |
|
128 | + if (is_subclass_of($event = new $class(), '\HexMakina\kadro\Models\Interfaces\EventInterface')) |
|
129 | 129 | { |
130 | - if(!empty($filters['date_start'])) |
|
130 | + if (!empty($filters['date_start'])) |
|
131 | 131 | $Query->aw_gte($event->event_field(), $filters['date_start'], $Query->table_label(), ':filter_date_start'); |
132 | 132 | |
133 | - if(!empty($filters['date_stop'])) |
|
133 | + if (!empty($filters['date_stop'])) |
|
134 | 134 | $Query->aw_lte($event->event_field(), $filters['date_stop'], $Query->table_label(), ':filter_date_stop'); |
135 | 135 | |
136 | - if(empty($options['order_by'])) |
|
136 | + if (empty($options['order_by'])) |
|
137 | 137 | $Query->order_by([$event->event_field(), 'DESC']); |
138 | 138 | } |
139 | 139 | |
140 | - if(isset($filters['content'])) $Query->aw_filter_content($filters['content']); |
|
140 | + if (isset($filters['content'])) $Query->aw_filter_content($filters['content']); |
|
141 | 141 | |
142 | - if(isset($filters['ids'])) |
|
142 | + if (isset($filters['ids'])) |
|
143 | 143 | { |
144 | - if(empty($filters['ids'])) |
|
144 | + if (empty($filters['ids'])) |
|
145 | 145 | $Query->and_where('1=0'); // TODO: this is a new low.. find another way to cancel query |
146 | 146 | else $Query->aw_numeric_in('id', $filters['ids'], $Query->table_label()); |
147 | 147 | } |
148 | 148 | |
149 | - if(isset($options['order_by'])) // TODO commenting required about the array situation |
|
149 | + if (isset($options['order_by'])) // TODO commenting required about the array situation |
|
150 | 150 | { |
151 | 151 | $order_by = $options['order_by']; |
152 | 152 | |
153 | - if(is_string($order_by)) |
|
153 | + if (is_string($order_by)) |
|
154 | 154 | $Query->order_by($order_by); |
155 | 155 | |
156 | - elseif(is_array($order_by)) |
|
157 | - foreach($options['order_by'] as $order_by) |
|
156 | + elseif (is_array($order_by)) |
|
157 | + foreach ($options['order_by'] as $order_by) |
|
158 | 158 | { |
159 | - if(!isset($order_by[2])) |
|
159 | + if (!isset($order_by[2])) |
|
160 | 160 | array_unshift($order_by, ''); |
161 | 161 | |
162 | 162 | list($order_table, $order_field, $order_direction) = $order_by; |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | } |
165 | 165 | } |
166 | 166 | |
167 | - if(isset($options['limit']) && is_array($options['limit'])) |
|
167 | + if (isset($options['limit']) && is_array($options['limit'])) |
|
168 | 168 | $Query->limit($options['limit'][1], $options['limit'][0]); |
169 | 169 | |
170 | 170 | return $Query; |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | $ret = []; |
179 | 179 | $pk_name = implode('_', array_keys($Query->table()->primary_keys())); |
180 | 180 | |
181 | - if (count($pks = $Query->table()->primary_keys()) > 1) { |
|
181 | + if (count($pks = $Query->table()->primary_keys())>1) { |
|
182 | 182 | $concat_pk = sprintf('CONCAT(%s) as %s', implode(',', $pks), $pk_name); |
183 | 183 | $Query->select_also([$concat_pk]); |
184 | 184 | } |
@@ -121,51 +121,64 @@ |
||
121 | 121 | |
122 | 122 | foreach($table->columns() as $column_name => $column) |
123 | 123 | { |
124 | - if(isset($filters[$column_name]) && is_string($filters[$column_name])) |
|
125 | - $Query->aw_eq($column_name, $filters[$column_name]); |
|
124 | + if(isset($filters[$column_name]) && is_string($filters[$column_name])) { |
|
125 | + $Query->aw_eq($column_name, $filters[$column_name]); |
|
126 | + } |
|
126 | 127 | } |
127 | 128 | |
128 | 129 | if(is_subclass_of($event = new $class(), '\HexMakina\kadro\Models\Interfaces\EventInterface')) |
129 | 130 | { |
130 | - if(!empty($filters['date_start'])) |
|
131 | - $Query->aw_gte($event->event_field(), $filters['date_start'], $Query->table_label(), ':filter_date_start'); |
|
131 | + if(!empty($filters['date_start'])) { |
|
132 | + $Query->aw_gte($event->event_field(), $filters['date_start'], $Query->table_label(), ':filter_date_start'); |
|
133 | + } |
|
132 | 134 | |
133 | - if(!empty($filters['date_stop'])) |
|
134 | - $Query->aw_lte($event->event_field(), $filters['date_stop'], $Query->table_label(), ':filter_date_stop'); |
|
135 | + if(!empty($filters['date_stop'])) { |
|
136 | + $Query->aw_lte($event->event_field(), $filters['date_stop'], $Query->table_label(), ':filter_date_stop'); |
|
137 | + } |
|
135 | 138 | |
136 | - if(empty($options['order_by'])) |
|
137 | - $Query->order_by([$event->event_field(), 'DESC']); |
|
139 | + if(empty($options['order_by'])) { |
|
140 | + $Query->order_by([$event->event_field(), 'DESC']); |
|
141 | + } |
|
138 | 142 | } |
139 | 143 | |
140 | - if(isset($filters['content'])) $Query->aw_filter_content($filters['content']); |
|
144 | + if(isset($filters['content'])) { |
|
145 | + $Query->aw_filter_content($filters['content']); |
|
146 | + } |
|
141 | 147 | |
142 | 148 | if(isset($filters['ids'])) |
143 | 149 | { |
144 | - if(empty($filters['ids'])) |
|
145 | - $Query->and_where('1=0'); // TODO: this is a new low.. find another way to cancel query |
|
146 | - else $Query->aw_numeric_in('id', $filters['ids'], $Query->table_label()); |
|
150 | + if(empty($filters['ids'])) { |
|
151 | + $Query->and_where('1=0'); |
|
152 | + } |
|
153 | + // TODO: this is a new low.. find another way to cancel query |
|
154 | + else { |
|
155 | + $Query->aw_numeric_in('id', $filters['ids'], $Query->table_label()); |
|
156 | + } |
|
147 | 157 | } |
148 | 158 | |
149 | - if(isset($options['order_by'])) // TODO commenting required about the array situation |
|
159 | + if(isset($options['order_by'])) { |
|
160 | + // TODO commenting required about the array situation |
|
150 | 161 | { |
151 | 162 | $order_by = $options['order_by']; |
163 | + } |
|
152 | 164 | |
153 | - if(is_string($order_by)) |
|
154 | - $Query->order_by($order_by); |
|
155 | - |
|
156 | - elseif(is_array($order_by)) |
|
157 | - foreach($options['order_by'] as $order_by) |
|
165 | + if(is_string($order_by)) { |
|
166 | + $Query->order_by($order_by); |
|
167 | + } elseif(is_array($order_by)) { |
|
168 | + foreach($options['order_by'] as $order_by) |
|
158 | 169 | { |
159 | 170 | if(!isset($order_by[2])) |
160 | 171 | array_unshift($order_by, ''); |
172 | + } |
|
161 | 173 | |
162 | 174 | list($order_table, $order_field, $order_direction) = $order_by; |
163 | 175 | $Query->order_by([$order_table ?? '', $order_field, $order_direction]); |
164 | 176 | } |
165 | 177 | } |
166 | 178 | |
167 | - if(isset($options['limit']) && is_array($options['limit'])) |
|
168 | - $Query->limit($options['limit'][1], $options['limit'][0]); |
|
179 | + if(isset($options['limit']) && is_array($options['limit'])) { |
|
180 | + $Query->limit($options['limit'][1], $options['limit'][0]); |
|
181 | + } |
|
169 | 182 | |
170 | 183 | return $Query; |
171 | 184 | } |