mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-28 06:56:05 +00:00
ref
This commit is contained in:
@@ -37,8 +37,9 @@ use Espo\Core\{
|
||||
Api\Response,
|
||||
Exceptions\BadRequest,
|
||||
Exceptions\Error,
|
||||
Exceptions\Forbidden
|
||||
};
|
||||
Exceptions\Forbidden,
|
||||
Select\SearchParams,
|
||||
Select\Where\Item as WhereItem};
|
||||
|
||||
use stdClass;
|
||||
|
||||
@@ -53,22 +54,34 @@ class Notification extends RecordBase
|
||||
*/
|
||||
public function getActionList(Request $request, Response $response): stdClass
|
||||
{
|
||||
$userId = $this->user->getId();
|
||||
$searchParamsAux = $this->searchParamsFetcher->fetch($request);
|
||||
|
||||
$searchParams = $this->searchParamsFetcher->fetch($request);
|
||||
|
||||
$offset = $searchParams->getOffset();
|
||||
$maxSize = $searchParams->getMaxSize();
|
||||
$offset = $searchParamsAux->getOffset();
|
||||
$maxSize = $searchParamsAux->getMaxSize();
|
||||
|
||||
$after = $request->getQueryParam('after');
|
||||
|
||||
$params = [
|
||||
'offset' => $offset,
|
||||
'maxSize' => $maxSize,
|
||||
'after' => $after,
|
||||
];
|
||||
$searchParams = SearchParams
|
||||
::create()
|
||||
->withOffset($offset)
|
||||
->withMaxSize($maxSize);
|
||||
|
||||
$recordCollection = $this->getNotificationService()->get($userId, $params);
|
||||
if ($after) {
|
||||
$searchParams = $searchParams
|
||||
->withWhereAdded(
|
||||
WhereItem
|
||||
::createBuilder()
|
||||
->setAttribute('createdAt')
|
||||
->setType(WhereItem\Type::AFTER)
|
||||
->setValue($after)
|
||||
->build()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
$userId = $this->user->getId();
|
||||
|
||||
$recordCollection = $this->getNotificationService()->get($userId, $searchParams);
|
||||
|
||||
return (object) [
|
||||
'total' => $recordCollection->getTotal(),
|
||||
|
||||
@@ -32,6 +32,8 @@ namespace Espo\Tools\Notification;
|
||||
use Espo\Core\Acl;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\Record\Collection as RecordCollection;
|
||||
use Espo\Core\Select\SearchParams;
|
||||
use Espo\Core\Select\SelectBuilderFactory;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\Entities\Note;
|
||||
use Espo\Entities\Notification;
|
||||
@@ -46,38 +48,37 @@ class RecordService
|
||||
private Acl $acl;
|
||||
private Metadata $metadata;
|
||||
private NoteAccessControl $noteAccessControl;
|
||||
private SelectBuilderFactory $selectBuilderFactory;
|
||||
|
||||
public function __construct(
|
||||
EntityManager $entityManager,
|
||||
Acl $acl,
|
||||
Metadata $metadata,
|
||||
NoteAccessControl $noteAccessControl
|
||||
NoteAccessControl $noteAccessControl,
|
||||
SelectBuilderFactory $selectBuilderFactory
|
||||
) {
|
||||
$this->entityManager = $entityManager;
|
||||
$this->acl = $acl;
|
||||
$this->metadata = $metadata;
|
||||
$this->noteAccessControl = $noteAccessControl;
|
||||
$this->selectBuilderFactory = $selectBuilderFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Use params class FetchParams.
|
||||
* Get notifications for a user.
|
||||
*
|
||||
* @param array{
|
||||
* after?: ?string,
|
||||
* offset?: ?int,
|
||||
* maxSize?: ?int,
|
||||
* } $params
|
||||
* @return RecordCollection<Notification>
|
||||
* @throws Error
|
||||
*/
|
||||
public function get(string $userId, array $params = []): RecordCollection
|
||||
public function get(string $userId, SearchParams $searchParams): RecordCollection
|
||||
{
|
||||
$queryBuilder = $this->entityManager
|
||||
->getQueryBuilder()
|
||||
->select()
|
||||
->from(Notification::ENTITY_TYPE);
|
||||
|
||||
$whereClause = ['userId' => $userId];
|
||||
$queryBuilder = $this->selectBuilderFactory
|
||||
->create()
|
||||
->from(Notification::ENTITY_TYPE)
|
||||
->withSearchParams($searchParams)
|
||||
->buildQueryBuilder()
|
||||
->where(['userId' => $userId])
|
||||
->order('number', SearchParams::ORDER_DESC);
|
||||
|
||||
$user = $this->entityManager
|
||||
->getRDBRepositoryByClass(User::class)
|
||||
@@ -87,33 +88,17 @@ class RecordService
|
||||
throw new Error("User not found.");
|
||||
}
|
||||
|
||||
if (!empty($params['after'])) {
|
||||
$whereClause['createdAt>'] = $params['after'];
|
||||
}
|
||||
|
||||
$ignoreScopeList = $this->getIgnoreScopeList();
|
||||
|
||||
if (!empty($ignoreScopeList)) {
|
||||
$where = [];
|
||||
|
||||
$where[] = [
|
||||
if ($ignoreScopeList !== []) {
|
||||
$queryBuilder->where([
|
||||
'OR' => [
|
||||
'relatedParentType' => null,
|
||||
'relatedParentType!=' => $ignoreScopeList,
|
||||
]
|
||||
];
|
||||
|
||||
$whereClause[] = $where;
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
$offset = $params['offset'] ?? null;
|
||||
$maxSize = $params['maxSize'] ?? null;
|
||||
|
||||
$queryBuilder
|
||||
->limit($offset, $maxSize)
|
||||
->order('createdAt', 'DESC')
|
||||
->where($whereClause);
|
||||
|
||||
$query = $queryBuilder->build();
|
||||
|
||||
$collection = $this->entityManager
|
||||
|
||||
Reference in New Issue
Block a user