@@ -96,15 +96,15 @@ discard block |
||
| 96 | 96 | $value = $this->entity->wrap($this->relations, $value); |
| 97 | 97 | $this->dataSource->save($value); |
| 98 | 98 | $visibilityOverride->write($value); |
| 99 | - $this->entity->create((array_merge((array)$value, (array)$valueCopy)), $this->relations); |
|
| 99 | + $this->entity->create((array_merge((array)$value, (array)$valueCopy)), $this->relations); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | public function offsetExists($offset) { |
| 103 | 103 | if (count($this->dataSource->getPrimaryKey()) > 1) return new MultiPk($this, $offset, $this->dataSource->getPrimaryKey()); |
| 104 | - if (!empty($this->settings['filter'])) { |
|
| 105 | - $data = $this->dataSource->findByField(array_merge($this->settings['filter'], [$this->dataSource->getPrimaryKey()[0] => $offset])); |
|
| 106 | - return isset($data[0]); |
|
| 107 | - } |
|
| 104 | + if (!empty($this->settings['filter'])) { |
|
| 105 | + $data = $this->dataSource->findByField(array_merge($this->settings['filter'], [$this->dataSource->getPrimaryKey()[0] => $offset])); |
|
| 106 | + return isset($data[0]); |
|
| 107 | + } |
|
| 108 | 108 | return (bool) $this->dataSource->findById($offset); |
| 109 | 109 | } |
| 110 | 110 | |
@@ -114,10 +114,10 @@ discard block |
||
| 114 | 114 | |
| 115 | 115 | public function offsetGet($offset) { |
| 116 | 116 | if (count($this->dataSource->getPrimaryKey()) > 1) return new MultiPk($this, $offset, $this->dataSource->getPrimaryKey()); |
| 117 | - if (!empty($this->settings['filter'])) { |
|
| 118 | - $data = $this->dataSource->findByField(array_merge($this->settings['filter'], [$this->dataSource->getPrimaryKey()[0] => $offset])); |
|
| 119 | - return $this->entity->create(isset($data[0]) ? $data[0] : null, $this->relations); |
|
| 120 | - } |
|
| 117 | + if (!empty($this->settings['filter'])) { |
|
| 118 | + $data = $this->dataSource->findByField(array_merge($this->settings['filter'], [$this->dataSource->getPrimaryKey()[0] => $offset])); |
|
| 119 | + return $this->entity->create(isset($data[0]) ? $data[0] : null, $this->relations); |
|
| 120 | + } |
|
| 121 | 121 | return $this->entity->create($this->dataSource->findById($offset), $this->relations); |
| 122 | 122 | } |
| 123 | 123 | |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | else $limit = ''; |
| 115 | 115 | |
| 116 | 116 | $query = $this->selectBuilder->createSql($fields, $mode); |
| 117 | - $query['sql'] = array_filter($query['sql']); |
|
| 117 | + $query['sql'] = array_filter($query['sql']); |
|
| 118 | 118 | $this->adapter->query($this->crudBuilder->delete($this->table, $query['sql'], $query['args'], $limit)); |
| 119 | 119 | $this->addIndex(array_keys($query['args'])); |
| 120 | 120 | |
@@ -123,23 +123,23 @@ discard block |
||
| 123 | 123 | $this->resultCache = []; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - private function getIfNew($data) { |
|
| 127 | - $new = false; |
|
| 128 | - foreach ($this->primaryKey as $k) { |
|
| 129 | - if (empty($data->$k)) { |
|
| 130 | - $data->$k = null; |
|
| 131 | - $new = true; |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - return $new; |
|
| 135 | - } |
|
| 126 | + private function getIfNew($data) { |
|
| 127 | + $new = false; |
|
| 128 | + foreach ($this->primaryKey as $k) { |
|
| 129 | + if (empty($data->$k)) { |
|
| 130 | + $data->$k = null; |
|
| 131 | + $new = true; |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + return $new; |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | 137 | public function save($data, $tryagain = true) { |
| 138 | 138 | $tryagain = $tryagain && self::EDIT_STRUCTURE & $this->alterDb; |
| 139 | - $new = $this->getIfNew($data); |
|
| 139 | + $new = $this->getIfNew($data); |
|
| 140 | 140 | |
| 141 | 141 | try { |
| 142 | - $result = $this->insert($this->table, $this->primaryKey, $data); |
|
| 142 | + $result = $this->insert($this->table, $this->primaryKey, $data); |
|
| 143 | 143 | |
| 144 | 144 | //If there was an error but PDO is silent, trigger the catch block anyway |
| 145 | 145 | if ($result->errorCode() !== '00000') throw new \Exception('Could not insert into ' . $this->table); |
@@ -158,18 +158,18 @@ discard block |
||
| 158 | 158 | $this->updateCache($data); |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - private function checkIfUpdateWorked($data) { |
|
| 162 | - $updateWhere = $this->crudBuilder->update($this->table, $this->primaryKey, $data); |
|
| 163 | - $matched = $this->findByField($updateWhere->getArgs()); |
|
| 161 | + private function checkIfUpdateWorked($data) { |
|
| 162 | + $updateWhere = $this->crudBuilder->update($this->table, $this->primaryKey, $data); |
|
| 163 | + $matched = $this->findByField($updateWhere->getArgs()); |
|
| 164 | 164 | |
| 165 | - if (count($matched) == 0) throw new \InvalidArgumentException('Record inserted into table ' . $this->table . ' fails table constraints'); |
|
| 166 | - } |
|
| 165 | + if (count($matched) == 0) throw new \InvalidArgumentException('Record inserted into table ' . $this->table . ' fails table constraints'); |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - private function updateCache($data) { |
|
| 169 | - $pkValue = $data->{$this->primaryKey[0]}; |
|
| 168 | + private function updateCache($data) { |
|
| 169 | + $pkValue = $data->{$this->primaryKey[0]}; |
|
| 170 | 170 | if (isset($this->cache[$pkValue])) $this->cache[$pkValue] = (object) array_merge((array)$this->cache[$pkValue], (array)$data); |
| 171 | 171 | else $this->cache[$pkValue] = $data; |
| 172 | - } |
|
| 172 | + } |
|
| 173 | 173 | |
| 174 | 174 | private function insert($table, array $primaryKey, $data) { |
| 175 | 175 | $error = 0; |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | $result = $this->adapter->query($this->crudBuilder->update($table, $primaryKey, $data)); |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | - if ($result->rowCount() === 0) $this->checkIfUpdateWorked($data); |
|
| 187 | + if ($result->rowCount() === 0) $this->checkIfUpdateWorked($data); |
|
| 188 | 188 | |
| 189 | 189 | return $result; |
| 190 | 190 | } |
@@ -25,13 +25,13 @@ discard block |
||
| 25 | 25 | $this->crudBuilder = new \Maphper\Lib\CrudBuilder(); |
| 26 | 26 | $this->selectBuilder = new \Maphper\Lib\SelectBuilder(); |
| 27 | 27 | |
| 28 | - $this->fields = implode(',', array_map([$this->adapter, 'quote'], (array) $this->options->read('fields'))); |
|
| 28 | + $this->fields = implode(',', array_map([$this->adapter, 'quote'], (array)$this->options->read('fields'))); |
|
| 29 | 29 | |
| 30 | - $this->defaultSort = $this->options->read('defaultSort') !== false ? $this->options->read('defaultSort') : implode(', ', $this->primaryKey); |
|
| 30 | + $this->defaultSort = $this->options->read('defaultSort') !== false ? $this->options->read('defaultSort') : implode(', ', $this->primaryKey); |
|
| 31 | 31 | |
| 32 | 32 | $this->alterDb = $this->options->getEditMode(); |
| 33 | 33 | |
| 34 | - if (self::EDIT_OPTIMISE & $this->alterDb && rand(0,500) == 1) $this->adapter->optimiseColumns($table); |
|
| 34 | + if (self::EDIT_OPTIMISE & $this->alterDb && rand(0, 500) == 1) $this->adapter->optimiseColumns($table); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | public function getPrimaryKey() { |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | |
| 168 | 168 | private function updateCache($data) { |
| 169 | 169 | $pkValue = $data->{$this->primaryKey[0]}; |
| 170 | - if (isset($this->cache[$pkValue])) $this->cache[$pkValue] = (object) array_merge((array)$this->cache[$pkValue], (array)$data); |
|
| 170 | + if (isset($this->cache[$pkValue])) $this->cache[$pkValue] = (object)array_merge((array)$this->cache[$pkValue], (array)$data); |
|
| 171 | 171 | else $this->cache[$pkValue] = $data; |
| 172 | 172 | } |
| 173 | 173 | |