Initial commit
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Crm\Tools\Calendar\Api;
|
||||
|
||||
use Espo\Core\Api\Action;
|
||||
use Espo\Core\Api\Request;
|
||||
use Espo\Core\Api\Response;
|
||||
use Espo\Core\Api\ResponseComposer;
|
||||
use Espo\Core\Exceptions\BadRequest;
|
||||
use Espo\Core\Field\DateTime;
|
||||
use Espo\Modules\Crm\Tools\Calendar\Item as CalendarItem;
|
||||
use Espo\Modules\Crm\Tools\Calendar\Service;
|
||||
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Busy-ranges.
|
||||
*/
|
||||
class GetBusyRanges implements Action
|
||||
{
|
||||
public function __construct(private Service $calendarService) {}
|
||||
|
||||
public function process(Request $request): Response
|
||||
{
|
||||
$from = $request->getQueryParam('from');
|
||||
$to = $request->getQueryParam('to');
|
||||
$userIdListString = $request->getQueryParam('userIdList');
|
||||
|
||||
if (!$from || !$to || !$userIdListString) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
$userIdList = explode(',', $userIdListString);
|
||||
|
||||
$map = $this->calendarService->fetchBusyRangesForUsers(
|
||||
$userIdList,
|
||||
DateTime::fromString($from),
|
||||
DateTime::fromString($to),
|
||||
$request->getQueryParam('entityType'),
|
||||
$request->getQueryParam('entityId')
|
||||
);
|
||||
|
||||
$result = (object) [];
|
||||
|
||||
foreach ($map as $userId => $itemList) {
|
||||
$result->$userId = self::itemListToRaw($itemList);
|
||||
}
|
||||
|
||||
return ResponseComposer::json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CalendarItem[] $itemList
|
||||
* @return stdClass[]
|
||||
*/
|
||||
private static function itemListToRaw(array $itemList): array
|
||||
{
|
||||
return array_map(fn (CalendarItem $item) => $item->getRaw(), $itemList);
|
||||
}
|
||||
}
|
||||
138
application/Espo/Modules/Crm/Tools/Calendar/Api/GetCalendar.php
Normal file
138
application/Espo/Modules/Crm/Tools/Calendar/Api/GetCalendar.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Crm\Tools\Calendar\Api;
|
||||
|
||||
use Espo\Core\Api\Action;
|
||||
use Espo\Core\Api\Request;
|
||||
use Espo\Core\Api\Response;
|
||||
use Espo\Core\Api\ResponseComposer;
|
||||
use Espo\Core\Exceptions\BadRequest;
|
||||
use Espo\Core\Exceptions\Forbidden;
|
||||
use Espo\Core\Acl;
|
||||
use Espo\Core\Field\DateTime;
|
||||
use Espo\Entities\User;
|
||||
use Espo\Modules\Crm\Tools\Calendar\FetchParams;
|
||||
use Espo\Modules\Crm\Tools\Calendar\Item as CalendarItem;
|
||||
use Espo\Modules\Crm\Tools\Calendar\Service;
|
||||
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Calendar events.
|
||||
*/
|
||||
class GetCalendar implements Action
|
||||
{
|
||||
private const MAX_CALENDAR_RANGE = 123;
|
||||
|
||||
public function __construct(
|
||||
private Service $calendarService,
|
||||
private Acl $acl,
|
||||
private User $user
|
||||
) {}
|
||||
|
||||
public function process(Request $request): Response
|
||||
{
|
||||
if (!$this->acl->check('Calendar')) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
$from = $request->getQueryParam('from');
|
||||
$to = $request->getQueryParam('to');
|
||||
$isAgenda = $request->getQueryParam('agenda') === 'true';
|
||||
|
||||
if (empty($from) || empty($to)) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
if (strtotime($to) - strtotime($from) > self::MAX_CALENDAR_RANGE * 24 * 3600) {
|
||||
throw new Forbidden('Too long range.');
|
||||
}
|
||||
|
||||
$scopeList = null;
|
||||
|
||||
if ($request->getQueryParam('scopeList') !== null) {
|
||||
$scopeList = explode(',', $request->getQueryParam('scopeList'));
|
||||
}
|
||||
|
||||
$userId = $request->getQueryParam('userId');
|
||||
$userIdList = $request->getQueryParam('userIdList');
|
||||
$teamIdList = $request->getQueryParam('teamIdList');
|
||||
|
||||
$fetchParams = FetchParams
|
||||
::create(
|
||||
DateTime::fromString($from),
|
||||
DateTime::fromString($to)
|
||||
)
|
||||
->withScopeList($scopeList);
|
||||
|
||||
if ($teamIdList) {
|
||||
$teamIdList = explode(',', $teamIdList);
|
||||
|
||||
$raw = self::itemListToRaw(
|
||||
$this->calendarService->fetchForTeams($teamIdList, $fetchParams)
|
||||
);
|
||||
|
||||
return ResponseComposer::json($raw);
|
||||
}
|
||||
|
||||
if ($userIdList) {
|
||||
$userIdList = explode(',', $userIdList);
|
||||
|
||||
$raw = self::itemListToRaw(
|
||||
$this->calendarService->fetchForUsers($userIdList, $fetchParams)
|
||||
);
|
||||
|
||||
return ResponseComposer::json($raw);
|
||||
}
|
||||
|
||||
if (!$userId) {
|
||||
$userId = $this->user->getId();
|
||||
}
|
||||
|
||||
$fetchParams = $fetchParams
|
||||
->withIsAgenda($isAgenda)
|
||||
->withWorkingTimeRanges();
|
||||
|
||||
$raw = self::itemListToRaw(
|
||||
$this->calendarService->fetch($userId, $fetchParams)
|
||||
);
|
||||
|
||||
return ResponseComposer::json($raw);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CalendarItem[] $itemList
|
||||
* @return stdClass[]
|
||||
*/
|
||||
private static function itemListToRaw(array $itemList): array
|
||||
{
|
||||
return array_map(fn (CalendarItem $item) => $item->getRaw(), $itemList);
|
||||
}
|
||||
}
|
||||
116
application/Espo/Modules/Crm/Tools/Calendar/Api/GetTimeline.php
Normal file
116
application/Espo/Modules/Crm/Tools/Calendar/Api/GetTimeline.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Crm\Tools\Calendar\Api;
|
||||
|
||||
use Espo\Core\Api\Action;
|
||||
use Espo\Core\Api\Request;
|
||||
use Espo\Core\Api\Response;
|
||||
use Espo\Core\Api\ResponseComposer;
|
||||
use Espo\Core\Exceptions\BadRequest;
|
||||
use Espo\Core\Exceptions\Forbidden;
|
||||
use Espo\Core\Acl;
|
||||
use Espo\Core\Field\DateTime;
|
||||
use Espo\Modules\Crm\Tools\Calendar\FetchParams;
|
||||
use Espo\Modules\Crm\Tools\Calendar\Item as CalendarItem;
|
||||
use Espo\Modules\Crm\Tools\Calendar\Service;
|
||||
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Get timeline items.
|
||||
*/
|
||||
class GetTimeline implements Action
|
||||
{
|
||||
private const MAX_CALENDAR_RANGE = 123;
|
||||
|
||||
public function __construct(
|
||||
private Service $calendarService,
|
||||
private Acl $acl
|
||||
) {}
|
||||
|
||||
public function process(Request $request): Response
|
||||
{
|
||||
if (!$this->acl->check('Calendar')) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
$from = $request->getQueryParam('from');
|
||||
$to = $request->getQueryParam('to');
|
||||
|
||||
if (empty($from) || empty($to)) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
if (strtotime($to) - strtotime($from) > self::MAX_CALENDAR_RANGE * 24 * 3600) {
|
||||
throw new Forbidden('Too long range.');
|
||||
}
|
||||
|
||||
$scopeList = null;
|
||||
|
||||
if ($request->getQueryParam('scopeList') !== null) {
|
||||
$scopeList = explode(',', $request->getQueryParam('scopeList'));
|
||||
}
|
||||
|
||||
$userId = $request->getQueryParam('userId');
|
||||
$userIdList = $request->getQueryParam('userIdList');
|
||||
|
||||
$userIdList = $userIdList ? explode(',', $userIdList) : [];
|
||||
|
||||
if ($userId) {
|
||||
$userIdList[] = $userId;
|
||||
}
|
||||
|
||||
$fetchParams = FetchParams
|
||||
::create(
|
||||
DateTime::fromString($from . ':00'),
|
||||
DateTime::fromString($to . ':00')
|
||||
)
|
||||
->withScopeList($scopeList);
|
||||
|
||||
$map = $this->calendarService->fetchTimelineForUsers($userIdList, $fetchParams);
|
||||
|
||||
$result = (object) [];
|
||||
|
||||
foreach ($map as $userId => $itemList) {
|
||||
$result->$userId = self::itemListToRaw($itemList);
|
||||
}
|
||||
|
||||
return ResponseComposer::json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CalendarItem[] $itemList
|
||||
* @return stdClass[]
|
||||
*/
|
||||
private static function itemListToRaw(array $itemList): array
|
||||
{
|
||||
return array_map(fn (CalendarItem $item) => $item->getRaw(), $itemList);
|
||||
}
|
||||
}
|
||||
152
application/Espo/Modules/Crm/Tools/Calendar/FetchParams.php
Normal file
152
application/Espo/Modules/Crm/Tools/Calendar/FetchParams.php
Normal file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Crm\Tools\Calendar;
|
||||
|
||||
use Espo\Core\Field\DateTime;
|
||||
|
||||
class FetchParams
|
||||
{
|
||||
private DateTime $from;
|
||||
private DateTime $to;
|
||||
private bool $isAgenda = false;
|
||||
private bool $skipAcl = false;
|
||||
/** @var ?string[] */
|
||||
private ?array $scopeList = null;
|
||||
private bool $workingTimeRanges = false;
|
||||
private bool $workingTimeRangesInverted = false;
|
||||
|
||||
public function __construct(DateTime $from, DateTime $to)
|
||||
{
|
||||
$this->from = $from;
|
||||
$this->to = $to;
|
||||
}
|
||||
|
||||
public static function create(DateTime $from, DateTime $to): self
|
||||
{
|
||||
return new self($from, $to);
|
||||
}
|
||||
|
||||
public function withFrom(DateTime $from): self
|
||||
{
|
||||
$obj = clone $this;
|
||||
$obj->from = $from;
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public function withTo(DateTime $to): self
|
||||
{
|
||||
$obj = clone $this;
|
||||
$obj->to = $to;
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public function withIsAgenda(bool $isAgenda = true): self
|
||||
{
|
||||
$obj = clone $this;
|
||||
$obj->isAgenda = $isAgenda;
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public function withSkipAcl(bool $skipAcl = true): self
|
||||
{
|
||||
$obj = clone $this;
|
||||
$obj->skipAcl = $skipAcl;
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ?string[] $scopeList
|
||||
*/
|
||||
public function withScopeList(?array $scopeList): self
|
||||
{
|
||||
$obj = clone $this;
|
||||
$obj->scopeList = $scopeList;
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public function withWorkingTimeRanges(bool $workingTimeRanges = true): self
|
||||
{
|
||||
$obj = clone $this;
|
||||
$obj->workingTimeRanges = $workingTimeRanges;
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public function withWorkingTimeRangesInverted(bool $workingTimeRangesInverted = true): self
|
||||
{
|
||||
$obj = clone $this;
|
||||
$obj->workingTimeRangesInverted = $workingTimeRangesInverted;
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public function getFrom(): DateTime
|
||||
{
|
||||
return $this->from;
|
||||
}
|
||||
|
||||
public function getTo(): DateTime
|
||||
{
|
||||
return $this->to;
|
||||
}
|
||||
|
||||
public function isAgenda(): bool
|
||||
{
|
||||
return $this->isAgenda;
|
||||
}
|
||||
|
||||
public function skipAcl(): bool
|
||||
{
|
||||
return $this->skipAcl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ?string[]
|
||||
*/
|
||||
public function getScopeList(): ?array
|
||||
{
|
||||
return $this->scopeList;
|
||||
}
|
||||
|
||||
public function workingTimeRanges(): bool
|
||||
{
|
||||
return $this->workingTimeRanges;
|
||||
}
|
||||
|
||||
public function workingTimeRangesInverted(): bool
|
||||
{
|
||||
return $this->workingTimeRangesInverted;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Crm\Tools\Calendar\FreeBusy;
|
||||
|
||||
use Espo\Core\Field\DateTime;
|
||||
use Espo\Modules\Crm\Tools\Calendar\Items\Event;
|
||||
|
||||
readonly class FetchParams
|
||||
{
|
||||
/**
|
||||
* @param bool $accessCheck To user apply access check.
|
||||
* @param Event[] $ignoreEventList Events not to be included in a result.
|
||||
*/
|
||||
public function __construct(
|
||||
public DateTime $from,
|
||||
public DateTime $to,
|
||||
public bool $accessCheck = false,
|
||||
public array $ignoreEventList = [],
|
||||
) {}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Crm\Tools\Calendar\FreeBusy;
|
||||
|
||||
use Espo\Core\Exceptions\Forbidden;
|
||||
use Espo\Entities\User;
|
||||
use Espo\Modules\Crm\Tools\Calendar\FetchParams as CalendarFetchParams;
|
||||
use Espo\Modules\Crm\Tools\Calendar\Items\BusyRange;
|
||||
use Espo\Modules\Crm\Tools\Calendar\Service as CalendarService;
|
||||
|
||||
/**
|
||||
* @since 9.0.0
|
||||
*/
|
||||
class Service
|
||||
{
|
||||
public function __construct(
|
||||
private CalendarService $service,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Fetch busy-ranges for user. Access is not checked by default.
|
||||
*
|
||||
* @return BusyRange[]
|
||||
* @throws Forbidden
|
||||
*/
|
||||
public function fetchRanges(User $user, FetchParams $params): array
|
||||
{
|
||||
$fetchParams = CalendarFetchParams::create($params->from, $params->to);
|
||||
|
||||
return $this->service->fetchBusyRanges($user, $params, $fetchParams);
|
||||
}
|
||||
}
|
||||
39
application/Espo/Modules/Crm/Tools/Calendar/Item.php
Normal file
39
application/Espo/Modules/Crm/Tools/Calendar/Item.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Crm\Tools\Calendar;
|
||||
|
||||
use Espo\Core\Field\DateTime;
|
||||
|
||||
use stdClass;
|
||||
|
||||
interface Item
|
||||
{
|
||||
public function getRaw(): stdClass;
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Crm\Tools\Calendar\Items;
|
||||
|
||||
use Espo\Core\Field\DateTime;
|
||||
use Espo\Modules\Crm\Tools\Calendar\Item;
|
||||
|
||||
use stdClass;
|
||||
|
||||
class BusyRange implements Item
|
||||
{
|
||||
private DateTime $start;
|
||||
private DateTime $end;
|
||||
|
||||
public function __construct(DateTime $start, DateTime $end)
|
||||
{
|
||||
$this->start = $start;
|
||||
$this->end = $end;
|
||||
}
|
||||
|
||||
public function getStart(): DateTime
|
||||
{
|
||||
return $this->start;
|
||||
}
|
||||
|
||||
public function getEnd(): DateTime
|
||||
{
|
||||
return $this->end;
|
||||
}
|
||||
|
||||
public function getRaw(): stdClass
|
||||
{
|
||||
return (object) [
|
||||
'dateStart' => $this->start->toString(),
|
||||
'dateEnd' => $this->end->toString(),
|
||||
'isBusyRange' => true,
|
||||
];
|
||||
}
|
||||
}
|
||||
168
application/Espo/Modules/Crm/Tools/Calendar/Items/Event.php
Normal file
168
application/Espo/Modules/Crm/Tools/Calendar/Items/Event.php
Normal file
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Crm\Tools\Calendar\Items;
|
||||
|
||||
use Espo\Core\Field\DateTime;
|
||||
use Espo\Modules\Crm\Tools\Calendar\Item;
|
||||
|
||||
use RuntimeException;
|
||||
use stdClass;
|
||||
|
||||
class Event implements Item
|
||||
{
|
||||
private ?DateTime $start;
|
||||
private ?DateTime $end;
|
||||
private string $entityType;
|
||||
/** @var array<string, mixed> */
|
||||
private array $attributes;
|
||||
/** @var string[] */
|
||||
private array $userIdList = [];
|
||||
/** @var array<string, string> */
|
||||
private array $userNameMap = [];
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $attributes
|
||||
*/
|
||||
public function __construct(?DateTime $start, ?DateTime $end, string $entityType, array $attributes)
|
||||
{
|
||||
$this->start = $start;
|
||||
$this->end = $end;
|
||||
$this->entityType = $entityType;
|
||||
$this->attributes = $attributes;
|
||||
}
|
||||
|
||||
public function getRaw(): stdClass
|
||||
{
|
||||
$obj = (object) [
|
||||
'scope' => $this->entityType,
|
||||
'dateStart' => $this->start?->toString(),
|
||||
'dateEnd' => $this->end?->toString(),
|
||||
];
|
||||
|
||||
if ($this->userIdList !== []) {
|
||||
$obj->userIdList = $this->userIdList;
|
||||
$obj->userNameMap = (object) $this->userNameMap;
|
||||
}
|
||||
|
||||
foreach ($this->attributes as $key => $value) {
|
||||
$obj->$key = $obj->$key ?? $value;
|
||||
}
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function withAttribute(string $name, $value): self
|
||||
{
|
||||
$obj = clone $this;
|
||||
$obj->attributes[$name] = $value;
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public function withId(string $id): self
|
||||
{
|
||||
$obj = clone $this;
|
||||
$obj->attributes['id'] = $id;
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public function withUserIdAdded(string $userId): self
|
||||
{
|
||||
$obj = clone $this;
|
||||
$obj->userIdList[] = $userId;
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, string> $userNameMap
|
||||
*/
|
||||
public function withUserNameMap(array $userNameMap): self
|
||||
{
|
||||
$obj = clone $this;
|
||||
$obj->userNameMap = $userNameMap;
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public function getId(): string
|
||||
{
|
||||
$id = $this->attributes['id'] ?? null;
|
||||
|
||||
if (!$id) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
public function getStart(): ?DateTime
|
||||
{
|
||||
return $this->start;
|
||||
}
|
||||
|
||||
public function getEnd(): ?DateTime
|
||||
{
|
||||
return $this->end;
|
||||
}
|
||||
|
||||
public function getEntityType(): string
|
||||
{
|
||||
return $this->entityType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function getAttributes(): array
|
||||
{
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getUserIdList(): array
|
||||
{
|
||||
return $this->userIdList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAttribute(string $name)
|
||||
{
|
||||
return $this->attributes[$name] ?? null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Crm\Tools\Calendar\Items;
|
||||
|
||||
use Espo\Core\Field\DateTime;
|
||||
use Espo\Modules\Crm\Tools\Calendar\Item;
|
||||
use stdClass;
|
||||
|
||||
class NonWorkingRange implements Item
|
||||
{
|
||||
private DateTime $start;
|
||||
private DateTime $end;
|
||||
|
||||
public function __construct(DateTime $start, DateTime $end)
|
||||
{
|
||||
$this->start = $start;
|
||||
$this->end = $end;
|
||||
}
|
||||
|
||||
public function getStart(): DateTime
|
||||
{
|
||||
return $this->start;
|
||||
}
|
||||
|
||||
public function getEnd(): DateTime
|
||||
{
|
||||
return $this->end;
|
||||
}
|
||||
|
||||
public function getRaw(): stdClass
|
||||
{
|
||||
return (object) [
|
||||
'dateStart' => $this->start->toString(),
|
||||
'dateEnd' => $this->end->toString(),
|
||||
'isNonWorkingRange' => true,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Crm\Tools\Calendar\Items;
|
||||
|
||||
use Espo\Core\Field\DateTime;
|
||||
use Espo\Modules\Crm\Tools\Calendar\Item;
|
||||
|
||||
use stdClass;
|
||||
|
||||
class WorkingRange implements Item
|
||||
{
|
||||
private DateTime $start;
|
||||
private DateTime $end;
|
||||
|
||||
public function __construct(DateTime $start, DateTime $end)
|
||||
{
|
||||
$this->start = $start;
|
||||
$this->end = $end;
|
||||
}
|
||||
|
||||
public function getStart(): DateTime
|
||||
{
|
||||
return $this->start;
|
||||
}
|
||||
|
||||
public function getEnd(): DateTime
|
||||
{
|
||||
return $this->end;
|
||||
}
|
||||
|
||||
public function getRaw(): stdClass
|
||||
{
|
||||
return (object) [
|
||||
'dateStart' => $this->start->toString(),
|
||||
'dateEnd' => $this->end->toString(),
|
||||
'isWorkingRange' => true,
|
||||
];
|
||||
}
|
||||
}
|
||||
1115
application/Espo/Modules/Crm/Tools/Calendar/Service.php
Normal file
1115
application/Espo/Modules/Crm/Tools/Calendar/Service.php
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user