new api 2.0
This commit is contained in:
parent
daa2a09e82
commit
b3dd6cbb4c
|
@ -1,5 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PandoraFMS\Modules\Events\Repositories\EventRepository;
|
||||||
|
use PandoraFMS\Modules\Events\Repositories\EventRepositoryMySQL;
|
||||||
use PandoraFMS\Modules\Shared\Repositories\Repository;
|
use PandoraFMS\Modules\Shared\Repositories\Repository;
|
||||||
use PandoraFMS\Modules\Shared\Repositories\RepositoryMySQL;
|
use PandoraFMS\Modules\Shared\Repositories\RepositoryMySQL;
|
||||||
use PandoraFMS\Modules\Users\Repositories\UserRepository;
|
use PandoraFMS\Modules\Users\Repositories\UserRepository;
|
||||||
|
@ -9,10 +11,10 @@ use Slim\App;
|
||||||
use Slim\Factory\AppFactory;
|
use Slim\Factory\AppFactory;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'settings' => function () {
|
'settings' => function () {
|
||||||
return include __DIR__.'/settings.php';
|
return include __DIR__.'/settings.php';
|
||||||
},
|
},
|
||||||
App::class => function (ContainerInterface $container) {
|
App::class => function (ContainerInterface $container) {
|
||||||
AppFactory::setContainer($container);
|
AppFactory::setContainer($container);
|
||||||
|
|
||||||
$app = AppFactory::create();
|
$app = AppFactory::create();
|
||||||
|
@ -33,10 +35,13 @@ return [
|
||||||
|
|
||||||
return $app;
|
return $app;
|
||||||
},
|
},
|
||||||
Repository::class => function (ContainerInterface $container) {
|
Repository::class => function (ContainerInterface $container) {
|
||||||
return $container->get(RepositoryMySQL::class);
|
return $container->get(RepositoryMySQL::class);
|
||||||
},
|
},
|
||||||
UserRepository::class => function (ContainerInterface $container) {
|
UserRepository::class => function (ContainerInterface $container) {
|
||||||
return $container->get(UserRepositoryMySQL::class);
|
return $container->get(UserRepositoryMySQL::class);
|
||||||
},
|
},
|
||||||
|
EventRepository::class => function (ContainerInterface $container) {
|
||||||
|
return $container->get(EventRepositoryMySQL::class);
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
|
@ -826,6 +826,13 @@ function events_get_all(
|
||||||
|
|
||||||
$sql_filters = get_filter_date($filter);
|
$sql_filters = get_filter_date($filter);
|
||||||
|
|
||||||
|
if (isset($filter['id_event']) === true && $filter['id_event'] > 0) {
|
||||||
|
$sql_filters[] = sprintf(
|
||||||
|
' AND te.id_evento = %d ',
|
||||||
|
$filter['id_event']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($filter['id_agent']) === true && $filter['id_agent'] > 0) {
|
if (isset($filter['id_agent']) === true && $filter['id_agent'] > 0) {
|
||||||
$sql_filters[] = sprintf(
|
$sql_filters[] = sprintf(
|
||||||
' AND te.id_agente = %d ',
|
' AND te.id_agente = %d ',
|
||||||
|
|
|
@ -9,6 +9,9 @@ use PandoraFMS\Modules\EventFilters\Enums\EventFilterStatusEnum;
|
||||||
use PandoraFMS\Modules\EventFilters\Validators\EventFilterValidator;
|
use PandoraFMS\Modules\EventFilters\Validators\EventFilterValidator;
|
||||||
use PandoraFMS\Modules\Events\Enums\EventTypeEnum;
|
use PandoraFMS\Modules\Events\Enums\EventTypeEnum;
|
||||||
use PandoraFMS\Modules\Shared\Entities\Entity;
|
use PandoraFMS\Modules\Shared\Entities\Entity;
|
||||||
|
use PandoraFMS\Modules\Shared\Traits\GroupByFilterTrait;
|
||||||
|
use PandoraFMS\Modules\Shared\Traits\OrderFilterTrait;
|
||||||
|
use PandoraFMS\Modules\Shared\Traits\PaginationFilterTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @OA\Schema(
|
* @OA\Schema(
|
||||||
|
@ -392,6 +395,12 @@ use PandoraFMS\Modules\Shared\Entities\Entity;
|
||||||
*/
|
*/
|
||||||
final class EventFilter extends Entity
|
final class EventFilter extends Entity
|
||||||
{
|
{
|
||||||
|
use PaginationFilterTrait;
|
||||||
|
use OrderFilterTrait;
|
||||||
|
use GroupByFilterTrait;
|
||||||
|
|
||||||
|
private ?int $idEvent = null;
|
||||||
|
|
||||||
private ?int $idEventFilter = null;
|
private ?int $idEventFilter = null;
|
||||||
private ?int $idGroupFilter = null;
|
private ?int $idGroupFilter = null;
|
||||||
private ?string $name = null;
|
private ?string $name = null;
|
||||||
|
@ -437,10 +446,28 @@ final class EventFilter extends Entity
|
||||||
return ['idEventFilter' => 1];
|
return ['idEventFilter' => 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function toTranslateFilters(): array
|
||||||
|
{
|
||||||
|
$eventFilterFilter = new EventFilterFilter();
|
||||||
|
$filter_translate = $eventFilterFilter->fieldsTranslate();
|
||||||
|
|
||||||
|
$result = [];
|
||||||
|
foreach ($this->toArray() as $key => $value) {
|
||||||
|
if (isset($filter_translate[$key]) === true
|
||||||
|
&& $value !== null
|
||||||
|
) {
|
||||||
|
$result[$filter_translate[$key]] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
public function jsonSerialize(): mixed
|
public function jsonSerialize(): mixed
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'idEventFilter' => $this->getIdEventFilter(),
|
'idEventFilter' => $this->getIdEventFilter(),
|
||||||
|
'idEvent' => $this->getIdEvent(),
|
||||||
'idGroupFilter' => $this->getIdGroupFilter(),
|
'idGroupFilter' => $this->getIdGroupFilter(),
|
||||||
'name' => $this->getName(),
|
'name' => $this->getName(),
|
||||||
'idGroup' => $this->getIdGroup(),
|
'idGroup' => $this->getIdGroup(),
|
||||||
|
@ -485,6 +512,10 @@ final class EventFilter extends Entity
|
||||||
EventFilterValidator::INTEGER,
|
EventFilterValidator::INTEGER,
|
||||||
EventFilterValidator::GREATERTHAN,
|
EventFilterValidator::GREATERTHAN,
|
||||||
],
|
],
|
||||||
|
'idEvent' => [
|
||||||
|
EventFilterValidator::INTEGER,
|
||||||
|
EventFilterValidator::GREATERTHAN,
|
||||||
|
],
|
||||||
'idGroupFilter' => [
|
'idGroupFilter' => [
|
||||||
EventFilterValidator::INTEGER,
|
EventFilterValidator::INTEGER,
|
||||||
EventFilterValidator::GREATEREQUALTHAN,
|
EventFilterValidator::GREATEREQUALTHAN,
|
||||||
|
@ -921,4 +952,14 @@ final class EventFilter extends Entity
|
||||||
$this->regex = $regex;
|
$this->regex = $regex;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getIdEvent(): ?int
|
||||||
|
{
|
||||||
|
return $this->idEvent;
|
||||||
|
}
|
||||||
|
public function setIdEvent(?int $idEvent): self
|
||||||
|
{
|
||||||
|
$this->idEvent = $idEvent;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,8 +51,44 @@ final class EventFilterFilter extends FilterAbstract
|
||||||
public function fieldsTranslate(): array
|
public function fieldsTranslate(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'idEventFilter' => EventFilterDataMapper::ID_FILTER,
|
'idEventFilter' => EventFilterDataMapper::ID_FILTER,
|
||||||
'name' => EventFilterDataMapper::NAME,
|
'idEvent' => 'id_event',
|
||||||
|
'name' => EventFilterDataMapper::NAME,
|
||||||
|
'idEventFilter' => EventFilterDataMapper::ID_FILTER,
|
||||||
|
'idGroupFilter' => EventFilterDataMapper::ID_GROUP_FILTER,
|
||||||
|
'name' => EventFilterDataMapper::NAME,
|
||||||
|
'idGroup' => EventFilterDataMapper::ID_GROUP,
|
||||||
|
'eventType' => EventFilterDataMapper::EVENT_TYPE,
|
||||||
|
'severity' => EventFilterDataMapper::SEVERITY,
|
||||||
|
'status' => EventFilterDataMapper::STATUS,
|
||||||
|
'search' => EventFilterDataMapper::SEARCH,
|
||||||
|
'isNotSearch' => EventFilterDataMapper::NOT_SEARCH,
|
||||||
|
'textAgent' => EventFilterDataMapper::TEXT_AGENT,
|
||||||
|
'idAgent' => EventFilterDataMapper::ID_AGENT,
|
||||||
|
'idAgentModule' => EventFilterDataMapper::ID_AGENT_MODULE,
|
||||||
|
'pagination' => EventFilterDataMapper::PAGINATION,
|
||||||
|
'slice' => EventFilterDataMapper::SLICE,
|
||||||
|
'idUserAck' => EventFilterDataMapper::ID_USER_ACK,
|
||||||
|
'groupBy' => EventFilterDataMapper::ORDER_BY,
|
||||||
|
'tagWith' => EventFilterDataMapper::TAG_WITH,
|
||||||
|
'tagWithout' => EventFilterDataMapper::TAG_WITHOUT,
|
||||||
|
'filterOnlyAlert' => EventFilterDataMapper::FILTER_ONLY_ALERT,
|
||||||
|
'searchSecondaryGroups' => EventFilterDataMapper::SEARCH_SECONDARY_GROUPS,
|
||||||
|
'searchRecursiveGroups' => EventFilterDataMapper::SEARCH_RECURSIVE_GROUPS,
|
||||||
|
'dateFrom' => EventFilterDataMapper::DATE_FROM,
|
||||||
|
'dateTo' => EventFilterDataMapper::DATE_TO,
|
||||||
|
'source' => EventFilterDataMapper::SOURCE,
|
||||||
|
'idExtra' => EventFilterDataMapper::ID_EXTRA,
|
||||||
|
'userComment' => EventFilterDataMapper::USER_COMMENT,
|
||||||
|
'idSourceEvent' => EventFilterDataMapper::ID_SOURCE_EVENT,
|
||||||
|
'serverId' => EventFilterDataMapper::SERVER_ID,
|
||||||
|
'timeFrom' => EventFilterDataMapper::TIME_FROM,
|
||||||
|
'timeTo' => EventFilterDataMapper::TIME_TO,
|
||||||
|
'customData' => EventFilterDataMapper::CUSTOM_DATA,
|
||||||
|
'customDataFilterType' => EventFilterDataMapper::CUSTOM_DATA_FILTER_TYPE,
|
||||||
|
'ownerUser' => EventFilterDataMapper::OWNER_USER,
|
||||||
|
'privateFilterUser' => EventFilterDataMapper::PRIVATE_FILTER_USER,
|
||||||
|
'regex' => EventFilterDataMapper::REGEX,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace PandoraFMS\Modules\Events\Actions;
|
namespace PandoraFMS\Modules\Events\Actions;
|
||||||
|
|
||||||
use PandoraFMS\Modules\Events\Entities\EventFilter;
|
use PandoraFMS\Modules\EventFilters\Entities\EventFilter;
|
||||||
use PandoraFMS\Modules\Events\Services\CountEventService;
|
use PandoraFMS\Modules\Events\Services\CountEventService;
|
||||||
use PandoraFMS\Modules\Events\Services\ListEventService;
|
use PandoraFMS\Modules\Events\Services\ListEventService;
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ final class DeleteEventController extends Controller
|
||||||
$idEvent = $this->getParam($request, 'idEvent');
|
$idEvent = $this->getParam($request, 'idEvent');
|
||||||
$event = $this->getEventAction->__invoke($idEvent);
|
$event = $this->getEventAction->__invoke($idEvent);
|
||||||
|
|
||||||
//$this->acl->validate(0, 'UM', ' tried to manage event');
|
$this->acl->validate(0, 'EM', ' tried to manage event');
|
||||||
|
|
||||||
$result = $this->deleteEventAction->__invoke($event);
|
$result = $this->deleteEventAction->__invoke($event);
|
||||||
return $this->getResponse($response, $result);
|
return $this->getResponse($response, $result);
|
||||||
|
|
|
@ -36,7 +36,7 @@ final class GetEventController extends Controller
|
||||||
{
|
{
|
||||||
$idEvent = $this->getParam($request, 'idEvent');
|
$idEvent = $this->getParam($request, 'idEvent');
|
||||||
|
|
||||||
//$this->acl->validate(0, 'UM', ' tried to manage event');
|
$this->acl->validate(0, 'ER', ' tried to manage event');
|
||||||
|
|
||||||
$result = $this->getEventAction->__invoke($idEvent);
|
$result = $this->getEventAction->__invoke($idEvent);
|
||||||
return $this->getResponse($response, $result);
|
return $this->getResponse($response, $result);
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
namespace PandoraFMS\Modules\Events\Controllers;
|
namespace PandoraFMS\Modules\Events\Controllers;
|
||||||
|
|
||||||
use PandoraFMS\Modules\Events\Actions\ListEventAction;
|
use PandoraFMS\Modules\Events\Actions\ListEventAction;
|
||||||
use PandoraFMS\Modules\Events\Entities\EventFilter;
|
use PandoraFMS\Modules\EventFilters\Entities\EventFilter;
|
||||||
use PandoraFMS\Modules\Shared\Controllers\Controller;
|
use PandoraFMS\Modules\Shared\Controllers\Controller;
|
||||||
use PandoraFMS\Modules\Shared\Services\ValidateAclSystem;
|
use PandoraFMS\Modules\Shared\Services\ValidateAclSystem;
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ final class ListEventController extends Controller
|
||||||
// @var EventFilter $eventFilter.
|
// @var EventFilter $eventFilter.
|
||||||
$eventFilter = $this->fromRequest($request, EventFilter::class);
|
$eventFilter = $this->fromRequest($request, EventFilter::class);
|
||||||
|
|
||||||
//$this->acl->validate(0, 'UM', ' tried to manage event');
|
$this->acl->validate(0, 'ER', ' tried to read event');
|
||||||
|
|
||||||
$result = $this->listEventAction->__invoke($eventFilter);
|
$result = $this->listEventAction->__invoke($eventFilter);
|
||||||
return $this->getResponse($response, $result);
|
return $this->getResponse($response, $result);
|
||||||
|
|
|
@ -44,7 +44,7 @@ final class UpdateEventController extends Controller
|
||||||
$params = $this->extractParams($request);
|
$params = $this->extractParams($request);
|
||||||
$event->fromArray($params);
|
$event->fromArray($params);
|
||||||
|
|
||||||
//$this->acl->validate(0, 'UM', ' tried to manage event');
|
$this->acl->validate(0, 'EW', ' tried to write event');
|
||||||
|
|
||||||
$result = $this->updateEventAction->__invoke($event, $oldEvent);
|
$result = $this->updateEventAction->__invoke($event, $oldEvent);
|
||||||
return $this->getResponse($response, $result);
|
return $this->getResponse($response, $result);
|
||||||
|
|
|
@ -1,87 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace PandoraFMS\Modules\Events\Entities;
|
|
||||||
|
|
||||||
use PandoraFMS\Modules\Events\Validators\EventValidator;
|
|
||||||
use PandoraFMS\Modules\Shared\Core\FilterAbstract;
|
|
||||||
|
|
||||||
|
|
||||||
final class EventFilter extends FilterAbstract
|
|
||||||
{
|
|
||||||
private ?string $freeSearch = null;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->setDefaultFieldOrder(EventDataMapper::UTIMESTAMP);
|
|
||||||
$this->setDefaultDirectionOrder($this::ASC);
|
|
||||||
$this->setEntityFilter(new Event());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function fieldsTranslate(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'idEvent' => EventDataMapper::ID_EVENT,
|
|
||||||
'utimestamp' => EventDataMapper::UTIMESTAMP,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function fieldsReadOnly(): array
|
|
||||||
{
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function jsonSerialize(): mixed
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'freeSearch' => $this->getFreeSearch(),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getValidations(): array
|
|
||||||
{
|
|
||||||
$validations = [];
|
|
||||||
if($this->getEntityFilter() !== null) {
|
|
||||||
$validations = $this->getEntityFilter()->getValidations();
|
|
||||||
}
|
|
||||||
$validations['freeSearch'] = EventValidator::STRING;
|
|
||||||
return $validations;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function validateFields(array $filters): array
|
|
||||||
{
|
|
||||||
return (new EventValidator())->validate($filters);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the value of freeSearch.
|
|
||||||
*
|
|
||||||
* @return ?string
|
|
||||||
*/
|
|
||||||
public function getFreeSearch(): ?string
|
|
||||||
{
|
|
||||||
return $this->freeSearch;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the value of freeSearch.
|
|
||||||
*
|
|
||||||
* @param ?string $freeSearch
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function setFreeSearch(?string $freeSearch): self
|
|
||||||
{
|
|
||||||
$this->freeSearch = $freeSearch;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the value of fieldsFreeSearch.
|
|
||||||
*
|
|
||||||
* @return ?array
|
|
||||||
*/
|
|
||||||
public function getFieldsFreeSearch(): ?array
|
|
||||||
{
|
|
||||||
return [EventDataMapper::UTIMESTAMP];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -2,64 +2,23 @@
|
||||||
|
|
||||||
namespace PandoraFMS\Modules\Events\Repositories;
|
namespace PandoraFMS\Modules\Events\Repositories;
|
||||||
|
|
||||||
|
use PandoraFMS\Modules\EventFilters\Entities\EventFilter;
|
||||||
use PandoraFMS\Modules\Events\Entities\Event;
|
use PandoraFMS\Modules\Events\Entities\Event;
|
||||||
use PandoraFMS\Modules\Events\Entities\EventDataMapper;
|
|
||||||
use PandoraFMS\Modules\Events\Entities\EventFilter;
|
|
||||||
use PandoraFMS\Modules\Shared\Repositories\Repository;
|
|
||||||
|
|
||||||
class EventRepository
|
interface EventRepository
|
||||||
{
|
{
|
||||||
public function __construct(
|
|
||||||
private Repository $repository,
|
|
||||||
private EventDataMapper $eventDataMapper
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Event[],
|
* @return Event[],
|
||||||
*/
|
*/
|
||||||
public function list(EventFilter $eventFilter): array
|
public function list(EventFilter $eventFilter): array;
|
||||||
{
|
|
||||||
return $this->repository->__list(
|
|
||||||
$eventFilter,
|
|
||||||
$this->eventDataMapper
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function count(EventFilter $eventFilter): int
|
public function count(EventFilter $eventFilter): int;
|
||||||
{
|
|
||||||
return $this->repository->__count(
|
|
||||||
$eventFilter,
|
|
||||||
$this->eventDataMapper
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getOne(EventFilter $eventFilter): Event
|
public function getOne(EventFilter $eventFilter): Event;
|
||||||
{
|
|
||||||
return $this->repository->__getOne(
|
|
||||||
$eventFilter,
|
|
||||||
$this->eventDataMapper
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function create(Event $event): Event
|
public function create(Event $event): Event;
|
||||||
{
|
|
||||||
$id = $this->repository->__create($event, $this->eventDataMapper);
|
|
||||||
return $event->setIdEvent($id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function update(Event $event): Event
|
public function update(Event $event): Event;
|
||||||
{
|
|
||||||
return $this->repository->__update(
|
|
||||||
$event,
|
|
||||||
$this->eventDataMapper,
|
|
||||||
$event->getIdEvent()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function delete(int $id): void
|
|
||||||
{
|
|
||||||
$this->repository->__delete($id, $this->eventDataMapper);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public function delete(string $id): void;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,168 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PandoraFMS\Modules\Events\Repositories;
|
||||||
|
|
||||||
|
use InvalidArgumentException;
|
||||||
|
use PandoraFMS\Core\Config;
|
||||||
|
use PandoraFMS\Modules\EventFilters\Entities\EventFilter;
|
||||||
|
use PandoraFMS\Modules\Events\Entities\Event;
|
||||||
|
use PandoraFMS\Modules\Events\Entities\EventDataMapper;
|
||||||
|
use PandoraFMS\Modules\Shared\Enums\HttpCodesEnum;
|
||||||
|
use PandoraFMS\Modules\Shared\Exceptions\NotFoundException;
|
||||||
|
use PandoraFMS\Modules\Shared\Repositories\RepositoryMySQL;
|
||||||
|
|
||||||
|
class EventRepositoryMySQL extends RepositoryMySQL implements EventRepository
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private EventDataMapper $eventDataMapper,
|
||||||
|
private Config $config
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Event[],
|
||||||
|
*/
|
||||||
|
public function list(EventFilter $eventFilter): array
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$fields = ['te.*'];
|
||||||
|
$filter = $eventFilter->toTranslateFilters();
|
||||||
|
$offset = ($eventFilter->getPage() ?? null);
|
||||||
|
$limit = ($eventFilter->getSizePage() ?? null);
|
||||||
|
$order = ($eventFilter->getSortDirection() ?? null);
|
||||||
|
$sort_field = ($eventFilter->getSortField() ?? null);
|
||||||
|
|
||||||
|
$list = $this->getEvents(
|
||||||
|
$fields,
|
||||||
|
$filter,
|
||||||
|
$offset,
|
||||||
|
$limit,
|
||||||
|
$order,
|
||||||
|
$sort_field
|
||||||
|
);
|
||||||
|
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
// Capture errors mysql.
|
||||||
|
throw new InvalidArgumentException(
|
||||||
|
strip_tags($th->getMessage()),
|
||||||
|
HttpCodesEnum::INTERNAL_SERVER_ERROR
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_array($list) === false) {
|
||||||
|
throw new NotFoundException(__('%s not found', $this->eventDataMapper->getStringNameClass()));
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = [];
|
||||||
|
foreach ($list as $fields) {
|
||||||
|
$result[] = $this->eventDataMapper->fromDatabase($fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function count(EventFilter $eventFilter): int
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$fields = ['count'];
|
||||||
|
$filter = $eventFilter->toTranslateFilters();
|
||||||
|
$count = $this->getEvents(
|
||||||
|
$fields,
|
||||||
|
$filter
|
||||||
|
);
|
||||||
|
|
||||||
|
if (empty($count) === false
|
||||||
|
&& isset($count[0]) === true
|
||||||
|
&& isset($count[0]['nitems']) === true
|
||||||
|
&& empty($count[0]['nitems']) === false
|
||||||
|
) {
|
||||||
|
$count = $count[0]['nitems'];
|
||||||
|
}
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
// Capture errors mysql.
|
||||||
|
throw new InvalidArgumentException(
|
||||||
|
strip_tags($th->getMessage()),
|
||||||
|
HttpCodesEnum::INTERNAL_SERVER_ERROR
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (int) $count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getOne(EventFilter $eventFilter): Event
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$fields = ['te.*'];
|
||||||
|
$filter = $eventFilter->toTranslateFilters();
|
||||||
|
$result = $this->getEvents(
|
||||||
|
$fields,
|
||||||
|
$filter
|
||||||
|
);
|
||||||
|
|
||||||
|
if (empty($result) === false
|
||||||
|
&& isset($result[0]) === true
|
||||||
|
) {
|
||||||
|
$result = $result[0];
|
||||||
|
}
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
// Capture errors mysql.
|
||||||
|
throw new InvalidArgumentException(
|
||||||
|
strip_tags($th->getMessage()),
|
||||||
|
HttpCodesEnum::INTERNAL_SERVER_ERROR
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($result) === true) {
|
||||||
|
throw new NotFoundException(__('%s not found', $this->eventDataMapper->getStringNameClass()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->eventDataMapper->fromDatabase($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(Event $event): Event
|
||||||
|
{
|
||||||
|
$this->__create($event, $this->eventDataMapper);
|
||||||
|
return $event;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(Event $event): Event
|
||||||
|
{
|
||||||
|
return $this->__update(
|
||||||
|
$event,
|
||||||
|
$this->eventDataMapper,
|
||||||
|
$event->getIdEvent()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete(string $id): void
|
||||||
|
{
|
||||||
|
$this->__delete($id, $this->eventDataMapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEvents(
|
||||||
|
$fields,
|
||||||
|
$filter,
|
||||||
|
$offset = null,
|
||||||
|
$limit = null,
|
||||||
|
$order = null,
|
||||||
|
$sort_field = null
|
||||||
|
): array {
|
||||||
|
// TODO: XXX.
|
||||||
|
$history = true;
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
require_once $this->config->get('homedir').'/include/functions_events.php';
|
||||||
|
$list = \events_get_all(
|
||||||
|
$fields,
|
||||||
|
$filter,
|
||||||
|
$offset,
|
||||||
|
$limit,
|
||||||
|
$order,
|
||||||
|
$sort_field,
|
||||||
|
$history
|
||||||
|
);
|
||||||
|
ob_get_clean();
|
||||||
|
|
||||||
|
return $list;
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace PandoraFMS\Modules\Events\Services;
|
namespace PandoraFMS\Modules\Events\Services;
|
||||||
|
|
||||||
use PandoraFMS\Modules\Events\Entities\EventFilter;
|
use PandoraFMS\Modules\EventFilters\Entities\EventFilter;
|
||||||
use PandoraFMS\Modules\Events\Repositories\EventRepository;
|
use PandoraFMS\Modules\Events\Repositories\EventRepository;
|
||||||
|
|
||||||
final class CountEventService
|
final class CountEventService
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
namespace PandoraFMS\Modules\Events\Services;
|
namespace PandoraFMS\Modules\Events\Services;
|
||||||
|
|
||||||
use PandoraFMS\Modules\Events\Entities\Event;
|
use PandoraFMS\Modules\Events\Entities\Event;
|
||||||
use PandoraFMS\Modules\Events\Entities\EventFilter;
|
use PandoraFMS\Modules\EventFilters\Entities\EventFilter;
|
||||||
use PandoraFMS\Modules\Events\Repositories\EventRepository;
|
use PandoraFMS\Modules\Events\Repositories\EventRepository;
|
||||||
|
|
||||||
final class GetEventService
|
final class GetEventService
|
||||||
|
@ -16,9 +16,7 @@ final class GetEventService
|
||||||
public function __invoke(int $idEvent): Event
|
public function __invoke(int $idEvent): Event
|
||||||
{
|
{
|
||||||
$eventFilter = new EventFilter();
|
$eventFilter = new EventFilter();
|
||||||
/** @var Event $entityFilter */
|
$eventFilter->setIdEvent($idEvent);
|
||||||
$entityFilter = $eventFilter->getEntityFilter();
|
|
||||||
$entityFilter->setIdEvent($idEvent);
|
|
||||||
|
|
||||||
return $this->eventRepository->getOne($eventFilter);
|
return $this->eventRepository->getOne($eventFilter);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace PandoraFMS\Modules\Events\Services;
|
namespace PandoraFMS\Modules\Events\Services;
|
||||||
|
|
||||||
use PandoraFMS\Modules\Events\Entities\EventFilter;
|
use PandoraFMS\Modules\EventFilters\Entities\EventFilter;
|
||||||
use PandoraFMS\Modules\Events\Repositories\EventRepository;
|
use PandoraFMS\Modules\Events\Repositories\EventRepository;
|
||||||
|
|
||||||
final class ListEventService
|
final class ListEventService
|
||||||
|
|
Loading…
Reference in New Issue