@@ -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 |