mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-28 06:56:05 +00:00
record collection getApiOutput method
This commit is contained in:
@@ -35,6 +35,9 @@ use Espo\Tools\ActionHistory\Service as Service;
|
||||
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class LastViewed
|
||||
{
|
||||
public function __construct(private SearchParamsFetcher $searchParamsFetcher, private Service $service)
|
||||
@@ -49,9 +52,6 @@ class LastViewed
|
||||
|
||||
$result = $this->service->getLastViewed($maxSize, $offset);
|
||||
|
||||
return (object) [
|
||||
'total' => $result->getTotal(),
|
||||
'list' => $result->getValueMapList(),
|
||||
];
|
||||
return $result->toApiOutput();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,10 +83,7 @@ class Notification extends RecordBase
|
||||
|
||||
$recordCollection = $this->getNotificationService()->get($userId, $searchParams);
|
||||
|
||||
return (object) [
|
||||
'total' => $recordCollection->getTotal(),
|
||||
'list' => $recordCollection->getValueMapList(),
|
||||
];
|
||||
return $recordCollection->toApiOutput();
|
||||
}
|
||||
|
||||
public function getActionNotReadCount(): int
|
||||
|
||||
@@ -79,12 +79,12 @@ class Stream
|
||||
|
||||
$reactionsCheckDate = DateTime::createNow();
|
||||
|
||||
return (object) [
|
||||
'total' => $collection->getTotal(),
|
||||
'list' => $collection->getValueMapList(),
|
||||
'reactionsCheckDate' => $reactionsCheckDate->toString(),
|
||||
'updatedReactions' => $this->getReactionUpdates($request, $id),
|
||||
];
|
||||
$output = $collection->toApiOutput();
|
||||
|
||||
$output->reactionsCheckDate = $reactionsCheckDate->toString();
|
||||
$output->updatedReactions = $this->getReactionUpdates($request, $id);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
if ($id === null) {
|
||||
@@ -94,11 +94,11 @@ class Stream
|
||||
$collection = $this->service->find($scope, $id, $searchParams);
|
||||
$pinnedCollection = $this->service->getPinned($scope, $id);
|
||||
|
||||
return (object) [
|
||||
'total' => $collection->getTotal(),
|
||||
'list' => $collection->getValueMapList(),
|
||||
'pinnedList' => $pinnedCollection->getValueMapList(),
|
||||
];
|
||||
$output = $collection->toApiOutput();
|
||||
|
||||
$output->pinnedList = $pinnedCollection->getValueMapList();
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,10 +126,7 @@ class Stream
|
||||
$this->userRecordService->find($id, $searchParams) :
|
||||
$this->service->find($scope, $id ?? '', $searchParams);
|
||||
|
||||
return (object) [
|
||||
'total' => $result->getTotal(),
|
||||
'list' => $result->getValueMapList(),
|
||||
];
|
||||
return $result->toApiOutput();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -150,10 +147,7 @@ class Stream
|
||||
|
||||
$result = $this->service->findUpdates($scope, $id, $searchParams);
|
||||
|
||||
return (object) [
|
||||
'total' => $result->getTotal(),
|
||||
'list' => $result->getValueMapList(),
|
||||
];
|
||||
return $result->toApiOutput();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,7 +31,6 @@ namespace Espo\Core\Controllers;
|
||||
|
||||
use Espo\Core\Exceptions\BadRequest;
|
||||
use Espo\Core\Api\Request;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\Exceptions\Forbidden;
|
||||
use Espo\Core\Exceptions\NotFound;
|
||||
use Espo\Core\Exceptions\NotFoundSilent;
|
||||
@@ -65,12 +64,9 @@ class Record extends RecordBase
|
||||
|
||||
$searchParams = $this->fetchSearchParamsFromRequest($request);
|
||||
|
||||
$recordCollection = $this->getRecordService()->findLinked($id, $link, $searchParams);
|
||||
$result = $this->getRecordService()->findLinked($id, $link, $searchParams);
|
||||
|
||||
return (object) [
|
||||
'total' => $recordCollection->getTotal(),
|
||||
'list' => $recordCollection->getValueMapList(),
|
||||
];
|
||||
return $result->toApiOutput();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -255,10 +255,7 @@ class RecordBase extends Base implements
|
||||
|
||||
$recordCollection = $this->getRecordService()->find($searchParams, $findParams);
|
||||
|
||||
return (object) [
|
||||
'total' => $recordCollection->getTotal(),
|
||||
'list' => $recordCollection->getValueMapList(),
|
||||
];
|
||||
return $recordCollection->toApiOutput();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
namespace Espo\Core\Record;
|
||||
|
||||
use Espo\ORM\Collection as OrmCollection;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\EntityCollection;
|
||||
|
||||
use stdClass;
|
||||
@@ -37,7 +38,7 @@ use stdClass;
|
||||
/**
|
||||
* Contains an ORM collection and total number of records.
|
||||
*
|
||||
* @template-covariant TEntity of \Espo\ORM\Entity
|
||||
* @template-covariant TEntity of Entity
|
||||
*/
|
||||
class Collection
|
||||
{
|
||||
@@ -100,7 +101,7 @@ class Collection
|
||||
/**
|
||||
* Create.
|
||||
*
|
||||
* @template CEntity of \Espo\ORM\Entity
|
||||
* @template CEntity of Entity
|
||||
* @param OrmCollection<CEntity> $collection
|
||||
* @return self<CEntity>
|
||||
*/
|
||||
@@ -112,7 +113,7 @@ class Collection
|
||||
/**
|
||||
* Create w/o count.
|
||||
*
|
||||
* @template CEntity of \Espo\ORM\Entity
|
||||
* @template CEntity of Entity
|
||||
* @param OrmCollection<CEntity> $collection
|
||||
* @return self<CEntity>
|
||||
*/
|
||||
@@ -132,4 +133,17 @@ class Collection
|
||||
|
||||
return new self($collection, self::TOTAL_HAS_NO_MORE);
|
||||
}
|
||||
|
||||
/**
|
||||
* To API output. To be used in API actions.
|
||||
*
|
||||
* @since 9.1.0
|
||||
*/
|
||||
public function toApiOutput(): stdClass
|
||||
{
|
||||
return (object) [
|
||||
'total' => $this->getTotal(),
|
||||
'list' => $this->getValueMapList(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,13 +78,10 @@ class Get implements Action
|
||||
|
||||
$fetchParams = new ActivitiesFetchParams($maxSize, $offset, $targetEntityType);
|
||||
|
||||
$recordCollection = $type === 'history' ?
|
||||
$result = $type === 'history' ?
|
||||
$this->service->getHistory($parentType, $id, $fetchParams) :
|
||||
$this->service->getActivities($parentType, $id, $fetchParams);
|
||||
|
||||
return ResponseComposer::json([
|
||||
'total' => $recordCollection->getTotal(),
|
||||
'list' => $recordCollection->getValueMapList(),
|
||||
]);
|
||||
return ResponseComposer::json($result->toApiOutput());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,9 +81,6 @@ class GetListTyped implements Action
|
||||
$searchParams
|
||||
);
|
||||
|
||||
return ResponseComposer::json([
|
||||
'total' => $result->getTotal(),
|
||||
'list' => $result->getValueMapList(),
|
||||
]);
|
||||
return ResponseComposer::json($result->toApiOutput());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,12 +59,9 @@ class GetUpcoming implements Action
|
||||
|
||||
$params = $this->fetchParams($request);
|
||||
|
||||
$recordCollection = $this->service->get($userId, $params);
|
||||
$result = $this->service->get($userId, $params);
|
||||
|
||||
return ResponseComposer::json([
|
||||
'total' => $recordCollection->getTotal(),
|
||||
'list' => $recordCollection->getValueMapList(),
|
||||
]);
|
||||
return ResponseComposer::json($result->toApiOutput());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -65,11 +65,8 @@ class GetOptedOut implements Action
|
||||
|
||||
$searchParams = $this->searchParamsFetcher->fetch($request);
|
||||
|
||||
$collection = $this->service->find($id, $searchParams);
|
||||
$result = $this->service->find($id, $searchParams);
|
||||
|
||||
return ResponseComposer::json((object) [
|
||||
'total' => $collection->getTotal(),
|
||||
'list' => $collection->getValueMapList(),
|
||||
]);
|
||||
return ResponseComposer::json($result->toApiOutput());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,9 +59,6 @@ class Get implements Action
|
||||
|
||||
$result = $this->service->find($query, $offset, $maxSize);
|
||||
|
||||
return ResponseComposer::json([
|
||||
'total' => $result->getTotal(),
|
||||
'list' => $result->getValueMapList(),
|
||||
]);
|
||||
return ResponseComposer::json($result->toApiOutput());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,9 +67,6 @@ class GetFollowers implements Action
|
||||
|
||||
$collection = $this->service->find($entityType, $id, $searchParams);
|
||||
|
||||
return ResponseComposer::json((object) [
|
||||
'total' => $collection->getTotal(),
|
||||
'list' => $collection->getValueMapList(),
|
||||
]);
|
||||
return ResponseComposer::json($collection->toApiOutput());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,12 +61,9 @@ class GetGlobal implements Action
|
||||
|
||||
$searchParams = $this->fetchSearchParams($request);
|
||||
|
||||
$collection = $this->service->find($searchParams);
|
||||
$result = $this->service->find($searchParams);
|
||||
|
||||
return ResponseComposer::json([
|
||||
'list' => $collection->getValueMapList(),
|
||||
'total' => $collection->getTotal(),
|
||||
]);
|
||||
return ResponseComposer::json($result->toApiOutput());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -61,10 +61,7 @@ class GetOwn implements Action
|
||||
|
||||
$collection = $this->service->findOwn($userId, $searchParams);
|
||||
|
||||
return ResponseComposer::json([
|
||||
'list' => $collection->getValueMapList(),
|
||||
'total' => $collection->getTotal(),
|
||||
]);
|
||||
return ResponseComposer::json($collection->toApiOutput());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -57,11 +57,8 @@ class PostRecordUsersAccess implements Action
|
||||
|
||||
$entity = $this->entityProvider->get($entityType, $id);
|
||||
|
||||
$collection = $this->usersAccessService->get($entity, $searchParams);
|
||||
$result = $this->usersAccessService->get($entity, $searchParams);
|
||||
|
||||
return ResponseComposer::json([
|
||||
'list' => $collection->getValueMapList(),
|
||||
'total' => $collection->getTotal(),
|
||||
]);
|
||||
return ResponseComposer::json($result->toApiOutput());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user