@@ -23,7 +23,7 @@ |
||
| 23 | 23 | public function updateProxy(ProxyGenerator &$proxy) |
| 24 | 24 | { |
| 25 | 25 | // In the closure, $this is the proxied database |
| 26 | - $callback = function ($args, $next) { |
|
| 26 | + $callback = function($args, $next) { |
|
| 27 | 27 | |
| 28 | 28 | // The first argument is always the sql query |
| 29 | 29 | $sql = $args[0]; |
@@ -41,7 +41,7 @@ |
||
| 41 | 41 | foreach ($export_fields as $field=>$_title) { |
| 42 | 42 | $parts = explode('.', $field); |
| 43 | 43 | if (count($parts) < 2) continue; |
| 44 | - $main = implode('.', array_slice($parts,0,-1)); |
|
| 44 | + $main = implode('.', array_slice($parts, 0, -1)); |
|
| 45 | 45 | if (!in_array($main, $eager)) { |
| 46 | 46 | $eager[] = $main; |
| 47 | 47 | } |
@@ -40,7 +40,9 @@ discard block |
||
| 40 | 40 | $export_eager = []; |
| 41 | 41 | foreach ($export_fields as $field=>$_title) { |
| 42 | 42 | $parts = explode('.', $field); |
| 43 | - if (count($parts) < 2) continue; |
|
| 43 | + if (count($parts) < 2) { |
|
| 44 | + continue; |
|
| 45 | + } |
|
| 44 | 46 | $main = implode('.', array_slice($parts,0,-1)); |
| 45 | 47 | if (!in_array($main, $eager)) { |
| 46 | 48 | $eager[] = $main; |
@@ -48,7 +50,9 @@ discard block |
||
| 48 | 50 | } |
| 49 | 51 | } |
| 50 | 52 | } |
| 51 | - if ($eager) return $dataList->with($eager); |
|
| 53 | + if ($eager) { |
|
| 54 | + return $dataList->with($eager); |
|
| 55 | + } |
|
| 52 | 56 | return $dataList; |
| 53 | 57 | } |
| 54 | 58 | } |
@@ -12,7 +12,7 @@ |
||
| 12 | 12 | $result = []; |
| 13 | 13 | foreach ($arr as $k => $v) { |
| 14 | 14 | $key = $k; |
| 15 | - if ($kfield!==null) { |
|
| 15 | + if ($kfield !== null) { |
|
| 16 | 16 | if (is_array($v) && isset($v[$kfield])) $key = $v[$kfield]; |
| 17 | 17 | elseif (is_object($v) && isset($v->$kfield)) $key = $v->$kfield; |
| 18 | 18 | } |
@@ -13,8 +13,11 @@ |
||
| 13 | 13 | foreach ($arr as $k => $v) { |
| 14 | 14 | $key = $k; |
| 15 | 15 | if ($kfield!==null) { |
| 16 | - if (is_array($v) && isset($v[$kfield])) $key = $v[$kfield]; |
|
| 17 | - elseif (is_object($v) && isset($v->$kfield)) $key = $v->$kfield; |
|
| 16 | + if (is_array($v) && isset($v[$kfield])) { |
|
| 17 | + $key = $v[$kfield]; |
|
| 18 | + } elseif (is_object($v) && isset($v->$kfield)) { |
|
| 19 | + $key = $v->$kfield; |
|
| 20 | + } |
|
| 18 | 21 | } |
| 19 | 22 | $result[$key] = $v; |
| 20 | 23 | } |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | * Replaces DataList when EagerLoading is used. Fetches data when the main query is actually executed. |
| 11 | 11 | * Appends related objects when a DataObject is actually created. |
| 12 | 12 | */ |
| 13 | -class EagerLoadedDataList extends DataList{ |
|
| 13 | +class EagerLoadedDataList extends DataList { |
|
| 14 | 14 | |
| 15 | 15 | const ID_LIMIT = 5000; |
| 16 | 16 | public $withList = []; |
@@ -121,12 +121,12 @@ discard block |
||
| 121 | 121 | |
| 122 | 122 | $descriptor['map'] = Utils::extractField($data, $descriptor['localField']); |
| 123 | 123 | $uniqueIDs = array_unique($descriptor['map']); |
| 124 | - while(count($uniqueIDs)) { |
|
| 125 | - $IDsubset = array_splice($uniqueIDs,0,self::ID_LIMIT); |
|
| 124 | + while (count($uniqueIDs)) { |
|
| 125 | + $IDsubset = array_splice($uniqueIDs, 0, self::ID_LIMIT); |
|
| 126 | 126 | $result = DataObject::get($depClass)->filter('ID', $IDsubset); |
| 127 | - if (count($depSeq)>1) { |
|
| 127 | + if (count($depSeq) > 1) { |
|
| 128 | 128 | $result = $result |
| 129 | - ->with(implode('.', array_slice($depSeq,1))); |
|
| 129 | + ->with(implode('.', array_slice($depSeq, 1))); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | foreach ($result as $depRecord) { |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | public function eagerLoadHasMany($data, $hasManys, $withHasManys) |
| 143 | 143 | { |
| 144 | 144 | $localClass = $this->dataClass(); |
| 145 | - $localClassTail = basename(str_replace('\\','/', $localClass)); |
|
| 145 | + $localClassTail = basename(str_replace('\\', '/', $localClass)); |
|
| 146 | 146 | |
| 147 | 147 | foreach ($withHasManys as $depSeq) { |
| 148 | 148 | $dep = $depSeq[0]; |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | 'map' => [], |
| 157 | 157 | ]; |
| 158 | 158 | $result = DataObject::get($depClass)->filter($depKey, $data); |
| 159 | - if (count($depSeq)>1) { |
|
| 159 | + if (count($depSeq) > 1) { |
|
| 160 | 160 | $result = $result |
| 161 | 161 | ->with(implode('.', array_slice($depSeq, 1))); |
| 162 | 162 | } |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | implode(',', [$component['childField'], $component['parentField']]), |
| 198 | 198 | $component['join'], |
| 199 | 199 | [ |
| 200 | - $component['parentField'].' IN (' . implode(',', $data).')' |
|
| 200 | + $component['parentField'].' IN ('.implode(',', $data).')' |
|
| 201 | 201 | ] |
| 202 | 202 | )->execute(); |
| 203 | 203 | |
@@ -212,9 +212,9 @@ discard block |
||
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | $result = DataObject::get($depClass)->filter('ID', array_keys($relListReverted)); |
| 215 | - if (count($depSeq)>1) { |
|
| 215 | + if (count($depSeq) > 1) { |
|
| 216 | 216 | $result = $result |
| 217 | - ->with(implode('.', array_slice($depSeq,1))); |
|
| 217 | + ->with(implode('.', array_slice($depSeq, 1))); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | foreach ($result as $depRecord) { |
@@ -67,7 +67,9 @@ discard block |
||
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | public function prepareEagerRelations() { |
| 70 | - if ($this->relationsPrepared) return; |
|
| 70 | + if ($this->relationsPrepared) { |
|
| 71 | + return; |
|
| 72 | + } |
|
| 71 | 73 | $this->relationsPrepared = true; |
| 72 | 74 | $localClass = $this->dataClass(); |
| 73 | 75 | $config = Config::forClass($localClass); |
@@ -221,7 +223,9 @@ discard block |
||
| 221 | 223 | foreach ($idsQuery as $row) { |
| 222 | 224 | $relID = $row[$component['childField']]; |
| 223 | 225 | $localID = $row[$component['parentField']]; |
| 224 | - if (!isset($collection[$localID])) $collection[$localID] = []; |
|
| 226 | + if (!isset($collection[$localID])) { |
|
| 227 | + $collection[$localID] = []; |
|
| 228 | + } |
|
| 225 | 229 | $collection[$localID][] = $relID; |
| 226 | 230 | $relListReverted[$relID] = 1; //use ids as keys to avoid |
| 227 | 231 | } |
@@ -16,7 +16,9 @@ |
||
| 16 | 16 | if (!isset($this->owner->withList)) { |
| 17 | 17 | $this->owner->withList = []; |
| 18 | 18 | } |
| 19 | - if (!is_array($list)) $list = [$list]; |
|
| 19 | + if (!is_array($list)) { |
|
| 20 | + $list = [$list]; |
|
| 21 | + } |
|
| 20 | 22 | $list = array_map(function($e) {return explode('.', $e); }, $list); |
| 21 | 23 | $this->owner->withList = array_merge($this->owner->withList, $list); |
| 22 | 24 | return EagerLoadedDataList::cloneFrom($this->owner); |