@@ -96,9 +96,9 @@ |
||
96 | 96 | if (!empty($date_stop)) { |
97 | 97 | $this->statement()->aw_lte($this->model()->event_field(), $date_stop, $this->statement()->table_label(), ':filter_date_stop'); |
98 | 98 | } |
99 | - // |
|
100 | - // if(empty($options['order_by'])) |
|
101 | - // $this->statement()->order_by([$this->model()->event_field(), 'DESC']); |
|
99 | + // |
|
100 | + // if(empty($options['order_by'])) |
|
101 | + // $this->statement()->order_by([$this->model()->event_field(), 'DESC']); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | public function filter_with_ids($ids) |
@@ -67,7 +67,7 @@ |
||
67 | 67 | public static function otm($k = null) |
68 | 68 | { |
69 | 69 | $type = static::model_type(); |
70 | - $d = ['t' => $type . 's_models', 'k' => $type . '_id', 'a' => $type . 's_otm']; |
|
70 | + $d = ['t' => $type.'s_models', 'k' => $type.'_id', 'a' => $type.'s_otm']; |
|
71 | 71 | return is_null($k) ? $d : $d[$k]; |
72 | 72 | } |
73 | 73 | } |
@@ -266,7 +266,7 @@ |
||
266 | 266 | |
267 | 267 | if ($Query->is_success()) { |
268 | 268 | foreach ($Query->ret_obj(get_called_class()) as $rec) { |
269 | - $ret[$rec->get($pk_name)] = $rec; |
|
269 | + $ret[$rec->get($pk_name)] = $rec; |
|
270 | 270 | } |
271 | 271 | } |
272 | 272 |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | public function import($assoc_data) |
43 | 43 | { |
44 | 44 | if (!is_array($assoc_data)) { |
45 | - throw new \Exception(__FUNCTION__ . '(assoc_data) parm is not an array'); |
|
45 | + throw new \Exception(__FUNCTION__.'(assoc_data) parm is not an array'); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | // shove it all up in model, god will sort them out |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | |
70 | 70 | if ($table_name === false) { |
71 | 71 | $calling_class = $reflect->getShortName(); |
72 | - if (defined($const_name = 'TABLE_' . strtoupper($calling_class))) { |
|
72 | + if (defined($const_name = 'TABLE_'.strtoupper($calling_class))) { |
|
73 | 73 | $table_name = constant($const_name); |
74 | 74 | } else { |
75 | 75 | $table_name = strtolower($calling_class); |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | $ret = []; |
115 | 115 | $pk_name = implode('_', array_keys($Query->table()->primary_keys())); |
116 | 116 | |
117 | - if (count($pks = $Query->table()->primary_keys()) > 1) { |
|
117 | + if (count($pks = $Query->table()->primary_keys())>1) { |
|
118 | 118 | $concat_pk = sprintf('CONCAT(%s) as %s', implode(',', $pks), $pk_name); |
119 | 119 | $Query->select_also([$concat_pk]); |
120 | 120 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | |
13 | 13 | public function __toString() |
14 | 14 | { |
15 | - return static::class_short_name() . ' #' . $this->get_id(); |
|
15 | + return static::class_short_name().' #'.$this->get_id(); |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | public function immortal(): bool |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | |
27 | 27 | $extraction_table = $extraction_class::table(); |
28 | 28 | foreach ($extraction_table->columns() as $column_name => $column) { |
29 | - $probe_name = $extraction_class::table_alias() . '_' . $column_name; |
|
29 | + $probe_name = $extraction_class::table_alias().'_'.$column_name; |
|
30 | 30 | |
31 | 31 | if (!is_null($probe_res = $this->get($probe_name))) { |
32 | 32 | $extract_model->set($column_name, $probe_res); |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | */ |
186 | 186 | public static function table_alias(): string |
187 | 187 | { |
188 | - return defined(get_called_class() . '::TABLE_ALIAS') ? static::TABLE_ALIAS : static::model_type(); |
|
188 | + return defined(get_called_class().'::TABLE_ALIAS') ? static::TABLE_ALIAS : static::model_type(); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | public static function class_short_name() |
@@ -7,15 +7,15 @@ discard block |
||
7 | 7 | |
8 | 8 | class TableModelSelector |
9 | 9 | { |
10 | - private $model; |
|
10 | + private $model; |
|
11 | 11 | |
12 | - public function __construct(ModelInterface $m) |
|
13 | - { |
|
14 | - $this->model = $m; |
|
15 | - } |
|
12 | + public function __construct(ModelInterface $m) |
|
13 | + { |
|
14 | + $this->model = $m; |
|
15 | + } |
|
16 | 16 | |
17 | - public function select($filters = [], $options = []): SelectInterface |
|
18 | - { |
|
17 | + public function select($filters = [], $options = []): SelectInterface |
|
18 | + { |
|
19 | 19 | $class = get_class($this->model); |
20 | 20 | $table = $class::table(); |
21 | 21 | |
@@ -24,25 +24,25 @@ discard block |
||
24 | 24 | |
25 | 25 | if(!isset($options['eager']) || $options['eager'] !== false) |
26 | 26 | { |
27 | - $Query->eager(); |
|
27 | + $Query->eager(); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | |
31 | 31 | foreach($table->columns() as $column_name => $column) |
32 | 32 | { |
33 | - if(isset($filters[$column_name]) && is_string($filters[$column_name])) |
|
33 | + if(isset($filters[$column_name]) && is_string($filters[$column_name])) |
|
34 | 34 | $Query->aw_eq($column_name, $filters[$column_name]); |
35 | 35 | } |
36 | 36 | |
37 | 37 | if(is_subclass_of($event = new $class(), '\HexMakina\kadro\Models\Interfaces\EventInterface')) |
38 | 38 | { |
39 | - if(!empty($filters['date_start'])) |
|
39 | + if(!empty($filters['date_start'])) |
|
40 | 40 | $Query->aw_gte($event->event_field(), $filters['date_start'], $Query->table_label(), ':filter_date_start'); |
41 | 41 | |
42 | - if(!empty($filters['date_stop'])) |
|
42 | + if(!empty($filters['date_stop'])) |
|
43 | 43 | $Query->aw_lte($event->event_field(), $filters['date_stop'], $Query->table_label(), ':filter_date_stop'); |
44 | 44 | |
45 | - if(empty($options['order_by'])) |
|
45 | + if(empty($options['order_by'])) |
|
46 | 46 | $Query->order_by([$event->event_field(), 'DESC']); |
47 | 47 | } |
48 | 48 | |
@@ -50,32 +50,32 @@ discard block |
||
50 | 50 | |
51 | 51 | if(isset($filters['ids'])) |
52 | 52 | { |
53 | - if(empty($filters['ids'])) |
|
53 | + if(empty($filters['ids'])) |
|
54 | 54 | $Query->and_where('1=0'); // TODO: this is a new low.. find another way to cancel query |
55 | - else $Query->aw_numeric_in('id', $filters['ids'], $Query->table_label()); |
|
55 | + else $Query->aw_numeric_in('id', $filters['ids'], $Query->table_label()); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | if(isset($options['order_by'])) // TODO commenting required about the array situation |
59 | 59 | { |
60 | - $order_by = $options['order_by']; |
|
60 | + $order_by = $options['order_by']; |
|
61 | 61 | |
62 | - if(is_string($order_by)) |
|
62 | + if(is_string($order_by)) |
|
63 | 63 | $Query->order_by($order_by); |
64 | 64 | |
65 | - elseif(is_array($order_by)) |
|
65 | + elseif(is_array($order_by)) |
|
66 | 66 | foreach($options['order_by'] as $order_by) |
67 | 67 | { |
68 | - if(!isset($order_by[2])) |
|
68 | + if(!isset($order_by[2])) |
|
69 | 69 | array_unshift($order_by, ''); |
70 | 70 | |
71 | - list($order_table, $order_field, $order_direction) = $order_by; |
|
72 | - $Query->order_by([$order_table ?? '', $order_field, $order_direction]); |
|
71 | + list($order_table, $order_field, $order_direction) = $order_by; |
|
72 | + $Query->order_by([$order_table ?? '', $order_field, $order_direction]); |
|
73 | 73 | } |
74 | 74 | } |
75 | 75 | |
76 | 76 | if(isset($options['limit']) && is_array($options['limit'])) |
77 | - $Query->limit($options['limit'][1], $options['limit'][0]); |
|
77 | + $Query->limit($options['limit'][1], $options['limit'][0]); |
|
78 | 78 | |
79 | 79 | return $Query; |
80 | - } |
|
80 | + } |
|
81 | 81 | } |
@@ -22,50 +22,50 @@ discard block |
||
22 | 22 | $Query = $table->select(null, $class::table_alias()); |
23 | 23 | |
24 | 24 | |
25 | - if(!isset($options['eager']) || $options['eager'] !== false) |
|
25 | + if (!isset($options['eager']) || $options['eager'] !== false) |
|
26 | 26 | { |
27 | 27 | $Query->eager(); |
28 | 28 | } |
29 | 29 | |
30 | 30 | |
31 | - foreach($table->columns() as $column_name => $column) |
|
31 | + foreach ($table->columns() as $column_name => $column) |
|
32 | 32 | { |
33 | - if(isset($filters[$column_name]) && is_string($filters[$column_name])) |
|
33 | + if (isset($filters[$column_name]) && is_string($filters[$column_name])) |
|
34 | 34 | $Query->aw_eq($column_name, $filters[$column_name]); |
35 | 35 | } |
36 | 36 | |
37 | - if(is_subclass_of($event = new $class(), '\HexMakina\kadro\Models\Interfaces\EventInterface')) |
|
37 | + if (is_subclass_of($event = new $class(), '\HexMakina\kadro\Models\Interfaces\EventInterface')) |
|
38 | 38 | { |
39 | - if(!empty($filters['date_start'])) |
|
39 | + if (!empty($filters['date_start'])) |
|
40 | 40 | $Query->aw_gte($event->event_field(), $filters['date_start'], $Query->table_label(), ':filter_date_start'); |
41 | 41 | |
42 | - if(!empty($filters['date_stop'])) |
|
42 | + if (!empty($filters['date_stop'])) |
|
43 | 43 | $Query->aw_lte($event->event_field(), $filters['date_stop'], $Query->table_label(), ':filter_date_stop'); |
44 | 44 | |
45 | - if(empty($options['order_by'])) |
|
45 | + if (empty($options['order_by'])) |
|
46 | 46 | $Query->order_by([$event->event_field(), 'DESC']); |
47 | 47 | } |
48 | 48 | |
49 | - if(isset($filters['content'])) $Query->aw_filter_content($filters['content']); |
|
49 | + if (isset($filters['content'])) $Query->aw_filter_content($filters['content']); |
|
50 | 50 | |
51 | - if(isset($filters['ids'])) |
|
51 | + if (isset($filters['ids'])) |
|
52 | 52 | { |
53 | - if(empty($filters['ids'])) |
|
53 | + if (empty($filters['ids'])) |
|
54 | 54 | $Query->and_where('1=0'); // TODO: this is a new low.. find another way to cancel query |
55 | 55 | else $Query->aw_numeric_in('id', $filters['ids'], $Query->table_label()); |
56 | 56 | } |
57 | 57 | |
58 | - if(isset($options['order_by'])) // TODO commenting required about the array situation |
|
58 | + if (isset($options['order_by'])) // TODO commenting required about the array situation |
|
59 | 59 | { |
60 | 60 | $order_by = $options['order_by']; |
61 | 61 | |
62 | - if(is_string($order_by)) |
|
62 | + if (is_string($order_by)) |
|
63 | 63 | $Query->order_by($order_by); |
64 | 64 | |
65 | - elseif(is_array($order_by)) |
|
66 | - foreach($options['order_by'] as $order_by) |
|
65 | + elseif (is_array($order_by)) |
|
66 | + foreach ($options['order_by'] as $order_by) |
|
67 | 67 | { |
68 | - if(!isset($order_by[2])) |
|
68 | + if (!isset($order_by[2])) |
|
69 | 69 | array_unshift($order_by, ''); |
70 | 70 | |
71 | 71 | list($order_table, $order_field, $order_direction) = $order_by; |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | } |
74 | 74 | } |
75 | 75 | |
76 | - if(isset($options['limit']) && is_array($options['limit'])) |
|
76 | + if (isset($options['limit']) && is_array($options['limit'])) |
|
77 | 77 | $Query->limit($options['limit'][1], $options['limit'][0]); |
78 | 78 | |
79 | 79 | return $Query; |
@@ -30,51 +30,64 @@ |
||
30 | 30 | |
31 | 31 | foreach($table->columns() as $column_name => $column) |
32 | 32 | { |
33 | - if(isset($filters[$column_name]) && is_string($filters[$column_name])) |
|
34 | - $Query->aw_eq($column_name, $filters[$column_name]); |
|
33 | + if(isset($filters[$column_name]) && is_string($filters[$column_name])) { |
|
34 | + $Query->aw_eq($column_name, $filters[$column_name]); |
|
35 | + } |
|
35 | 36 | } |
36 | 37 | |
37 | 38 | if(is_subclass_of($event = new $class(), '\HexMakina\kadro\Models\Interfaces\EventInterface')) |
38 | 39 | { |
39 | - if(!empty($filters['date_start'])) |
|
40 | - $Query->aw_gte($event->event_field(), $filters['date_start'], $Query->table_label(), ':filter_date_start'); |
|
40 | + if(!empty($filters['date_start'])) { |
|
41 | + $Query->aw_gte($event->event_field(), $filters['date_start'], $Query->table_label(), ':filter_date_start'); |
|
42 | + } |
|
41 | 43 | |
42 | - if(!empty($filters['date_stop'])) |
|
43 | - $Query->aw_lte($event->event_field(), $filters['date_stop'], $Query->table_label(), ':filter_date_stop'); |
|
44 | + if(!empty($filters['date_stop'])) { |
|
45 | + $Query->aw_lte($event->event_field(), $filters['date_stop'], $Query->table_label(), ':filter_date_stop'); |
|
46 | + } |
|
44 | 47 | |
45 | - if(empty($options['order_by'])) |
|
46 | - $Query->order_by([$event->event_field(), 'DESC']); |
|
48 | + if(empty($options['order_by'])) { |
|
49 | + $Query->order_by([$event->event_field(), 'DESC']); |
|
50 | + } |
|
47 | 51 | } |
48 | 52 | |
49 | - if(isset($filters['content'])) $Query->aw_filter_content($filters['content']); |
|
53 | + if(isset($filters['content'])) { |
|
54 | + $Query->aw_filter_content($filters['content']); |
|
55 | + } |
|
50 | 56 | |
51 | 57 | if(isset($filters['ids'])) |
52 | 58 | { |
53 | - if(empty($filters['ids'])) |
|
54 | - $Query->and_where('1=0'); // TODO: this is a new low.. find another way to cancel query |
|
55 | - else $Query->aw_numeric_in('id', $filters['ids'], $Query->table_label()); |
|
59 | + if(empty($filters['ids'])) { |
|
60 | + $Query->and_where('1=0'); |
|
61 | + } |
|
62 | + // TODO: this is a new low.. find another way to cancel query |
|
63 | + else { |
|
64 | + $Query->aw_numeric_in('id', $filters['ids'], $Query->table_label()); |
|
65 | + } |
|
56 | 66 | } |
57 | 67 | |
58 | - if(isset($options['order_by'])) // TODO commenting required about the array situation |
|
68 | + if(isset($options['order_by'])) { |
|
69 | + // TODO commenting required about the array situation |
|
59 | 70 | { |
60 | 71 | $order_by = $options['order_by']; |
72 | + } |
|
61 | 73 | |
62 | - if(is_string($order_by)) |
|
63 | - $Query->order_by($order_by); |
|
64 | - |
|
65 | - elseif(is_array($order_by)) |
|
66 | - foreach($options['order_by'] as $order_by) |
|
74 | + if(is_string($order_by)) { |
|
75 | + $Query->order_by($order_by); |
|
76 | + } elseif(is_array($order_by)) { |
|
77 | + foreach($options['order_by'] as $order_by) |
|
67 | 78 | { |
68 | 79 | if(!isset($order_by[2])) |
69 | 80 | array_unshift($order_by, ''); |
81 | + } |
|
70 | 82 | |
71 | 83 | list($order_table, $order_field, $order_direction) = $order_by; |
72 | 84 | $Query->order_by([$order_table ?? '', $order_field, $order_direction]); |
73 | 85 | } |
74 | 86 | } |
75 | 87 | |
76 | - if(isset($options['limit']) && is_array($options['limit'])) |
|
77 | - $Query->limit($options['limit'][1], $options['limit'][0]); |
|
88 | + if(isset($options['limit']) && is_array($options['limit'])) { |
|
89 | + $Query->limit($options['limit'][1], $options['limit'][0]); |
|
90 | + } |
|
78 | 91 | |
79 | 92 | return $Query; |
80 | 93 | } |