diff --git a/application/Espo/Core/Controllers/Record.php b/application/Espo/Core/Controllers/Record.php index 00f3b2fd6e..9f54604556 100644 --- a/application/Espo/Core/Controllers/Record.php +++ b/application/Espo/Core/Controllers/Record.php @@ -27,7 +27,7 @@ abstract class Record extends Base throw new Forbidden(); } - return $entity; + return $entity->toArray(); } public function actionPatch($params, $data) @@ -44,7 +44,7 @@ abstract class Record extends Base $service = $this->getService(); if ($entity = $service->createEntity($data)) { - return $entity; + return $entity->toArray(); } throw new Error(); @@ -59,7 +59,7 @@ abstract class Record extends Base $id = $params['id']; if ($this->getService()->updateEntity($id, $data)) { - return $entity; + return $entity->toArray(); } throw new Error(); @@ -77,7 +77,7 @@ abstract class Record extends Base $asc = $data['asc']; $sortBy = $data['sortBy']; - return $this->getService()->findEntities(array( + $result = $this->getService()->findEntities(array( 'where' => $where, 'offset' => $offset, 'limit' => $limit, @@ -85,10 +85,10 @@ abstract class Record extends Base 'sortBy' => $sortBy, )); - /*return array( - 'total' => count($entityList), - 'list' => $entityList - );*/ + return array( + 'total' => $result['total'], + 'list' => $result['collection']->toArray() + ); } public function actionDelete($params) @@ -140,17 +140,17 @@ abstract class Record extends Base $asc = $data['asc']; $sortBy = $data['sortBy']; - $entityList = $this->getService()->findLinkedEntities($id, $link, array( + $result = $this->getService()->findLinkedEntities($id, $link, array( 'where' => $where, 'offset' => $offset, 'limit' => $limit, 'asc' => $asc, 'sortBy' => $sortBy, )); - + return array( - 'total' => count($entityList), - 'list' => $entityList + 'total' => $result['total'], + 'list' => $result['collection']->toArray() ); } diff --git a/application/Espo/Services/Record.php b/application/Espo/Services/Record.php index c317f4b3bb..d7f9448091 100644 --- a/application/Espo/Services/Record.php +++ b/application/Espo/Services/Record.php @@ -96,7 +96,7 @@ class Record extends \Espo\Core\Services\Base $entity->set($data); $this->getRepository()->save($entity); - return $entity->toArray(); + return $entity; } public function updateEntity($id, $data) @@ -110,7 +110,7 @@ class Record extends \Espo\Core\Services\Base $entity->set($data); $this->getRepository()->save($entity); - return $entity->toArray(); + return $entity; } public function deleteEntity($id) @@ -128,11 +128,11 @@ class Record extends \Espo\Core\Services\Base { $selectParams = $this->getSelectManager()->getSelectParams($this->name, $params, true); $collection = $this->getRepository()->find($selectParams); - + return array( 'total' => $this->getRepository()->count($selectParams), - 'list' => $collection->toArray() - ); + 'collection' => $collection, + ); } public function findLinkedEntities($id, $link, $params) @@ -152,10 +152,10 @@ class Record extends \Espo\Core\Services\Base // TODO // $repository->via($entity, $link)->find($selectParams); - + return array( 'total' => $this->getRepository()->countRelated($entity, $link, $selectParams), - 'list' => $collection->toArray() + 'collection' => $collection, ); } @@ -174,8 +174,7 @@ class Record extends \Espo\Core\Services\Base throw new Error(); } - $foreignEntity = $this->getEntityManager()->getEntity($foreignEntityName, $foreignId); - + $foreignEntity = $this->getEntityManager()->getEntity($foreignEntityName, $foreignId); if (!empty($foreignEntity)) { $this->getRepository()->relate($entity, $link, $foreignEntity);