@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace HnrAzevedo\Datamanager; |
4 | 4 | |
5 | -trait DataTrait{ |
|
5 | +trait DataTrait { |
|
6 | 6 | use CrudTrait, CheckTrait; |
7 | 7 | |
8 | 8 | protected ?string $table = null; |
@@ -25,15 +25,15 @@ discard block |
||
25 | 25 | { |
26 | 26 | $return = ['data' => '', 'where' => '']; |
27 | 27 | $c = -1; |
28 | - foreach($this->where as $clause => $condition){ |
|
28 | + foreach ($this->where as $clause => $condition) { |
|
29 | 29 | $c++; |
30 | - if(strlen($clause) === 0){ |
|
30 | + if (strlen($clause) === 0) { |
|
31 | 31 | $return['where'] .= " {$clause} {$condition[0]} {$condition[1]} :q_{$condition[0]}{$c} "; |
32 | 32 | $return['data'] .= "q_{$condition[0]}={$condition[2]}{$c}&"; |
33 | 33 | continue; |
34 | 34 | } |
35 | 35 | |
36 | - foreach($condition as $value){ |
|
36 | + foreach ($condition as $value) { |
|
37 | 37 | $return['where'] .= " {$clause} {$value[0]} {$value[1]} :q_{$value[0]}{$c} "; |
38 | 38 | $return['data'] .= "q_{$value[0]}={$value[2]}{$c}&"; |
39 | 39 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | $return = ['data' => []]; |
47 | 47 | |
48 | 48 | foreach ($this->data as $key => $value) { |
49 | - if($this->upgradeable($key) && !$this->isIncremented($key)){ |
|
49 | + if ($this->upgradeable($key) && !$this->isIncremented($key)) { |
|
50 | 50 | $return['data'][$key] = $this->data[$key]['value']; |
51 | 51 | } |
52 | 52 | } |
@@ -62,16 +62,16 @@ discard block |
||
62 | 62 | $c++; |
63 | 63 | $key = (!$key) ? '' : " {$key} "; |
64 | 64 | |
65 | - if(!is_array($value[0])){ |
|
65 | + if (!is_array($value[0])) { |
|
66 | 66 | $return['where'] .= " {$key} {$value[0]} {$value[1]} :q_{$value[0]}{$c} "; |
67 | 67 | $return['data']["q_{$value[0]}{$c}"] = $value[2]; |
68 | 68 | continue; |
69 | 69 | } |
70 | 70 | |
71 | 71 | |
72 | - for($i = 0; $i < count($value); $i++){ |
|
72 | + for ($i = 0; $i < count($value); $i++) { |
|
73 | 73 | |
74 | - if(!is_array($value[$i][2])){ |
|
74 | + if (!is_array($value[$i][2])) { |
|
75 | 75 | $return['where'] .= " {$key} {$value[$i][0]} {$value[$i][1]} :q_{$value[$i][0]}{$c}{$i} "; |
76 | 76 | $return['data']["q_{$value[$i][0]}{$c}{$i}"] = $value[$i][2]; |
77 | 77 | continue; |
@@ -79,12 +79,12 @@ discard block |
||
79 | 79 | |
80 | 80 | $return['where'] .= " {$key} {$value[$i][0]} {$value[$i][1]} ("; |
81 | 81 | |
82 | - foreach($value[$i][2] as $v => $valu){ |
|
82 | + foreach ($value[$i][2] as $v => $valu) { |
|
83 | 83 | $return['where'] .= " :q_{$value[$i][0]}{$c}{$i}_{$v},"; |
84 | 84 | $return['data']["q_{$value[$i][0]}{$c}{$i}_{$v}"] = $valu; |
85 | 85 | } |
86 | 86 | |
87 | - $return['where'] = substr($return['where'],0,-1) .') '; |
|
87 | + $return['where'] = substr($return['where'], 0, -1).') '; |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | return $return; |
@@ -95,14 +95,14 @@ discard block |
||
95 | 95 | $return = ['where' => '', 'data' => []]; |
96 | 96 | |
97 | 97 | $c = -1; |
98 | - foreach($this->between as $field => $value){ |
|
98 | + foreach ($this->between as $field => $value) { |
|
99 | 99 | $c++; |
100 | - $condition = (count(explode(' ',$field)) > 2) ? ' '.explode(' ',$field)[0].' ' : ' AND '; |
|
101 | - $field = str_replace(['AND','OR',' '],'',$field); |
|
100 | + $condition = (count(explode(' ', $field)) > 2) ? ' '.explode(' ', $field)[0].' ' : ' AND '; |
|
101 | + $field = str_replace(['AND', 'OR', ' '], '', $field); |
|
102 | 102 | $return['where'] .= " {$condition} {$field} BETWEEN :q_1{$field}{$c} AND :q_2{$field}{$c} "; |
103 | 103 | $return['data'] = [ |
104 | - "q_1{$field}{$c}" => (date_format( date_create_from_format(DATAMANAGER_CONFIG['dateformat'],$value[0]) , 'Y-m-d')), |
|
105 | - "q_2{$field}{$c}" => (date_format( date_create_from_format(DATAMANAGER_CONFIG['dateformat'],$value[1]) , 'Y-m-d')) |
|
104 | + "q_1{$field}{$c}" => (date_format(date_create_from_format(DATAMANAGER_CONFIG['dateformat'], $value[0]), 'Y-m-d')), |
|
105 | + "q_2{$field}{$c}" => (date_format(date_create_from_format(DATAMANAGER_CONFIG['dateformat'], $value[1]), 'Y-m-d')) |
|
106 | 106 | ]; |
107 | 107 | } |
108 | 108 | return $return; |
@@ -110,21 +110,21 @@ discard block |
||
110 | 110 | |
111 | 111 | protected function mountSelect() |
112 | 112 | { |
113 | - $select = implode(',',array_keys($this->select)); |
|
113 | + $select = implode(',', array_keys($this->select)); |
|
114 | 114 | |
115 | - $this->query = str_replace('*', $select,$this->query); |
|
115 | + $this->query = str_replace('*', $select, $this->query); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | protected function mountLimit() |
119 | 119 | { |
120 | - if(!is_null($this->limit)){ |
|
120 | + if (!is_null($this->limit)) { |
|
121 | 121 | $this->query .= " LIMIT {$this->limit}"; |
122 | 122 | } |
123 | 123 | } |
124 | 124 | |
125 | 125 | protected function mountOffset() |
126 | 126 | { |
127 | - if(!is_null($this->offset)){ |
|
127 | + if (!is_null($this->offset)) { |
|
128 | 128 | $this->query .= " OFFSET {$this->offset}"; |
129 | 129 | } |
130 | 130 | } |