EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
Event unset Date field if not all day
Yuriiec3ccc2a0f82
diff --git a/application/Espo/Core/Repositories/Event.php b/application/Espo/Core/Repositories/Event.phpindex 64264f7f4f..ee8ba153ff 100644--- a/application/Espo/Core/Repositories/Event.php+++ b/application/Espo/Core/Repositories/Event.php@@ -30,6 +30,7 @@namespace Espo\Core\Repositories;use Espo\Core\ORM\Entity as CoreEntity;+use Espo\Modules\Crm\Entities\Meeting;use Espo\Modules\Crm\Entities\Reminder;use Espo\ORM\Entity;use Espo\Core\Di;@@ -58,29 +59,39 @@ class Event extends Database implementsprotected function beforeSave(Entity $entity, array $options = []){if (- $entity->isAttributeChanged('status') &&- in_array($entity->get('status'), $this->getNotActualStatuses())+ $entity->isAttributeChanged(Meeting::FIELD_STATUS) &&+ in_array($entity->get(Meeting::FIELD_STATUS), $this->getNotActualStatuses())) {$entity->set('reminders', []);}- if ($entity->has('dateStartDate')) {- $dateStartDate = $entity->get('dateStartDate');+ if (+ $entity->hasAttribute(Meeting::FIELD_IS_ALL_DAY) &&+ $entity->get(Meeting::FIELD_IS_ALL_DAY) === false+ ) {+ $entity->setMultiple([+ Meeting::FIELD_DATE_START_DATE => null,+ Meeting::FIELD_DATE_END_DATE => null,+ ]);+ }++ if ($entity->has(Meeting::FIELD_DATE_START_DATE)) {+ $dateStartDate = $entity->get(Meeting::FIELD_DATE_START_DATE);if (!empty($dateStartDate)) {$dateStart = $dateStartDate . ' 00:00:00';$dateStart = $this->convertDateTimeToDefaultTimezone($dateStart);- $entity->set('dateStart', $dateStart);+ $entity->set(Meeting::FIELD_DATE_START, $dateStart);} else {/** @noinspection PhpRedundantOptionalArgumentInspection */- $entity->set('dateStartDate', null);+ $entity->set(Meeting::FIELD_DATE_START_DATE, null);}}- if ($entity->has('dateEndDate')) {- $dateEndDate = $entity->get('dateEndDate');+ if ($entity->has(Meeting::FIELD_DATE_END_DATE)) {+ $dateEndDate = $entity->get(Meeting::FIELD_DATE_END_DATE);if (!empty($dateEndDate)) {try {@@ -94,10 +105,10 @@ class Event extends Database implements$dt->modify('+1 day');$dateEnd = $dt->format(DateTimeUtil::SYSTEM_DATE_TIME_FORMAT);- $entity->set('dateEnd', $dateEnd);+ $entity->set(Meeting::FIELD_DATE_END, $dateEnd);} else {/** @noinspection PhpRedundantOptionalArgumentInspection */- $entity->set('dateEndDate', null);+ $entity->set(Meeting::FIELD_DATE_END_DATE, null);}}diff --git a/application/Espo/Modules/Crm/Entities/Meeting.php b/application/Espo/Modules/Crm/Entities/Meeting.phpindex ffad394f0c..a9d03cd1f8 100644--- a/application/Espo/Modules/Crm/Entities/Meeting.php+++ b/application/Espo/Modules/Crm/Entities/Meeting.php@@ -51,6 +51,19 @@ class Meeting extends Entitypublic const STATUS_HELD = 'Held';public const STATUS_NOT_HELD = 'Not Held';+ /** @since 10.0.0 */+ public const string FIELD_IS_ALL_DAY = 'isAllDay';+ /** @since 10.0.0 */+ public const string FIELD_DATE_START_DATE = 'dateStartDate';+ /** @since 10.0.0 */+ public const string FIELD_DATE_END_DATE = 'dateEndDate';+ /** @since 10.0.0 */+ public const string FIELD_DATE_START = 'dateStart';+ /** @since 10.0.0 */+ public const string FIELD_DATE_END = 'dateEnd';+ /** @since 10.0.0 */+ public const string FIELD_STATUS = 'status';+public const LINK_USERS = 'users';public const LINK_CONTACTS = 'contacts';public const LINK_LEADS = 'leads';@@ -255,4 +268,12 @@ class Meeting extends Entity{return $this->get('externalService');}++ /**+ * @since 10.0.0+ */+ public function isAllDay(): bool+ {+ return (bool) $this->get(self::FIELD_IS_ALL_DAY);+ }}