@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | $con = NOSQLParserTrait::initConnection($model, $con); |
| 23 | 23 | $collection = $con->selectCollection($model->getSchema()->name); |
| 24 | 24 | $result = $collection->findOne(['_id' => new ObjectId($pk)]); |
| 25 | - if(null !== $result) { |
|
| 25 | + if (null !== $result) { |
|
| 26 | 26 | $model->feed($result->getArrayCopy()); |
| 27 | 27 | } else { |
| 28 | 28 | throw new ApiException(t('Document not found'), 404); |
@@ -48,13 +48,13 @@ discard block |
||
| 48 | 48 | $filters = self::parseCriteria($criteria, $model); |
| 49 | 49 | $resultSet->count = $collection->countDocuments($filters); |
| 50 | 50 | $nosqlOptions = [ |
| 51 | - 'limit' => (integer)(array_key_exists(Api::API_LIMIT_FIELD, $criteria) ? $criteria[Api::API_LIMIT_FIELD] : Config::getParam('pagination.limit', 50)), |
|
| 52 | - 'skip' => (integer)(array_key_exists(Api::API_PAGE_FIELD, $criteria) ? $criteria[Api::API_PAGE_FIELD] : 1) |
|
| 51 | + 'limit' => (integer) (array_key_exists(Api::API_LIMIT_FIELD, $criteria) ? $criteria[Api::API_LIMIT_FIELD] : Config::getParam('pagination.limit', 50)), |
|
| 52 | + 'skip' => (integer) (array_key_exists(Api::API_PAGE_FIELD, $criteria) ? $criteria[Api::API_PAGE_FIELD] : 1) |
|
| 53 | 53 | ]; |
| 54 | 54 | $results = $collection->find($filters, $nosqlOptions); |
| 55 | 55 | /** @var $result */ |
| 56 | 56 | $items = $results->toArray(); |
| 57 | - foreach($items as $item) { |
|
| 57 | + foreach ($items as $item) { |
|
| 58 | 58 | $model->feed($item->getArrayCopy(), true); |
| 59 | 59 | $resultSet->items[] = $model->getDtoCopy(true); |
| 60 | 60 | } |
@@ -108,9 +108,9 @@ discard block |
||
| 108 | 108 | break; |
| 109 | 109 | } |
| 110 | 110 | } elseif (NOSQLBase::NOSQL_TYPE_INTEGER === $property->type) { |
| 111 | - $filterValue = (integer)$filterValue; |
|
| 111 | + $filterValue = (integer) $filterValue; |
|
| 112 | 112 | } else { |
| 113 | - $filterValue = (float)$filterValue; |
|
| 113 | + $filterValue = (float) $filterValue; |
|
| 114 | 114 | } |
| 115 | 115 | $filterValue = [ |
| 116 | 116 | '$eq' => $filterValue, |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | public function getDtoCopy($cleanPk = false) { |
| 46 | 46 | $copy = clone $this->dto; |
| 47 | - if($cleanPk) { |
|
| 47 | + if ($cleanPk) { |
|
| 48 | 48 | $this->dto->resetPk(); |
| 49 | 49 | } |
| 50 | 50 | return $copy; |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | */ |
| 61 | 61 | public function save(Database $con = null) { |
| 62 | 62 | $saved = false; |
| 63 | - if(null === $con) { |
|
| 63 | + if (null === $con) { |
|
| 64 | 64 | $con = ParserService::getInstance()->createConnection($this->getDomain()); |
| 65 | 65 | } |
| 66 | 66 | $collection = $con->selectCollection($this->getSchema()->name); |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | $isInsert = $isUpdate = false; |
| 69 | 69 | $this->prepareData(); |
| 70 | 70 | $this->dto->setLastUpdate(); |
| 71 | - if($this->isNew()) { |
|
| 71 | + if ($this->isNew()) { |
|
| 72 | 72 | $this->preInsert($con); |
| 73 | 73 | $isInsert = true; |
| 74 | 74 | } elseif ($this->isModified()) { |
@@ -76,19 +76,19 @@ discard block |
||
| 76 | 76 | $isUpdate = true; |
| 77 | 77 | } |
| 78 | 78 | $result = $collection->insertOne($this->toArray()); |
| 79 | - if($result->getInsertedCount() > 0) { |
|
| 79 | + if ($result->getInsertedCount() > 0) { |
|
| 80 | 80 | $id = $result->getInsertedId(); |
| 81 | 81 | $this->dto->setPk($id->jsonSerialize()['$oid']); |
| 82 | - if($isInsert) { |
|
| 82 | + if ($isInsert) { |
|
| 83 | 83 | $this->postInsert($con); |
| 84 | - } elseif($isUpdate) { |
|
| 84 | + } elseif ($isUpdate) { |
|
| 85 | 85 | $this->postUpdate($con); |
| 86 | 86 | } |
| 87 | 87 | $saved = true; |
| 88 | 88 | $this->countAction(); |
| 89 | 89 | } |
| 90 | - } catch(\Exception $exception) { |
|
| 91 | - if($exception instanceof NOSQLValidationException) { |
|
| 90 | + } catch (\Exception $exception) { |
|
| 91 | + if ($exception instanceof NOSQLValidationException) { |
|
| 92 | 92 | throw $exception; |
| 93 | 93 | } else { |
| 94 | 94 | Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray()); |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | */ |
| 104 | 104 | public function update(Database $con = null) { |
| 105 | 105 | $updated = false; |
| 106 | - if(null === $con) { |
|
| 106 | + if (null === $con) { |
|
| 107 | 107 | $con = ParserService::getInstance()->createConnection($this->getDomain()); |
| 108 | 108 | } |
| 109 | 109 | $collection = $con->selectCollection($this->getSchema()->name); |
@@ -117,8 +117,8 @@ discard block |
||
| 117 | 117 | $this->postUpdate($con); |
| 118 | 118 | $updated = true; |
| 119 | 119 | $this->countAction(); |
| 120 | - } catch(\Exception $exception) { |
|
| 121 | - if($exception instanceof NOSQLValidationException) { |
|
| 120 | + } catch (\Exception $exception) { |
|
| 121 | + if ($exception instanceof NOSQLValidationException) { |
|
| 122 | 122 | throw $exception; |
| 123 | 123 | } else { |
| 124 | 124 | Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray()); |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | */ |
| 135 | 135 | public function bulkInsert(array $data, Database $con = null) { |
| 136 | 136 | $inserts = 0; |
| 137 | - if(null === $con) { |
|
| 137 | + if (null === $con) { |
|
| 138 | 138 | $con = ParserService::getInstance()->createConnection($this->getDomain()); |
| 139 | 139 | } |
| 140 | 140 | $collection = $con->selectCollection($this->getSchema()->name); |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | $ids = $result->getInsertedIds(); |
| 145 | 145 | $inserts = $this->parseInsertedDtos($con, $ids, $dtos); |
| 146 | 146 | $this->setActionCount($inserts); |
| 147 | - } catch(\Exception $exception) { |
|
| 147 | + } catch (\Exception $exception) { |
|
| 148 | 148 | Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray()); |
| 149 | 149 | } |
| 150 | 150 | return $inserts; |
@@ -161,14 +161,14 @@ discard block |
||
| 161 | 161 | $upserts = 0; |
| 162 | 162 | $filter = $options = []; |
| 163 | 163 | |
| 164 | - if(null === $con) { |
|
| 164 | + if (null === $con) { |
|
| 165 | 165 | $con = ParserService::getInstance()->createConnection($this->getDomain()); |
| 166 | 166 | } |
| 167 | 167 | $collection = $con->selectCollection($this->getSchema()->name); |
| 168 | 168 | |
| 169 | 169 | $operations = []; |
| 170 | 170 | try { |
| 171 | - foreach($data as $item) { |
|
| 171 | + foreach ($data as $item) { |
|
| 172 | 172 | $filter[$id] = ['$eq' => $item[$id]]; |
| 173 | 173 | $update = []; |
| 174 | 174 | $update['$set'] = $item; |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | */ |
| 195 | 195 | public function delete(Database $con = null) { |
| 196 | 196 | $deleted = false; |
| 197 | - if(null === $con) { |
|
| 197 | + if (null === $con) { |
|
| 198 | 198 | $con = ParserService::getInstance()->createConnection($this->getDomain()); |
| 199 | 199 | } |
| 200 | 200 | $collection = $con->selectCollection($this->getSchema()->name); |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | $deleted = true; |
| 206 | 206 | $this->dto = null; |
| 207 | 207 | $this->countAction(); |
| 208 | - } catch(\Exception $exception) { |
|
| 208 | + } catch (\Exception $exception) { |
|
| 209 | 209 | Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray()); |
| 210 | 210 | } |
| 211 | 211 | return $deleted; |
@@ -219,14 +219,14 @@ discard block |
||
| 219 | 219 | */ |
| 220 | 220 | public function bulkDelete(array $filters, Database $con = null) { |
| 221 | 221 | $deletedCount = 0; |
| 222 | - if(null === $con) { |
|
| 222 | + if (null === $con) { |
|
| 223 | 223 | $con = ParserService::getInstance()->createConnection($this->getDomain()); |
| 224 | 224 | } |
| 225 | 225 | $collection = $con->selectCollection($this->getSchema()->name); |
| 226 | 226 | try { |
| 227 | 227 | $result = $collection->deleteMany($filters); |
| 228 | 228 | $deletedCount = $result->getDeletedCount(); |
| 229 | - } catch(\Exception $exception) { |
|
| 229 | + } catch (\Exception $exception) { |
|
| 230 | 230 | Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray()); |
| 231 | 231 | } |
| 232 | 232 | return $deletedCount; |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | $dtos = []; |
| 244 | 244 | /** @var NOSQLModelDto $dto */ |
| 245 | 245 | foreach ($data as &$insertData) { |
| 246 | - if(is_object($insertData) && $insertData instanceof NOSQLModelDto) { |
|
| 246 | + if (is_object($insertData) && $insertData instanceof NOSQLModelDto) { |
|
| 247 | 247 | $dto = clone $insertData; |
| 248 | 248 | } else { |
| 249 | 249 | $dto = $this->getDtoCopy(true); |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | foreach ($ids as $index => $insertedId) { |
| 274 | 274 | $id = $insertedId->jsonSerialize(); |
| 275 | 275 | $dto = $dtos[$index]; |
| 276 | - if($dto instanceof NOSQLModelDto) { |
|
| 276 | + if ($dto instanceof NOSQLModelDto) { |
|
| 277 | 277 | $dto->setPk($id['$oid']); |
| 278 | 278 | } else { |
| 279 | 279 | |