Initial commit

This commit is contained in:
root
2026-01-19 17:44:46 +01:00
commit 823af8b11d
8721 changed files with 1130846 additions and 0 deletions

View File

@@ -0,0 +1,80 @@
<?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\Entities;
use Espo\Core\Field\LinkParent;
use Espo\Core\ORM\Entity;
use Espo\Core\Record\ActionHistory\Action;
class ActionHistoryRecord extends Entity
{
public const ENTITY_TYPE = 'ActionHistoryRecord';
public const ACTION_CREATE = Action::CREATE;
public const ACTION_READ = Action::READ;
public const ACTION_UPDATE = Action::UPDATE;
public const ACTION_DELETE = Action::DELETE;
/**
* @param Action::* $action
*/
public function setAction(string $action): self
{
return $this->set('action', $action);
}
public function setUserId(string $userId): self
{
return $this->set('userId', $userId);
}
public function setIpAddress(?string $ipAddress): self
{
return $this->set('ipAddress', $ipAddress);
}
public function setAuthTokenId(?string $authTokenId): self
{
return $this->set('authTokenId', $authTokenId);
}
public function setAuthLogRecordId(?string $authLogRecordId): self
{
return $this->set('authLogRecordId', $authLogRecordId);
}
public function setTarget(LinkParent $target): self
{
$this->set('targetId', $target->getId());
$this->set('targetType', $target->getEntityType());
return $this;
}
}

View File

@@ -0,0 +1,53 @@
<?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\Entities;
use Espo\Core\Name\Field;
use Espo\Core\ORM\Entity;
class AddressCountry extends Entity
{
public const ENTITY_TYPE = 'AddressCountry';
public function getName(): string
{
return $this->get(Field::NAME);
}
public function getCode(): string
{
return $this->get('code');
}
public function isPreferred(): bool
{
return (bool) $this->get('isPreferred');
}
}

View File

@@ -0,0 +1,112 @@
<?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\Entities;
use Espo\Core\ORM\Entity;
use Espo\ORM\Defs\Params\AttributeParam;
class AppLogRecord extends Entity
{
public const ENTITY_TYPE = 'AppLogRecord';
public function setMessage(string $message): self
{
$this->set('message', $message);
return $this;
}
public function setLevel(string $level): self
{
$this->set('level', $level);
return $this;
}
public function setCode(?int $code): self
{
$this->set('code', $code);
return $this;
}
public function setExceptionClass(?string $exceptionClass): self
{
$len = $this->getAttributeParam('exceptionClass', AttributeParam::LEN);
if ($exceptionClass && strlen($exceptionClass) > $len) {
$exceptionClass = substr($exceptionClass, $len);
}
$this->set('exceptionClass', $exceptionClass);
return $this;
}
public function setFile(?string $file): self
{
$len = $this->getAttributeParam('file', AttributeParam::LEN);
if ($file && strlen($file) > $len) {
$file = substr($file, $len);
}
$this->set('file', $file);
return $this;
}
public function setLine(?int $code): self
{
$this->set('line', $code);
return $this;
}
public function setRequestMethod(?string $requestMethod): self
{
$this->set('requestMethod', $requestMethod);
return $this;
}
public function setRequestResourcePath(?string $requestResourcePath): self
{
$len = $this->getAttributeParam('requestResourcePath', AttributeParam::LEN);
if ($requestResourcePath && strlen($requestResourcePath) > $len) {
$requestResourcePath = substr($requestResourcePath, $len);
}
$this->set('requestResourcePath', $requestResourcePath);
return $this;
}
}

View File

@@ -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\Entities;
use Espo\Core\Name\Field;
use Espo\Core\ORM\Entity;
class AppSecret extends Entity
{
public const ENTITY_TYPE = 'AppSecret';
public function getName(): string
{
return $this->get(Field::NAME);
}
public function getValue(): string
{
return (string) $this->get('value');
}
public function setName(string $name): self
{
$this->set(Field::NAME, $name);
return $this;
}
/**
* @internal Do not use.
* @todo Rename to setValue in v9.0.
*/
public function setSecretValue(string $value): self
{
$this->set('value', $value);
return $this;
}
}

View File

@@ -0,0 +1,35 @@
<?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\Entities;
class ArrayValue extends \Espo\Core\ORM\Entity
{
public const ENTITY_TYPE = 'ArrayValue';
}

View File

@@ -0,0 +1,218 @@
<?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\Entities;
use Espo\Core\Name\Field;
use Espo\Core\ORM\Entity;
use Espo\Core\Field\LinkParent;
class Attachment extends Entity
{
public const ENTITY_TYPE = 'Attachment';
public const ROLE_ATTACHMENT = 'Attachment';
public const ROLE_INLINE_ATTACHMENT = 'Inline Attachment';
public const ROLE_EXPORT_FILE = 'Export File';
/**
* Multiple attachment can refer to one file. Source ID is an original attachment.
*/
public function getSourceId(): ?string
{
$sourceId = $this->get('sourceId');
if (!$sourceId && $this->hasId()) {
$sourceId = $this->getId();
}
return $sourceId;
}
/**
* A storage.
*/
public function getStorage(): ?string
{
return $this->get('storage');
}
/**
* A file name.
*/
public function getName(): ?string
{
return $this->get(Field::NAME);
}
/**
* A size in bytes.
*/
public function getSize(): ?int
{
return $this->get('size');
}
/**
* A mime-type.
*/
public function getType(): ?string
{
return $this->get('type');
}
/**
* A field the attachment is related through.
*/
public function getTargetField(): ?string
{
return $this->get('field');
}
public function getParent(): ?LinkParent
{
/** @var ?LinkParent */
return $this->getValueObject(Field::PARENT);
}
public function getRelated(): ?LinkParent
{
/** @var ?LinkParent */
return $this->getValueObject('related');
}
public function getParentType(): ?string
{
return $this->get('parentType');
}
public function getRelatedType(): ?string
{
return $this->get('relatedType');
}
public function isBeingUploaded(): bool
{
return (bool) $this->get('isBeingUploaded');
}
/**
* A role.
*/
public function getRole(): ?string
{
return $this->get('role');
}
/**
* Multiple attachment can refer to one file. Source ID is an original attachment.
*/
public function setSourceId(?string $sourceId): self
{
$this->set('sourceId', $sourceId);
return $this;
}
public function setStorage(?string $storage): self
{
$this->set('storage', $storage);
return $this;
}
public function setName(?string $name): self
{
$this->set(Field::NAME, $name);
return $this;
}
public function setType(?string $type): self
{
$this->set('type', $type);
return $this;
}
public function setRole(?string $type): self
{
$this->set('role', $type);
return $this;
}
public function setSize(?int $size): self
{
$this->set('size', $size);
return $this;
}
public function setContents(?string $contents): self
{
$this->set('contents', $contents);
return $this;
}
public function setTargetField(?string $field): self
{
$this->set('field', $field);
return $this;
}
public function setParent(LinkParent|Entity|null $parent): self
{
if ($parent instanceof LinkParent) {
$this->setValueObject(Field::PARENT, $parent);
return $this;
}
$this->relations->set(Field::PARENT, $parent);
return $this;
}
public function setRelated(LinkParent|Entity|null $related): self
{
if ($related instanceof LinkParent) {
$this->setValueObject('related', $related);
return $this;
}
$this->relations->set('related', $related);
return $this;
}
}

View File

@@ -0,0 +1,123 @@
<?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\Entities;
use Espo\Core\ORM\Entity;
class AuthLogRecord extends Entity
{
public const ENTITY_TYPE = 'AuthLogRecord';
public const DENIAL_REASON_CREDENTIALS = 'CREDENTIALS';
public const DENIAL_REASON_WRONG_CODE = 'WRONG_CODE';
public const DENIAL_REASON_INACTIVE_USER = 'INACTIVE_USER';
public const DENIAL_REASON_IS_PORTAL_USER = 'IS_PORTAL_USER';
public const DENIAL_REASON_IS_NOT_PORTAL_USER = 'IS_NOT_PORTAL_USER';
public const DENIAL_REASON_USER_IS_NOT_IN_PORTAL = 'USER_IS_NOT_IN_PORTAL';
public const DENIAL_REASON_IS_SYSTEM_USER = 'IS_SYSTEM_USER';
public const DENIAL_REASON_FORBIDDEN = 'FORBIDDEN';
public function setUsername(?string $username): self
{
$this->set('username', $username);
return $this;
}
public function setIpAddress(?string $ipAddress): self
{
$this->set('ipAddress', $ipAddress);
return $this;
}
public function setRequestMethod(string $requestMethod): self
{
$this->set('requestMethod', $requestMethod);
return $this;
}
public function setRequestUrl(string $requestUrl): self
{
$this->set('requestUrl', $requestUrl);
return $this;
}
public function setAuthenticationMethod(?string $authenticationMethod): self
{
$this->set('authenticationMethod', $authenticationMethod);
return $this;
}
public function setRequestTime(?float $requestTime): self
{
$this->set('requestTime', $requestTime);
return $this;
}
public function setUserId(?string $userId): self
{
$this->set('userId', $userId);
return $this;
}
public function setPortalId(?string $portalId): self
{
$this->set('portalId', $portalId);
return $this;
}
public function setAuthTokenId(?string $authTokenId): self
{
$this->set('authTokenId', $authTokenId);
return $this;
}
public function setIsDenied(bool $isDenied = true): self
{
$this->set('isDenied', $isDenied);
return $this;
}
public function setDenialReason(?string $denialReason): self
{
$this->set('denialReason', $denialReason);
return $this;
}
}

View File

@@ -0,0 +1,125 @@
<?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\Entities;
use Espo\Core\Authentication\AuthToken\AuthToken as AuthTokenInterface;
use Espo\Core\Field\DateTime;
use Espo\Core\ORM\Entity as BaseEntity;
class AuthToken extends BaseEntity implements AuthTokenInterface
{
public const ENTITY_TYPE = 'AuthToken';
public function getToken(): string
{
return $this->get('token');
}
public function getUserId(): string
{
return $this->get('userId');
}
public function getPortalId(): ?string
{
return $this->get('portalId');
}
public function getSecret(): ?string
{
return $this->get('secret');
}
public function isActive(): bool
{
return $this->get('isActive');
}
public function getHash(): ?string
{
return $this->get('hash');
}
public function setIsActive(bool $isActive): self
{
$this->set('isActive', $isActive);
return $this;
}
public function setUserId(string $userId): self
{
$this->set('userId', $userId);
return $this;
}
public function setPortalId(?string $portalId): self
{
$this->set('portalId', $portalId);
return $this;
}
public function setHash(?string $hash): self
{
$this->set('hash', $hash);
return $this;
}
public function setToken(string $token): self
{
$this->set('token', $token);
return $this;
}
public function setSecret(string $secret): self
{
$this->set('secret', $secret);
return $this;
}
public function setIpAddress(?string $ipAddress): self
{
$this->set('ipAddress', $ipAddress);
return $this;
}
public function setLastAccessNow(): self
{
$this->set('lastAccess', DateTime::createNow()->toString());
return $this;
}
}

View File

@@ -0,0 +1,42 @@
<?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\Entities;
use Espo\Core\ORM\Entity;
class AuthenticationProvider extends Entity
{
public const ENTITY_TYPE = 'AuthenticationProvider';
public function getMethod(): ?string
{
return $this->get('method');
}
}

View File

@@ -0,0 +1,35 @@
<?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\Entities;
class Autofollow extends \Espo\Core\ORM\Entity
{
public const ENTITY_TYPE = 'Autofollow';
}

View File

@@ -0,0 +1,35 @@
<?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\Entities;
class Currency extends \Espo\Core\ORM\Entity
{
public const ENTITY_TYPE = 'Currency';
}

View File

@@ -0,0 +1,35 @@
<?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\Entities;
class DashboardTemplate extends \Espo\Core\ORM\Entity
{
public const ENTITY_TYPE = 'DashboardTemplate';
}

View File

@@ -0,0 +1,924 @@
<?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\Entities;
use Espo\Core\Field\LinkMultiple;
use Espo\Core\Name\Field;
use Espo\Core\Utils\Util;
use Espo\Core\ORM\Entity;
use Espo\Core\Field\DateTime;
use Espo\Core\Field\LinkParent;
use Espo\Core\Field\Link;
use Espo\Modules\Crm\Entities\Account;
use Espo\ORM\Entity as OrmEntity;
use Espo\ORM\EntityCollection;
use Espo\Repositories\Email as EmailRepository;
use Espo\Tools\Email\Util as EmailUtil;
use RuntimeException;
use stdClass;
class Email extends Entity
{
public const ENTITY_TYPE = 'Email';
public const STATUS_BEING_IMPORTED = 'Being Imported';
public const STATUS_ARCHIVED = 'Archived';
public const STATUS_SENT = 'Sent';
public const STATUS_SENDING = 'Sending';
public const STATUS_DRAFT = 'Draft';
public const RELATIONSHIP_EMAIL_USER = 'EmailUser';
public const ALIAS_INBOX = 'emailUserInbox';
public const USERS_COLUMN_IS_READ = 'isRead';
public const USERS_COLUMN_IN_TRASH = 'inTrash';
public const USERS_COLUMN_IN_ARCHIVE = 'inArchive';
public const USERS_COLUMN_FOLDER_ID = 'folderId';
public const USERS_COLUMN_IS_IMPORTANT = 'isImportant';
public const GROUP_STATUS_FOLDER_ARCHIVE = 'Archive';
public const GROUP_STATUS_FOLDER_TRASH = 'Trash';
public const SAVE_OPTION_IS_BEING_IMPORTED = 'isBeingImported';
public const SAVE_OPTION_IS_JUST_SENT = 'isJustSent';
private const ATTR_BODY_PLAIN = 'bodyPlain';
public const LINK_REPLIES = 'replies';
public const ADDRESS_FROM = 'from';
public const ADDRESS_TO = 'to';
public const ADDRESS_CC = 'cc';
public const ADDRESS_BCC = 'bcc';
public const ADDRESS_REPLY_TO = 'replyTo';
public function get(string $attribute): mixed
{
if ($attribute === 'subject') {
return $this->get(Field::NAME);
}
if ($attribute === 'fromName') {
return EmailUtil::parseFromName($this->get('fromString') ?? '') ?: null;
}
if ($attribute === 'fromAddress') {
return EmailUtil::parseFromAddress($this->get('fromString') ?? '') ?: null;
}
if ($attribute === 'replyToName') {
return $this->getReplyToNameInternal();
}
if ($attribute === 'replyToAddress') {
return $this->getReplyToAddressInternal();
}
if ($attribute === self::ATTR_BODY_PLAIN) {
return $this->getBodyPlain();
}
return parent::get($attribute);
}
public function has(string $attribute): bool
{
if ($attribute === 'subject') {
return $this->has(Field::NAME);
}
if ($attribute === 'fromName' || $attribute === 'fromAddress') {
return $this->has('fromString');
}
if ($attribute === 'replyToName' || $attribute === 'replyToAddress') {
return $this->has('replyToString');
}
return parent::has($attribute);
}
public function getFetched(string $attribute): mixed
{
if ($attribute === 'subject') {
return $this->getFetched(Field::NAME);
}
return parent::getFetched($attribute);
}
public function isAttributeChanged(string $name): bool
{
if ($name === 'subject') {
$name = Field::NAME;
}
return parent::isAttributeChanged($name);
}
/** @noinspection PhpUnused */
protected function _setSubject(?string $value): void
{
$this->set(Field::NAME, $value);
}
private function getReplyToNameInternal(): ?string
{
if (!$this->has('replyToString')) {
return null;
}
$string = $this->get('replyToString');
if (!$string) {
return null;
}
$string = trim(explode(';', $string)[0]);
return EmailUtil::parseFromName($string);
}
private function getReplyToAddressInternal(): ?string
{
if (!$this->has('replyToString')) {
return null;
}
$string = $this->get('replyToString');
if (!$string) {
return null;
}
$string = trim(explode(';', $string)[0]);
return EmailUtil::parseFromAddress($string);
}
/** @noinspection PhpUnused */
protected function _setIsRead(?bool $value): void
{
$this->setInContainer('isRead', $value !== false);
if ($value === true || $value === false) {
$this->setInContainer('isUsers', true);
return;
}
$this->setInContainer('isUsers', false);
}
/**
* @deprecated As of v7.4. As the system user ID may be not constant in the future.
* @todo Remove in v10.0.
*/
public function isManuallyArchived(): bool
{
if ($this->getStatus() !== Email::STATUS_ARCHIVED) {
return false;
}
return true;
}
/**
* @todo Revise.
* @deprecated
*/
public function addAttachment(Attachment $attachment): void
{
if (!$this->id) {
return;
}
$attachment->set('parentId', $this->id);
$attachment->set('parentType', Email::ENTITY_TYPE);
if (!$this->entityManager) {
throw new RuntimeException();
}
$this->entityManager->saveEntity($attachment);
}
public function hasBodyPlain(): bool
{
return $this->hasInContainer(self::ATTR_BODY_PLAIN) && $this->getFromContainer(self::ATTR_BODY_PLAIN);
}
/**
* @since 9.0.0
*/
public function getBodyPlainWithoutReplyPart(): ?string
{
$body = $this->getBodyPlain();
if (!$body) {
return null;
}
return EmailUtil::stripPlainTextQuotePart($body) ?: null;
}
public function getBodyPlain(): ?string
{
if ($this->getFromContainer(self::ATTR_BODY_PLAIN)) {
return $this->getFromContainer(self::ATTR_BODY_PLAIN);
}
if (!$this->isHtml()) {
return $this->getBody();
}
$body = $this->getBody() ?: '';
return EmailUtil::stripHtml($body) ?: null;
}
public function getBodyPlainForSending(): string
{
return $this->getBodyPlain() ?? '';
}
public function getBodyForSending(): string
{
$body = $this->getBody() ?: '';
if ($body && $this->isHtml()) {
$attachmentList = $this->getInlineAttachmentList();
foreach ($attachmentList as $attachment) {
$id = $attachment->getId();
$partId = $id . '@espo';
$body = str_replace(
"\"?entryPoint=attachment&amp;id=$id\"",
"\"cid:$partId\"",
$body
);
}
}
return $body;
}
/**
* @return Attachment[]
*/
public function getInlineAttachmentList(): array
{
$idList = [];
$body = $this->getBody();
if (!$body) {
return [];
}
$matches = [];
if (!preg_match_all("/\?entryPoint=attachment&amp;id=([^&=\"']+)/", $body, $matches)) {
return [];
}
if (empty($matches[1]) || !is_array($matches[1])) {
return [];
}
$attachmentList = [];
foreach ($matches[1] as $id) {
if (in_array($id, $idList)) {
continue;
}
$idList[] = $id;
if (!$this->entityManager) {
throw new RuntimeException();
}
$attachment = $this->entityManager->getRDBRepositoryByClass(Attachment::class)->getById($id);
if ($attachment) {
$attachmentList[] = $attachment;
}
}
return $attachmentList;
}
public function getDateSent(): ?DateTime
{
/** @var ?DateTime */
return $this->getValueObject('dateSent');
}
public function getDeliveryDate(): ?DateTime
{
/** @var ?DateTime */
return $this->getValueObject('deliveryDate');
}
public function getSubject(): ?string
{
return $this->get('subject');
}
/**
* @param Email::STATUS_* $status
* @noinspection PhpDocSignatureInspection
*/
public function setStatus(string $status): self
{
$this->set('status', $status);
return $this;
}
public function setSubject(?string $subject): self
{
$this->set('subject', $subject);
return $this;
}
/**
* @param string[] $idList
*/
public function setAttachmentIdList(array $idList): self
{
$this->setLinkMultipleIdList('attachments', $idList);
return $this;
}
public function getBody(): ?string
{
return $this->get('body');
}
public function setBody(?string $body): self
{
$this->set('body', $body);
return $this;
}
public function setBodyPlain(?string $bodyPlain): self
{
$this->set(self::ATTR_BODY_PLAIN, $bodyPlain);
return $this;
}
public function isHtml(): ?bool
{
return $this->get('isHtml');
}
public function isRead(): ?bool
{
return $this->get('isRead');
}
public function setIsHtml(bool $isHtml = true): self
{
$this->set('isHtml', $isHtml);
return $this;
}
public function setIsPlain(bool $isPlain = true): self
{
$this->set('isHtml', !$isPlain);
return $this;
}
public function setFromAddress(?string $address): self
{
$this->set('from', $address);
return $this;
}
/**
* @param string[] $addressList
*/
public function setToAddressList(array $addressList): self
{
$this->set('to', implode(';', $addressList));
return $this;
}
/**
* @param string[] $addressList
*/
public function setCcAddressList(array $addressList): self
{
$this->set('cc', implode(';', $addressList));
return $this;
}
/**
* @param string[] $addressList
* @noinspection PhpUnused
*/
public function setBccAddressList(array $addressList): self
{
$this->set('bcc', implode(';', $addressList));
return $this;
}
/**
* @param string[] $addressList
*/
public function setReplyToAddressList(array $addressList): self
{
$this->set('replyTo', implode(';', $addressList));
return $this;
}
public function addToAddress(string $address): self
{
$list = $this->getToAddressList();
$list[] = $address;
$this->set('to', implode(';', $list));
return $this;
}
public function addCcAddress(string $address): self
{
$list = $this->getCcAddressList();
$list[] = $address;
$this->set('cc', implode(';', $list));
return $this;
}
public function addBccAddress(string $address): self
{
$list = $this->getBccAddressList();
$list[] = $address;
$this->set('bcc', implode(';', $list));
return $this;
}
public function addReplyToAddress(string $address): self
{
$list = $this->getReplyToAddressList();
$list[] = $address;
$this->set('replyTo', implode(';', $list));
return $this;
}
public function getFromString(): ?string
{
return $this->get('fromString');
}
public function getFromAddress(): ?string
{
if (!$this->hasInContainer('from') && !$this->isNew()) {
$this->getEmailRepository()->loadFromField($this);
}
return $this->get('from');
}
/**
* @return string[]
*/
public function getToAddressList(): array
{
if (!$this->hasInContainer('to') && !$this->isNew()) {
$this->getEmailRepository()->loadToField($this);
}
$value = $this->get('to');
if (!$value) {
return [];
}
return explode(';', $value);
}
/**
* @return string[]
*/
public function getCcAddressList(): array
{
if (!$this->hasInContainer('cc') && !$this->isNew()) {
$this->getEmailRepository()->loadCcField($this);
}
$value = $this->get('cc');
if (!$value) {
return [];
}
return explode(';', $value);
}
/**
* @return string[]
*/
public function getBccAddressList(): array
{
if (!$this->hasInContainer('bcc') && !$this->isNew()) {
$this->getEmailRepository()->loadBccField($this);
}
$value = $this->get('bcc');
if (!$value) {
return [];
}
return explode(';', $value);
}
/**
* @return string[]
*/
public function getReplyToAddressList(): array
{
if (!$this->hasInContainer('replyTo') && !$this->isNew()) {
$this->getEmailRepository()->loadReplyToField($this);
}
$value = $this->get('replyTo');
if (!$value) {
return [];
}
return explode(';', $value);
}
public function setDummyMessageId(): self
{
$this->set('messageId', 'dummy:' . Util::generateId());
return $this;
}
public function getMessageId(): ?string
{
return $this->get('messageId');
}
public function getParentType(): ?string
{
return $this->get('parentType');
}
public function getParentId(): ?string
{
return $this->get('parentId');
}
public function getParent(): ?OrmEntity
{
/** @var ?OrmEntity */
return $this->relations->getOne(Field::PARENT);
}
public function setAccount(Link|Account|null $account): self
{
return $this->setRelatedLinkOrEntity('account', $account);
}
public function setParent(LinkParent|OrmEntity|null $parent): self
{
return $this->setRelatedLinkOrEntity(Field::PARENT, $parent);
}
public function getStatus(): ?string
{
return $this->get('status');
}
public function getAccount(): ?Account
{
/** @var ?Account */
return $this->relations->getOne('account');
}
public function getTeams(): LinkMultiple
{
/** @var LinkMultiple */
return $this->getValueObject(Field::TEAMS);
}
public function getUsers(): LinkMultiple
{
/** @var LinkMultiple */
return $this->getValueObject('users');
}
public function getAssignedUsers(): LinkMultiple
{
/** @var LinkMultiple */
return $this->getValueObject(Field::ASSIGNED_USERS);
}
public function getAssignedUser(): ?Link
{
/** @var ?Link */
return $this->getValueObject(Field::ASSIGNED_USER);
}
public function getCreatedBy(): ?Link
{
/** @var ?Link */
return $this->getValueObject(Field::CREATED_BY);
}
public function getSentBy(): ?Link
{
/** @var ?Link */
return $this->getValueObject('sentBy');
}
public function setSentBy(Link|User|null $sentBy): self
{
return $this->setRelatedLinkOrEntity('sentBy', $sentBy);
}
public function getGroupFolder(): ?Link
{
/** @var ?Link */
return $this->getValueObject('groupFolder');
}
public function getReplied(): ?Email
{
/** @var ?Email */
return $this->relations->getOne('replied');
}
/**
* @return string[]
*/
public function getAttachmentIdList(): array
{
/** @var string[] */
return $this->getLinkMultipleIdList('attachments');
}
private function getEmailRepository(): EmailRepository
{
if (!$this->entityManager) {
throw new RuntimeException();
}
/** @var EmailRepository */
return $this->entityManager->getRepository(Email::ENTITY_TYPE);
}
public function setReplied(?Email $replied): self
{
return $this->setRelatedLinkOrEntity('replied', $replied);
}
/**
* @deprecated As of v9.0.0.
* @todo Remove in v9.2.0.
*/
public function setRepliedId(?string $repliedId): self
{
$this->set('repliedId', $repliedId);
return $this;
}
public function setMessageId(?string $messageId): self
{
$this->set('messageId', $messageId);
return $this;
}
public function setGroupFolder(Link|GroupEmailFolder|null $groupFolder): self
{
return $this->setRelatedLinkOrEntity('groupFolder', $groupFolder);
}
public function setGroupFolderId(?string $groupFolderId): self
{
$groupFolder = $groupFolderId ? Link::create($groupFolderId) : null;
return $this->setGroupFolder($groupFolder);
}
public function getGroupStatusFolder(): ?string
{
return $this->get('groupStatusFolder');
}
public function setGroupStatusFolder(?string $groupStatusFolder): self
{
$this->set('groupStatusFolder', $groupStatusFolder);
return $this;
}
public function setDateSent(?DateTime $dateSent): self
{
$this->setValueObject('dateSent', $dateSent);
return $this;
}
public function setDeliveryDate(?DateTime $deliveryDate): self
{
$this->setValueObject('deliveryDate', $deliveryDate);
return $this;
}
public function setAssignedUserId(?string $assignedUserId): self
{
$this->set('assignedUserId', $assignedUserId);
return $this;
}
public function addAssignedUserId(string $assignedUserId): self
{
$this->addLinkMultipleId(Field::ASSIGNED_USERS, $assignedUserId);
return $this;
}
public function addUserId(string $userId): self
{
$this->addLinkMultipleId('users', $userId);
return $this;
}
public function getUserColumnIsRead(string $userId): ?bool
{
return $this->getLinkMultipleColumn('users', self::USERS_COLUMN_IS_READ, $userId);
}
public function getUserColumnInTrash(string $userId): ?bool
{
return $this->getLinkMultipleColumn('users', self::USERS_COLUMN_IN_TRASH, $userId);
}
public function getUserColumnFolderId(string $userId): ?string
{
return $this->getLinkMultipleColumn('users', self::USERS_COLUMN_FOLDER_ID, $userId);
}
public function setUserColumnFolderId(string $userId, ?string $folderId): self
{
$this->setLinkMultipleColumn('users', self::USERS_COLUMN_FOLDER_ID, $userId, $folderId);
return $this;
}
public function setUserColumnIsRead(string $userId, bool $isRead): self
{
$this->setLinkMultipleColumn('users', self::USERS_COLUMN_IS_READ, $userId, $isRead);
return $this;
}
public function setUserColumnInTrash(string $userId, bool $inTrash): self
{
$this->setLinkMultipleColumn('users', self::USERS_COLUMN_IN_TRASH, $userId, $inTrash);
return $this;
}
public function getUserSkipNotification(string $userId): bool
{
/** @var stdClass $map */
$map = $this->get('skipNotificationMap') ?? (object) [];
return $map->$userId ?? false;
}
public function setUserSkipNotification(string $userId): self
{
/** @var stdClass $map */
$map = $this->get('skipNotificationMap') ?? (object) [];
$map->$userId = true;
$this->set('skipNotificationMap', $map);
return $this;
}
public function addTeamId(string $teamId): self
{
$this->addLinkMultipleId(Field::TEAMS, $teamId);
return $this;
}
public function setTeams(LinkMultiple $teams): self
{
$this->setValueObject(Field::TEAMS, $teams);
return $this;
}
/**
* @return EntityCollection<Attachment>
*/
public function getAttachments(): iterable
{
/** @var EntityCollection<Attachment> */
return $this->relations->getMany('attachments');
}
public function getSendAt(): ?DateTime
{
/** @var ?DateTime */
return $this->getValueObject('sendAt');
}
public function setSendAt(?DateTime $sendAt): self
{
$this->setValueObject('sendAt', $sendAt);
return $this;
}
public function getIcsContents(): ?string
{
return $this->get('icsContents');
}
public function isReplied(): bool
{
return (bool) $this->get('isReplied');
}
public function setIsReplied(bool $isReplied = true): self
{
return $this->set('isReplied', $isReplied);
}
public function isAutoReply(): bool
{
return $this->get('isAutoReply');
}
public function setIsAutoReply(bool $isAutoReply = true): self
{
return $this->set('isAutoReply', $isAutoReply);
}
}

View File

@@ -0,0 +1,210 @@
<?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\Entities;
use Espo\Core\Name\Field;
use Espo\Core\ORM\Entity;
use Espo\Core\Field\Date;
use Espo\Core\Field\Link;
use Espo\Core\Field\LinkMultiple;
use stdClass;
class EmailAccount extends Entity
{
public const ENTITY_TYPE = 'EmailAccount';
public const STATUS_ACTIVE = 'Active';
public function isAvailableForFetching(): bool
{
return $this->isActive() && $this->get('useImap');
}
public function isAvailableForSending(): bool
{
return $this->isActive() && $this->get('useSmtp');
}
public function isActive(): bool
{
return $this->get('status') === self::STATUS_ACTIVE;
}
public function getEmailAddress(): ?string
{
return $this->get('emailAddress');
}
public function getAssignedUser(): ?Link
{
/** @var ?Link */
return $this->getValueObject(Field::ASSIGNED_USER);
}
public function getTeams(): LinkMultiple
{
/** @var LinkMultiple */
return LinkMultiple::create();
}
public function keepFetchedEmailsUnread(): bool
{
return (bool) $this->get('keepFetchedEmailsUnread');
}
public function storeSentEmails(): bool
{
return (bool) $this->get('storeSentEmails');
}
public function getFetchData(): stdClass
{
$data = $this->get('fetchData') ?? (object) [];
if (!property_exists($data, 'lastUID')) {
$data->lastUID = (object) [];
}
if (!property_exists($data, 'lastDate')) {
$data->lastDate = (object) [];
}
if (!property_exists($data, 'byDate')) {
$data->byDate = (object) [];
}
return $data;
}
public function getFetchSince(): ?Date
{
/** @var ?Date */
return $this->getValueObject('fetchSince');
}
public function getEmailFolder(): ?Link
{
/** @var ?Link */
return $this->getValueObject('emailFolder');
}
/**
* @return string[]
*/
public function getMonitoredFolderList(): array
{
return $this->get('monitoredFolders') ?? [];
}
public function getHost(): ?string
{
return $this->get('host');
}
public function getPort(): ?int
{
return $this->get('port');
}
public function getUsername(): ?string
{
return $this->get('username');
}
public function getPassword(): ?string
{
return $this->get('password');
}
public function getSecurity(): ?string
{
return $this->get('security');
}
/**
* @return ?class-string<object>
*/
public function getImapHandlerClassName(): ?string
{
/** @var ?class-string<object> */
return $this->get('imapHandler');
}
public function getSentFolder(): ?string
{
return $this->get('sentFolder');
}
public function getSmtpHost(): ?string
{
return $this->get('smtpHost');
}
public function getSmtpPort(): ?int
{
return $this->get('smtpPort');
}
public function getSmtpAuth(): bool
{
return $this->get('smtpAuth');
}
public function getSmtpSecurity(): ?string
{
return $this->get('smtpSecurity');
}
public function getSmtpUsername(): ?string
{
return $this->get('smtpUsername');
}
public function getSmtpPassword(): ?string
{
return $this->get('smtpPassword');
}
public function getSmtpAuthMechanism(): ?string
{
return $this->get('smtpAuthMechanism');
}
/**
* @return ?class-string<object>
*/
public function getSmtpHandlerClassName(): ?string
{
/** @var ?class-string<object> */
return $this->get('smtpHandler');
}
}

View File

@@ -0,0 +1,98 @@
<?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\Entities;
use Espo\Core\Name\Field;
use Espo\Core\ORM\Entity;
use InvalidArgumentException;
class EmailAddress extends Entity
{
public const ENTITY_TYPE = 'EmailAddress';
public const RELATION_ENTITY_EMAIL_ADDRESS = 'EntityEmailAddress';
/**
* @param string $value
* @return void
*/
protected function _setName($value)
{
if (empty($value)) {
throw new InvalidArgumentException("Not valid email address '{$value}'");
}
$this->setInContainer(Field::NAME, $value);
$this->set('lower', strtolower($value));
}
public function getAddress(): string
{
return $this->get(Field::NAME);
}
public function getLower(): string
{
return $this->get('lower');
}
public function isOptedOut(): bool
{
return $this->get('optOut');
}
public function isInvalid(): bool
{
return $this->get('invalid');
}
public function setOptedOut(bool $optedOut): self
{
$this->set('optOut', $optedOut);
return $this;
}
public function setInvalid(bool $invalid): self
{
$this->set('invalid', $invalid);
return $this;
}
public function setAddress(string $address): self
{
$this->set(Field::NAME, $address);
return $this;
}
}

View File

@@ -0,0 +1,118 @@
<?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\Entities;
use Espo\Core\ORM\Entity;
class EmailFilter extends Entity
{
public const ENTITY_TYPE = 'EmailFilter';
public const ACTION_SKIP = 'Skip';
public const ACTION_MOVE_TO_FOLDER = 'Move to Folder';
public const ACTION_MOVE_TO_GROUP_FOLDER = 'Move to Group Folder';
public const ACTION_NONE = 'None';
public const STATUS_ACTIVE = 'Active';
/**
* @return self::ACTION_*|null
*/
public function getAction(): ?string
{
return $this->get('action');
}
public function getEmailFolderId(): ?string
{
return $this->get('emailFolderId');
}
public function getGroupEmailFolderId(): ?string
{
return $this->get('groupEmailFolderId');
}
public function markAsRead(): bool
{
return (bool) $this->get('markAsRead');
}
public function skipNotification(): bool
{
return (bool) $this->get('skipNotification');
}
public function isGlobal(): bool
{
return (bool) $this->get('isGlobal');
}
public function getParentType(): ?string
{
return $this->get('parentType');
}
public function getParentId(): ?string
{
return $this->get('parentId');
}
public function getFrom(): ?string
{
return $this->get('from');
}
public function getTo(): ?string
{
return $this->get('to');
}
public function getSubject(): ?string
{
return $this->get('subject');
}
/**
* @return string[]
*/
public function getBodyContains(): array
{
return $this->get('bodyContains') ?? [];
}
/**
* @return string[]
*/
public function getBodyContainsAll(): array
{
return $this->get('bodyContainsAll') ?? [];
}
}

View File

@@ -0,0 +1,44 @@
<?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\Entities;
use Espo\Core\Name\Field;
use Espo\Core\ORM\Entity;
class EmailFolder extends Entity
{
public const ENTITY_TYPE = 'EmailFolder';
public function getName(): string
{
return $this->get(Field::NAME) ?? '';
}
}

View File

@@ -0,0 +1,73 @@
<?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\Entities;
use Espo\Core\ORM\Entity;
use Espo\ORM\EntityCollection;
class EmailTemplate extends Entity
{
public const ENTITY_TYPE = 'EmailTemplate';
public const STATUS_ACTIVE = 'Active';
public function getSubject(): ?string
{
return $this->get('subject');
}
public function getBody(): ?string
{
return $this->get('body');
}
public function isHtml(): bool
{
return (bool) $this->get('isHtml');
}
/**
* @return string[]
*/
public function getAttachmentIdList(): array
{
/** @var string[] */
return $this->getLinkMultipleIdList('attachments');
}
/**
* @return EntityCollection<Attachment>
*/
public function getAttachments(): EntityCollection
{
/** @var EntityCollection<Attachment> */
return $this->relations->getMany('attachments');
}
}

View File

@@ -0,0 +1,35 @@
<?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\Entities;
class EmailTemplateCategory extends \Espo\Core\Templates\Entities\CategoryTree
{
public const ENTITY_TYPE = 'EmailTemplateCategory';
}

View File

@@ -0,0 +1,131 @@
<?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\Entities;
use Espo\Core\Name\Field;
use Espo\Core\ORM\Entity;
use Espo\Core\Field\DateTime;
use Espo\Core\Field\Link;
use Espo\Tools\Export\Params;
use RuntimeException;
class Export extends Entity
{
public const ENTITY_TYPE = 'Export';
public const STATUS_PENDING = 'Pending';
public const STATUS_RUNNING = 'Running';
public const STATUS_SUCCESS = 'Success';
public const STATUS_FAILED = 'Failed';
public function getParams(): Params
{
$raw = $this->get('params');
if (!is_string($raw)) {
throw new RuntimeException("No 'params'.");
}
/** @var Params $params */
$params = unserialize(base64_decode($raw));
return $params;
}
public function getStatus(): string
{
$value = $this->get('status');
if (!is_string($value)) {
throw new RuntimeException("No 'status'.");
}
return $value;
}
public function getAttachmentId(): ?string
{
/** @var ?string */
return $this->get('attachmentId');
}
public function notifyOnFinish(): bool
{
return (bool) $this->get('notifyOnFinish');
}
public function getCreatedAt(): DateTime
{
$value = $this->getValueObject(Field::CREATED_AT);
if (!$value instanceof DateTime) {
throw new RuntimeException("No 'createdAt'.");
}
return $value;
}
public function getCreatedBy(): Link
{
$value = $this->getValueObject(Field::CREATED_BY);
if (!$value instanceof Link) {
throw new RuntimeException("No 'createdBy'.");
}
return $value;
}
public function setStatus(string $status): self
{
$this->set('status', $status);
return $this;
}
public function setAttachmentId(string $attachmentId): self
{
$this->set('attachmentId', $attachmentId);
return $this;
}
public function setNotifyOnFinish(bool $notifyOnFinish = true): self
{
$this->set('notifyOnFinish', $notifyOnFinish);
return $this;
}
}

View File

@@ -0,0 +1,68 @@
<?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\Entities;
use Espo\Core\Name\Field;
use Espo\Core\ORM\Entity;
class Extension extends Entity
{
public const ENTITY_TYPE = 'Extension';
public const LICENSE_STATUS_VALID = 'Valid';
public const LICENSE_STATUS_INVALID = 'Invalid';
public const LICENSE_STATUS_EXPIRED = 'Expired';
public const LICENSE_STATUS_SOFT_EXPIRED = 'Soft-Expired';
public function getName(): string
{
return (string) $this->get(Field::NAME);
}
public function getVersion(): string
{
return (string) $this->get('version');
}
public function getLicenseStatusMessage(): ?string
{
return $this->get('licenseStatusMessage');
}
public function getLicenseStatus(): ?string
{
return $this->get('licenseStatus');
}
public function isInstalled(): bool
{
return (bool) $this->get('isInstalled');
}
}

View File

@@ -0,0 +1,140 @@
<?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\Entities;
use Espo\Core\Field\DateTime;
use RuntimeException;
class ExternalAccount extends Integration
{
public const ENTITY_TYPE = 'ExternalAccount';
public function isEnabled(): bool
{
return (bool) $this->get('enabled');
}
public function setIsEnabled(bool $isEnabled): self
{
$this->set('enabled', $isEnabled);
return $this;
}
public function unsetData(): self
{
$this->set(['data' => null]);
return $this;
}
public function setIsLocked(bool $isLocked): self
{
$this->set('isLocked', $isLocked);
return $this;
}
public function isLocked(): bool
{
return (bool) $this->get('isLocked');
}
public function getRefreshTokenAttempts(): int
{
return (int) ($this->get('refreshTokenAttempts') ?? 0);
}
public function getAccessToken(): ?string
{
return $this->get('accessToken');
}
public function getRefreshToken(): ?string
{
return $this->get('refreshToken');
}
public function getTokenType(): ?string
{
return $this->get('tokenType');
}
public function getExpiresAt(): ?DateTime
{
$raw = $this->get('expiresAt');
if (!$raw) {
return null;
}
try {
return DateTime::fromString($raw);
} catch (RuntimeException) {
return null;
}
}
public function setAccessToken(?string $accessToken): self
{
$this->set('accessToken', $accessToken);
return $this;
}
public function setTokenType(?string $tokenType): self
{
$this->set('tokenType', $tokenType);
return $this;
}
public function setRefreshToken(?string $refreshToken): self
{
$this->set('refreshToken', $refreshToken);
return $this;
}
public function setExpiresAt(?string $expiresAt): self
{
$this->set('expiresAt', $expiresAt);
return $this;
}
public function setRefreshTokenAttempts(?int $refreshTokenAttempts): self
{
$this->set('refreshTokenAttempts', $refreshTokenAttempts);
return $this;
}
}

View File

@@ -0,0 +1,49 @@
<?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\Entities;
use Espo\Core\Field\LinkMultiple;
use Espo\Core\ORM\Entity;
class GroupEmailFolder extends Entity
{
public const ENTITY_TYPE = 'GroupEmailFolder';
public function getOrder(): ?int
{
return $this->get('order');
}
public function getTeams(): LinkMultiple
{
/** @var LinkMultiple */
return $this->getValueObject('teams');
}
}

View File

@@ -0,0 +1,73 @@
<?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\Entities;
use Espo\Core\ORM\Entity;
use Espo\Tools\Import\Params;
class Import extends Entity
{
public const ENTITY_TYPE = 'Import';
public const STATUS_STANDBY = 'Standby';
public const STATUS_IN_PROCESS = 'In Process';
public const STATUS_FAILED = 'Failed';
public const STATUS_PENDING = 'Pending';
public const STATUS_COMPLETE = 'Complete';
public function getStatus(): ?string
{
return $this->get('status');
}
public function getParams(): Params
{
$raw = $this->get('params');
return Params::fromRaw($raw);
}
public function getFileId(): ?string
{
return $this->get('fileId');
}
public function getTargetEntityType(): ?string
{
return $this->get('entityType');
}
/**
* @return ?string[]
*/
public function getTargetAttributeList(): ?array
{
return $this->get('attributeList');
}
}

View File

@@ -0,0 +1,37 @@
<?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\Entities;
use Espo\Core\ORM\Entity;
class ImportEntity extends Entity
{
public const ENTITY_TYPE = 'ImportEntity';
}

View File

@@ -0,0 +1,100 @@
<?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\Entities;
use Espo\Core\Field\Link;
use Espo\Core\ORM\Entity;
use LogicException;
class ImportError extends Entity
{
public const ENTITY_TYPE = 'ImportError';
public const TYPE_VALIDATION = 'Validation';
public const TYPE_NO_ACCESS = 'No-Access';
public const TYPE_NOT_FOUND = 'Not-Found';
public const TYPE_INTEGRITY_CONSTRAINT_VIOLATION = 'Integrity-Constraint-Violation';
/**
* @return self::TYPE_*|null
*/
public function getType(): ?string
{
return $this->get('type');
}
public function getExportRowIndex(): int
{
return $this->get('exportRowIndex');
}
public function getRowIndex(): int
{
return $this->get('rowIndex');
}
public function getValidationField(): ?string
{
return $this->get('validationField');
}
public function getValidationType(): ?string
{
return $this->get('validationType');
}
/**
* @return string[]
*/
public function getRow(): array
{
/** @var ?string[] $value */
$value = $this->get('row');
if ($value === null) {
throw new LogicException();
}
return $value;
}
public function getImportLink(): Link
{
/** @var ?Link $link */
$link = $this->getValueObject('import');
if ($link === null) {
throw new LogicException();
}
return $link;
}
}

View File

@@ -0,0 +1,280 @@
<?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\Entities;
use Espo\Core\Name\Field;
use Espo\Core\ORM\Entity;
use Espo\Core\Field\Date;
use Espo\Core\Field\Link;
use Espo\Core\Field\LinkMultiple;
use stdClass;
class InboundEmail extends Entity
{
public const ENTITY_TYPE = 'InboundEmail';
public const STATUS_ACTIVE = 'Active';
public const CASE_DISTRIBUTION_DIRECT_ASSIGNMENT = 'Direct-Assignment';
public const CASE_DISTRIBUTION_ROUND_ROBIN = 'Round-Robin';
public const CASE_DISTRIBUTION_LEAST_BUSY = 'Least-Busy';
public function isAvailableForFetching(): bool
{
return $this->isActive() && $this->get('useImap');
}
public function isAvailableForSending(): bool
{
return $this->isActive() && $this->get('useSmtp');
}
public function isActive(): bool
{
return $this->get('status') === self::STATUS_ACTIVE;
}
public function smtpIsForMassEmail(): bool
{
return (bool) $this->get('smtpIsForMassEmail');
}
public function storeSentEmails(): bool
{
return (bool) $this->get('storeSentEmails');
}
public function getReplyToAddress(): ?string
{
return $this->get('replyToAddress');
}
public function getReplyFromAddress(): ?string
{
return $this->get('replyFromAddress');
}
public function getReplyFromName(): ?string
{
return $this->get('replyFromName');
}
public function getName(): ?string
{
return $this->get(Field::NAME);
}
public function getFromName(): ?string
{
return $this->get('fromName');
}
public function getEmailAddress(): ?string
{
return $this->get('emailAddress');
}
public function getAssignToUser(): ?Link
{
/** @var ?Link */
return $this->getValueObject('assignToUser');
}
public function getTargetUserPosition(): ?string
{
return $this->get('targetUserPosition');
}
public function getTeam(): ?Link
{
/** @var ?Link */
return $this->getValueObject('team');
}
public function getTeams(): LinkMultiple
{
/** @var LinkMultiple */
return $this->getValueObject('teams');
}
public function addAllTeamUsers(): bool
{
return (bool) $this->get('addAllTeamUsers');
}
public function keepFetchedEmailsUnread(): bool
{
return (bool) $this->get('keepFetchedEmailsUnread');
}
public function getFetchData(): stdClass
{
$data = $this->get('fetchData') ?? (object) [];
if (!property_exists($data, 'lastUID')) {
$data->lastUID = (object) [];
}
if (!property_exists($data, 'lastDate')) {
$data->lastDate = (object) [];
}
if (!property_exists($data, 'byDate')) {
$data->byDate = (object) [];
}
return $data;
}
public function getFetchSince(): ?Date
{
/** @var ?Date */
return $this->getValueObject('fetchSince');
}
public function getEmailFolder(): ?Link
{
return null;
}
/**
* @return string[]
*/
public function getMonitoredFolderList(): array
{
return $this->get('monitoredFolders') ?? [];
}
public function getHost(): ?string
{
return $this->get('host');
}
public function getPort(): ?int
{
return $this->get('port');
}
public function getUsername(): ?string
{
return $this->get('username');
}
public function getPassword(): ?string
{
return $this->get('password');
}
public function getSecurity(): ?string
{
return $this->get('security');
}
/**
* @return ?class-string<object>
*/
public function getImapHandlerClassName(): ?string
{
/** @var ?class-string<object> */
return $this->get('imapHandler');
}
public function createCase(): bool
{
return (bool) $this->get('createCase');
}
public function autoReply(): bool
{
return (bool) $this->get('reply');
}
public function getSentFolder(): ?string
{
return $this->get('sentFolder');
}
public function getGroupEmailFolder(): ?Link
{
/** @var ?Link */
return $this->getValueObject('groupEmailFolder');
}
public function getCaseDistribution(): ?string
{
return $this->get('caseDistribution');
}
public function getSmtpHost(): ?string
{
return $this->get('smtpHost');
}
public function getSmtpPort(): ?int
{
return $this->get('smtpPort');
}
public function getSmtpAuth(): bool
{
return $this->get('smtpAuth');
}
public function getSmtpSecurity(): ?string
{
return $this->get('smtpSecurity');
}
public function getSmtpUsername(): ?string
{
return $this->get('smtpUsername');
}
public function getSmtpPassword(): ?string
{
return $this->get('smtpPassword');
}
public function getSmtpAuthMechanism(): ?string
{
return $this->get('smtpAuthMechanism');
}
/**
* @return ?class-string<object>
*/
public function getSmtpHandlerClassName(): ?string
{
/** @var ?class-string<object> */
return $this->get('smtpHandler');
}
}

View File

@@ -0,0 +1,186 @@
<?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\Entities;
use Espo\Core\ORM\Entity;
use Espo\ORM\Name\Attribute;
use stdClass;
class Integration extends Entity
{
public const ENTITY_TYPE = 'Integration';
private const ATTR_DATA = 'data';
private const ATTR_ENABLED = 'enabled';
public function has(string $attribute): bool
{
if ($attribute === Attribute::ID) {
return (bool) $this->id;
}
if ($this->hasAttribute($attribute)) {
return $this->hasInContainer($attribute);
}
return property_exists($this->getData(), $attribute);
}
public function get(string $attribute): mixed
{
if ($attribute === Attribute::ID) {
return $this->id;
}
if ($this->hasAttribute($attribute)) {
if ($this->hasInContainer($attribute)) {
return $this->getFromContainer($attribute);
}
return null;
}
return $this->getData()->$attribute ?? null;
}
public function clear(string $attribute): void
{
parent::clear($attribute);
$data = $this->getData();
unset($data->$attribute);
$this->set(self::ATTR_DATA, $data);
}
public function set($attribute, $value = null): static
{
if (is_object($attribute)) {
$attribute = get_object_vars($attribute);
}
if (is_array($attribute)) {
$this->populateFromArray($attribute, false);
return $this;
}
$name = $attribute;
if ($name === Attribute::ID) {
$this->id = $value;
return $this;
}
if ($this->hasAttribute($name)) {
$this->setInContainer($name, $value);
return $this;
}
$data = $this->getData();
$data->$name = $value;
$this->set(self::ATTR_DATA, $data);
return $this;
}
public function isAttributeChanged(string $name): bool
{
if ($name === self::ATTR_DATA) {
return true;
}
return parent::isAttributeChanged($name);
}
protected function populateFromArray(array $data, bool $onlyAccessible = true, bool $reset = false): void
{
if ($reset) {
$this->reset();
}
foreach ($data as $attribute => $value) {
if (!is_string($attribute)) {
continue;
}
if ($this->hasAttribute($attribute)) {
$value = $this->prepareAttributeValue($attribute, $value);
}
$this->set($attribute, $value);
}
}
public function getValueMap(): stdClass
{
$map = [];
if (isset($this->id)) {
$map[Attribute::ID] = $this->id;
}
foreach ($this->getAttributeList() as $attribute) {
if ($attribute === Attribute::ID) {
continue;
}
if ($attribute === self::ATTR_DATA) {
continue;
}
if ($this->has($attribute)) {
$map[$attribute] = $this->get($attribute);
}
}
$data = $this->getData();
$map = array_merge($map, get_object_vars($data));
return (object) $map;
}
public function isEnabled(): bool
{
return (bool) $this->get(self::ATTR_ENABLED);
}
public function getData(): stdClass
{
/** @var stdClass */
return $this->get(self::ATTR_DATA) ?? (object) [];
}
}

View File

@@ -0,0 +1,260 @@
<?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\Entities;
use Espo\Core\Field\DateTime;
use Espo\Core\Job\Job as JobJob;
use Espo\Core\Job\Job\Status;
use Espo\Core\Job\JobDataLess;
use Espo\Core\ORM\Entity;
use Espo\Core\Utils\DateTime as DateTimeUtil;
use stdClass;
class Job extends Entity
{
public const ENTITY_TYPE = 'Job';
/**
* Get a status.
*/
public function getStatus(): string
{
return $this->get('status');
}
/**
* Get a job name.
*/
public function getJob(): ?string
{
return $this->get('job');
}
/**
* Get a scheduled job name.
*/
public function getScheduledJobJob(): ?string
{
return $this->get('scheduledJobJob');
}
/**
* Get a target type.
*/
public function getTargetType(): ?string
{
return $this->get('targetType');
}
/**
* Get a target ID.
*/
public function getTargetId(): ?string
{
return $this->get('targetId');
}
/**
* Get a target group.
*/
public function getTargetGroup(): ?string
{
return $this->get('targetGroup');
}
/**
* Get a group.
*/
public function getGroup(): ?string
{
return $this->get('group');
}
/**
* Get a queue.
*/
public function getQueue(): ?string
{
return $this->get('queue');
}
/**
* Get data.
*/
public function getData(): stdClass
{
return $this->get('data') ?? (object) [];
}
/**
* Get a class name.
*
* @return ?class-string<JobJob|JobDataLess>
*/
public function getClassName(): ?string
{
return $this->get('className');
}
/**
* Get a service name.
*/
public function getServiceName(): ?string
{
return $this->get('serviceName');
}
/**
* Get a method name.
*/
public function getMethodName(): ?string
{
return $this->get('methodName');
}
/**
* Get a scheduled job ID.
*/
public function getScheduledJobId(): ?string
{
return $this->get('scheduledJobId');
}
/**
* Get a started date-time.
*/
public function getStartedAt(): ?string
{
return $this->get('startedAt');
}
/**
* Get a PID.
*/
public function getPid(): ?int
{
return $this->get('pid');
}
/**
* Get a number of attempts left.
*/
public function getAttempts(): int
{
return $this->get('attempts') ?? 0;
}
/**
* Get a number of failed attempts.
*/
public function getFailedAttempts(): int
{
return $this->get('failedAttempts') ?? 0;
}
/**
* Set status.
*
* @param Status::* $status
*/
public function setStatus(string $status): self
{
return $this->set('status', $status);
}
/**
* Set PID.
*/
public function setPid(?int $pid): self
{
return $this->set('pid', $pid);
}
/**
* Set started-at to now.
*/
public function setStartedAtNow(): self
{
return $this->set('startedAt', DateTimeUtil::getSystemNowString());
}
/**
* Set executed-at to now.
*/
public function setExecutedAtNow(): self
{
return $this->set('executedAt', DateTimeUtil::getSystemNowString());
}
public function setName(?string $name): self
{
return $this->set('name', $name);
}
public function setClassName(?string $className): self
{
return $this->set('className', $className);
}
public function setQueue(?string $queue): self
{
return $this->set('queue', $queue);
}
public function setGroup(?string $group): self
{
return $this->set('group', $group);
}
public function setTargetId(?string $targetId): self
{
return $this->set('targetId', $targetId);
}
public function setTargetType(?string $targetType): self
{
return $this->set('targetType', $targetType);
}
public function setData(?JobJob\Data $data): self
{
if (!$data) {
return $this->set('data', $data);
}
return $this->set('data', $data->getRaw());
}
public function setExecuteTime(?DateTime $executeTime): self
{
return $this->setValueObject('executeTime', $executeTime);
}
}

View File

@@ -0,0 +1,37 @@
<?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\Entities;
use Espo\Core\ORM\Entity;
class KanbanOrder extends Entity
{
public const ENTITY_TYPE = 'KanbanOrder';
}

View File

@@ -0,0 +1,42 @@
<?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\Entities;
use Espo\Core\ORM\Entity;
class LayoutRecord extends Entity
{
public const ENTITY_TYPE = 'LayoutRecord';
public function getData(): mixed
{
return $this->get('data');
}
}

View File

@@ -0,0 +1,45 @@
<?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\Entities;
use Espo\Core\ORM\Entity;
class LayoutSet extends Entity
{
public const ENTITY_TYPE = 'LayoutSet';
/**
* @return string[]
*/
public function getLayoutList(): array
{
return $this->get('layoutList') ?? [];
}
}

View File

@@ -0,0 +1,239 @@
<?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\Entities;
use Espo\Core\Name\Field;
use Espo\Core\ORM\Entity;
use stdClass;
class LeadCapture extends Entity
{
public const ENTITY_TYPE = 'LeadCapture';
/**
* @deprecated As of v7.2.
*/
public function isToSubscribeContactIfExists(): bool
{
return $this->get('subscribeToTargetList') && $this->get('subscribeContactToTargetList');
}
public function isActive(): bool
{
return (bool) $this->get('isActive');
}
public function hasFormCaptcha(): bool
{
return (bool) $this->get('formCaptcha');
}
/**
* @return string[]
*/
public function getFormFrameAncestors(): array
{
return $this->get('formFrameAncestors') ?? [];
}
public function getFormText(): ?string
{
return $this->get('formText');
}
public function getFormSuccessText(): ?string
{
return $this->get('formSuccessText');
}
public function getFormLanguage(): ?string
{
return $this->get('formLanguage');
}
public function getFormSuccessRedirectUrl(): ?string
{
$url = $this->get('formSuccessRedirectUrl');
if (!$url) {
return null;
}
if (!str_contains($url, '://')) {
$url = 'https://' . $url;
}
return $url;
}
/**
* @return string[]
*/
public function getFieldList(): array
{
return $this->get('fieldList') ?? [];
}
public function isFieldRequired(string $field): bool
{
/** @var stdClass $fieldParams */
$fieldParams = $this->get('fieldParams') ?? (object) [];
/** @var stdClass $itParams */
$itParams = $fieldParams->$field ?? (object) [];
return (bool) ($itParams->required ?? false);
}
public function getOptInConfirmationSuccessMessage(): ?string
{
return $this->get('optInConfirmationSuccessMessage');
}
public function duplicateCheck(): bool
{
return (bool) $this->get('duplicateCheck');
}
public function skipOptInConfirmationIfSubscribed(): bool
{
return (bool) $this->get('skipOptInConfirmationIfSubscribed');
}
public function createLeadBeforeOptInConfirmation(): bool
{
return (bool) $this->get('createLeadBeforeOptInConfirmation');
}
public function optInConfirmation(): bool
{
return (bool) $this->get('optInConfirmation');
}
public function getOptInConfirmationLifetime(): ?int
{
return $this->get('optInConfirmationLifetime');
}
public function subscribeToTargetList(): bool
{
return (bool) $this->get('subscribeToTargetList');
}
public function subscribeContactToTargetList(): bool
{
return (bool) $this->get('subscribeContactToTargetList');
}
public function getFormId(): ?string
{
return $this->get('formId');
}
public function setFormId(string $apiKey): self
{
return $this->set('formId', $apiKey);
}
public function getApiKey(): ?string
{
return $this->get('apiKey');
}
public function setApiKey(string $apiKey): self
{
$this->set('apiKey', $apiKey);
return $this;
}
public function getName(): ?string
{
return $this->get(Field::NAME);
}
public function getTargetTeamId(): ?string
{
return $this->get('targetTeamId');
}
public function getTargetListId(): ?string
{
return $this->get('targetListId');
}
public function getCampaignId(): ?string
{
return $this->get('campaignId');
}
public function getInboundEmailId(): ?string
{
return $this->get('inboundEmailId');
}
public function getLeadSource(): ?string
{
return $this->get('leadSource');
}
public function getOptInConfirmationEmailTemplateId(): ?string
{
return $this->get('optInConfirmationEmailTemplateId');
}
/**
* @since 8.1.0
*/
public function getPhoneNumberCountry(): ?string
{
return $this->get('phoneNumberCountry');
}
public function hasFormEnabled(): bool
{
return (bool) $this->get('formEnabled');
}
/**
* @since 9.1.0
*/
public function getFormTitle(): ?string
{
return $this->get('formTitle');
}
/**
* @since 9.1.0
*/
public function getFormTheme(): ?string
{
return $this->get('formTheme');
}
}

View File

@@ -0,0 +1,35 @@
<?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\Entities;
class LeadCaptureLogRecord extends \Espo\Core\ORM\Entity
{
public const ENTITY_TYPE = 'LeadCaptureLogRecord';
}

View File

@@ -0,0 +1,166 @@
<?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\Entities;
use Espo\Core\Name\Field;
use Espo\Core\ORM\Entity;
use Espo\Core\Field\DateTime;
use Espo\Core\Field\Link;
use Espo\Core\MassAction\Data;
use Espo\Core\MassAction\Params;
use RuntimeException;
use stdClass;
class MassAction extends Entity
{
public const ENTITY_TYPE = 'MassAction';
public const STATUS_PENDING = 'Pending';
public const STATUS_RUNNING = 'Running';
public const STATUS_SUCCESS = 'Success';
public const STATUS_FAILED = 'Failed';
public function getParams(): Params
{
$raw = $this->get('params');
if (!is_string($raw)) {
throw new RuntimeException("No 'params'.");
}
/** @var Params $params */
$params = unserialize(base64_decode($raw));
return $params;
}
public function getData(): Data
{
$raw = $this->get('data');
if (!$raw instanceof stdClass) {
throw new RuntimeException("No 'data'.");
}
return Data::fromRaw($raw);
}
public function getTargetEntityType(): string
{
$value = $this->get('entityType');
if (!is_string($value)) {
throw new RuntimeException("No 'entityType'.");
}
return $value;
}
public function getAction(): string
{
$value = $this->get('action');
if (!is_string($value)) {
throw new RuntimeException("No 'action'.");
}
return $value;
}
public function getStatus(): string
{
$value = $this->get('status');
if (!is_string($value)) {
throw new RuntimeException("No 'status'.");
}
return $value;
}
public function notifyOnFinish(): bool
{
return (bool) $this->get('notifyOnFinish');
}
public function getCreatedAt(): DateTime
{
$value = $this->getValueObject(Field::CREATED_AT);
if (!$value instanceof DateTime) {
throw new RuntimeException("No 'createdAt'.");
}
return $value;
}
public function getCreatedBy(): Link
{
$value = $this->getValueObject(Field::CREATED_BY);
if (!$value instanceof Link) {
throw new RuntimeException("No 'createdBy'.");
}
return $value;
}
public function getProcessedCount(): int
{
return (int) $this->get('processedCount');
}
public function setStatus(string $status): self
{
$this->set('status', $status);
return $this;
}
public function setProcessedCount(int $processedCount): self
{
$this->set('processedCount', $processedCount);
return $this;
}
public function setNotifyOnFinish(bool $notifyOnFinish = true): self
{
$this->set('notifyOnFinish', $notifyOnFinish);
return $this;
}
}

View File

@@ -0,0 +1,67 @@
<?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\Entities;
use Espo\Core\ORM\Entity;
class NextNumber extends Entity
{
public const ENTITY_TYPE = 'NextNumber';
public function getNumberValue(): ?int
{
return $this->get('value');
}
public function setNumberValue(int $value): self
{
return $this->set('value', $value);
}
public function setTargetEntityType(string $entityType): self
{
return $this->set('entityType', $entityType);
}
public function setTargetFieldName(string $fieldName): self
{
return $this->set('fieldName', $fieldName);
}
public function getTargetEntityType(): string
{
return $this->get('entityType');
}
public function getTargetFieldName(): string
{
return $this->get('fieldName');
}
}

View File

@@ -0,0 +1,362 @@
<?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\Entities;
use Espo\Core\Field\LinkParent;
use Espo\Core\Name\Field;
use Espo\Core\ORM\Entity;
use Espo\Core\Field\DateTime;
use Espo\ORM\Entity as OrmEntity;
use Espo\ORM\EntityCollection;
use Espo\ORM\Name\Attribute;
use RuntimeException;
use stdClass;
class Note extends Entity
{
public const ENTITY_TYPE = 'Note';
public const TARGET_SELF = 'self';
public const TARGET_ALL = 'all';
public const TARGET_TEAMS = 'teams';
public const TARGET_USERS = 'users';
public const TARGET_PORTALS = 'portals';
public const TYPE_POST = 'Post';
public const TYPE_UPDATE = 'Update';
/**
* @deprecated As of v9.2.0
*/
public const TYPE_STATUS = 'Status';
public const TYPE_CREATE = 'Create';
public const TYPE_CREATE_RELATED = 'CreateRelated';
public const TYPE_RELATE = 'Relate';
public const TYPE_UNRELATE = 'Unrelate';
public const TYPE_ASSIGN = 'Assign';
public const TYPE_EMAIL_RECEIVED = 'EmailReceived';
public const TYPE_EMAIL_SENT = 'EmailSent';
private bool $aclIsProcessed = false;
public function isPost(): bool
{
return $this->getType() === self::TYPE_POST;
}
public function isGlobal(): bool
{
return (bool) $this->get('isGlobal');
}
public function getType(): ?string
{
return $this->get('type');
}
public function getTargetType(): ?string
{
return $this->get('targetType');
}
public function getParentType(): ?string
{
return $this->get('parentType');
}
public function getParentId(): ?string
{
return $this->get('parentId');
}
public function getSuperParentType(): ?string
{
return $this->get('superParentType');
}
public function getSuperParentId(): ?string
{
return $this->get('superParentId');
}
public function getRelatedType(): ?string
{
return $this->get('relatedType');
}
public function getRelatedId(): ?string
{
return $this->get('relatedId');
}
public function getData(): stdClass
{
return $this->get('data') ?? (object) [];
}
public function isInternal(): bool
{
return (bool) $this->get('isInternal');
}
public function getPost(): ?string
{
return $this->get('post');
}
public function getNumber(): int
{
return $this->get('number');
}
public function getCreatedAt(): ?DateTime
{
/** @var ?DateTime */
return $this->getValueObject(Field::CREATED_AT);
}
public function setAclIsProcessed(): void
{
$this->aclIsProcessed = true;
}
public function isAclProcessed(): bool
{
return $this->aclIsProcessed;
}
public function loadAttachments(): void
{
$data = $this->get('data');
if (empty($data) || empty($data->attachmentsIds) || !is_array($data->attachmentsIds)) {
$this->loadLinkMultipleField('attachments');
return;
}
if (!$this->entityManager) {
throw new RuntimeException();
}
$attachmentsIds = $data->attachmentsIds;
$collection = $this->entityManager
->getRDBRepository(Attachment::ENTITY_TYPE)
->select([Attribute::ID, Field::NAME, 'type'])
->order(Field::CREATED_AT)
->where([
Attribute::ID => $attachmentsIds
])
->find();
$ids = [];
$names = (object) [];
$types = (object) [];
foreach ($collection as $e) {
$id = $e->getId();
$ids[] = $id;
$names->$id = $e->get(Field::NAME);
$types->$id = $e->get('type');
}
$this->set('attachmentsIds', $ids);
$this->set('attachmentsNames', $names);
$this->set('attachmentsTypes', $types);
}
public function addNotifiedUserId(string $userId): void
{
$userIdList = $this->get('notifiedUserIdList');
if (!is_array($userIdList)) {
$userIdList = [];
}
if (!in_array($userId, $userIdList)) {
$userIdList[] = $userId;
}
$this->set('notifiedUserIdList', $userIdList);
}
public function isUserIdNotified(string $userId): bool
{
$userIdList = $this->get('notifiedUserIdList') ?? [];
return in_array($userId, $userIdList);
}
public function getCreatedById(): ?string
{
return $this->get('createdById');
}
public function setType(string $type): self
{
return $this->set('type', $type);
}
public function setParent(LinkParent|OrmEntity|null $parent): self
{
return $this->setRelatedLinkOrEntity(Field::PARENT, $parent);
}
public function setRelated(LinkParent|OrmEntity|null $related): self
{
return $this->setRelatedLinkOrEntity('related', $related);
}
public function setSuperParent(LinkParent|OrmEntity|null $superParent): self
{
if ($superParent instanceof LinkParent) {
$this->setMultiple([
'superParentId' => $superParent->getId(),
'superParentType' => $superParent->getEntityType(),
]);
return $this;
}
return $this->setRelatedLinkOrEntity('superParent', $superParent);
}
public function setPost(?string $post): self
{
$this->set('post', $post);
return $this;
}
/**
* @param stdClass|array<string, mixed> $data
*/
public function setData(stdClass|array $data): self
{
return $this->set('data', $data);
}
public function loadAdditionalFields(): void
{
if (
$this->getType() == self::TYPE_POST ||
$this->getType() == self::TYPE_EMAIL_RECEIVED ||
$this->getType() == self::TYPE_EMAIL_SENT
) {
$this->loadAttachments();
}
if ($this->getParentId() && $this->getParentType()) {
$this->loadParentNameField(Field::PARENT);
}
if ($this->getRelatedId() && $this->getRelatedType()) {
$this->loadParentNameField('related');
}
if (
$this->getType() == self::TYPE_POST &&
$this->getParentId() === null &&
!$this->get('isGlobal')
) {
$targetType = $this->getTargetType();
if (
!$targetType ||
$targetType === self::TARGET_USERS ||
$targetType === self::TARGET_SELF
) {
$this->loadLinkMultipleField('users');
}
if (
$targetType !== self::TARGET_USERS &&
$targetType !== self::TARGET_SELF
) {
if (!$targetType || $targetType === self::TARGET_TEAMS) {
$this->loadLinkMultipleField(Field::TEAMS);
} else if ($targetType === self::TARGET_PORTALS) {
$this->loadLinkMultipleField('portals');
}
}
}
}
/**
* @param string[] $ids
*/
public function setTeamsIds(array $ids): self
{
return $this->set('teamsIds', $ids);
}
/**
* @param string[] $ids
*/
public function setUsersIds(array $ids): self
{
return $this->set('usersIds', $ids);
}
public function isPinned(): bool
{
return (bool) $this->get('isPinned');
}
public function setIsPinned(bool $isPinned): self
{
$this->set('isPinned', $isPinned);
return $this;
}
public function getParent(): ?OrmEntity
{
return $this->relations->getOne(Field::PARENT);
}
public function getSuperParent(): ?OrmEntity
{
return $this->relations->getOne('superParent');
}
/**
* @return EntityCollection<Attachment>
*/
public function getAttachments(): EntityCollection
{
/** @var EntityCollection<Attachment> */
return $this->relations->getMany('attachments');
}
}

View File

@@ -0,0 +1,176 @@
<?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\Entities;
use Espo\Core\Field\LinkParent;
use Espo\Core\ORM\Entity;
use stdClass;
class Notification extends Entity
{
public const ENTITY_TYPE = 'Notification';
public const TYPE_ENTITY_REMOVED = 'EntityRemoved';
public const TYPE_ASSIGN = 'Assign';
public const TYPE_EMAIL_RECEIVED = 'EmailReceived';
public const TYPE_NOTE = 'Note';
public const TYPE_MENTION_IN_POST = 'MentionInPost';
public const TYPE_MESSAGE = 'Message';
public const TYPE_USER_REACTION = 'UserReaction';
public const TYPE_SYSTEM = 'System';
public const ATTR_READ = 'read';
public const ATTR_USER_ID = 'userId';
public const ATTR_ACTION_ID = 'actionId';
public const ATTR_NUMBER = 'number';
public function getType(): ?string
{
return $this->get('type');
}
public function setMessage(?string $message): self
{
$this->set('message', $message);
return $this;
}
public function setType(string $type): self
{
$this->set('type', $type);
return $this;
}
public function getData(): ?stdClass
{
return $this->get('data');
}
public function getUserId(): ?string
{
return $this->get('userId');
}
/**
* @param stdClass|array<string, mixed> $data
*/
public function setData(stdClass|array $data): self
{
$this->set('data', $data);
return $this;
}
public function setUserId(string $userId): self
{
$this->set('userId', $userId);
return $this;
}
public function getRelated(): ?LinkParent
{
/** @var ?LinkParent */
return $this->getValueObject('related');
}
public function setRelated(LinkParent|Entity|null $related): self
{
if ($related instanceof LinkParent) {
$this->setValueObject('related', $related);
return $this;
}
$this->relations->set('related', $related);
return $this;
}
public function setRelatedParent(LinkParent|Entity|null $relatedParent): self
{
if ($relatedParent instanceof LinkParent) {
$this->setValueObject('relatedParent', $relatedParent);
return $this;
}
$this->relations->set('relatedParent', $relatedParent);
return $this;
}
public function setRelatedType(?string $relatedType): self
{
$this->set('relatedType', $relatedType);
return $this;
}
public function setRelatedId(?string $relatedId): self
{
$this->set('relatedId', $relatedId);
return $this;
}
public function isRead(): bool
{
return $this->get('read');
}
public function setRead(bool $read = true): self
{
$this->set('read', $read);
return $this;
}
/**
* @since 9.2.0
*/
public function setActionId(?string $actionId): self
{
$this->set('actionId', $actionId);
return $this;
}
/**
* @since 9.2.0
*/
public function getActionId(): ?string
{
return $this->get('actionId');
}
}

View File

@@ -0,0 +1,84 @@
<?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.
************************************************************************/
/** @noinspection PhpMultipleClassDeclarationsInspection */
namespace Espo\Entities;
use Espo\Core\Field\DateTime;
use Espo\Core\ORM\Entity;
use SensitiveParameter;
use ValueError;
class OAuthAccount extends Entity
{
public const ENTITY_TYPE = 'OAuthAccount';
public function getProvider(): OAuthProvider
{
$provider = $this->relations->getOne('provider');
if (!$provider instanceof OAuthProvider) {
throw new ValueError("No provider.");
}
return $provider;
}
public function getAccessToken(): ?string
{
return $this->get('accessToken');
}
public function getRefreshToken(): ?string
{
return $this->get('refreshToken');
}
public function getExpiresAt(): ?DateTime
{
/** @var ?DateTime */
return $this->getValueObject('expiresAt');
}
public function setAccessToken(#[SensitiveParameter] ?string $accessToken): self
{
return $this->set('accessToken', $accessToken);
}
public function setRefreshToken(#[SensitiveParameter] ?string $refreshToken): self
{
return $this->set('refreshToken', $refreshToken);
}
public function setExpiresAt(?DateTime $expiresAt): self
{
return $this->setValueObject('expiresAt', $expiresAt);
}
}

View File

@@ -0,0 +1,113 @@
<?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.
************************************************************************/
/** @noinspection PhpMultipleClassDeclarationsInspection */
namespace Espo\Entities;
use Espo\Core\ORM\Entity;
use stdClass;
use ValueError;
class OAuthProvider extends Entity
{
public const ENTITY_TYPE = 'OAuthProvider';
public function isActive(): bool
{
return $this->get('isActive');
}
public function getClientId(): string
{
$value = $this->get('clientId');
if (!is_string($value)) {
throw new ValueError("No client ID.");
}
return $value;
}
public function getClientSecret(): string
{
$value = $this->get('clientSecret');
if (!is_string($value)) {
throw new ValueError("No client secret.");
}
return $value;
}
public function getTokenEndpoint(): string
{
$value = $this->get('tokenEndpoint');
if (!is_string($value)) {
throw new ValueError("No token endpoint.");
}
return $value;
}
public function getAuthorizationEndpoint(): string
{
$value = $this->get('authorizationEndpoint');
if (!is_string($value)) {
throw new ValueError("No authorization endpoint.");
}
return $value;
}
/**
* @return string[]
*/
public function getScopes(): array
{
return $this->get('scopes') ?? [];
}
public function getScopeSeparator(): ?string
{
return $this->get('scopeSeparator');
}
public function getAuthorizationPrompt(): string
{
return $this->get('authorizationPrompt');
}
public function getAuthorizationParams(): ?stdClass
{
return $this->get('authorizationParams') ?? null;
}
}

View File

@@ -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\Entities;
use Espo\Core\ORM\Entity;
use UnexpectedValueException;
class PasswordChangeRequest extends Entity
{
public const ENTITY_TYPE = 'PasswordChangeRequest';
public function getUrl(): ?string
{
return $this->get('url');
}
public function getRequestId(): string
{
return $this->get('requestId');
}
public function getUserId(): string
{
$userId = $this->get('userId');
if ($userId === null) {
throw new UnexpectedValueException();
}
return $userId;
}
}

View File

@@ -0,0 +1,104 @@
<?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\Entities;
use Espo\Core\Name\Field;
use InvalidArgumentException;
use Espo\Core\ORM\Entity;
class PhoneNumber extends Entity
{
public const ENTITY_TYPE = 'PhoneNumber';
public const RELATION_ENTITY_PHONE_NUMBER = 'EntityPhoneNumber';
/**
* @param string $value
* @return void
*/
protected function _setName($value)
{
if (empty($value)) {
throw new InvalidArgumentException("Phone number can't be empty");
}
$this->setInContainer(Field::NAME, $value);
}
public function getNumber(): string
{
return $this->get(Field::NAME);
}
public function isOptedOut(): bool
{
return $this->get('optOut');
}
public function isInvalid(): bool
{
return $this->get('invalid');
}
public function getType(): ?string
{
return $this->get('type');
}
public function setType(string $type): self
{
$this->set('type', $type);
return $this;
}
public function setNumber(string $number): self
{
$this->set(Field::NAME, $number);
return $this;
}
public function setOptedOut(bool $optedOut): self
{
$this->set('optOut', $optedOut);
return $this;
}
public function setInvalid(bool $invalid): self
{
$this->set('invalid', $invalid);
return $this;
}
}

View File

@@ -0,0 +1,96 @@
<?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\Entities;
use Espo\Core\Field\Link;
use Espo\Core\ORM\Entity;
use Espo\Repositories\Portal as PortalRepository;
class Portal extends Entity
{
public const ENTITY_TYPE = 'Portal';
/**
* @var string[]
*/
protected $settingsAttributeList = [
'applicationName',
'companyLogoId',
'tabList',
'quickCreateList',
'dashboardLayout',
'dashletsOptions',
'theme',
'themeParams',
'language',
'timeZone',
'dateFormat',
'timeFormat',
'weekStart',
'defaultCurrency',
];
/**
* @return string[]
*/
public function getSettingsAttributeList(): array
{
return $this->settingsAttributeList;
}
public function getUrl(): ?string
{
if (!$this->has('url') && $this->entityManager) {
/** @var PortalRepository $repository */
$repository = $this->entityManager->getRDBRepositoryByClass(Portal::class);
$repository->loadUrlField($this);
}
return $this->get('url');
}
public function getAuthenticationProvider(): ?Link
{
/** @var ?Link */
return $this->getValueObject('authenticationProvider');
}
public function getLayoutSet(): ?Link
{
/** @var ?Link */
return $this->getValueObject('layoutSet');
}
public function isActive(): bool
{
return $this->get('isActive');
}
}

View File

@@ -0,0 +1,64 @@
<?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\Entities;
use Espo\Core\ORM\Entity;
use stdClass;
class PortalRole extends Entity
{
public const ENTITY_TYPE = 'PortalRole';
public function getRawData(): stdClass
{
return $this->get('data') ?? (object) [];
}
public function getRawFieldData(): stdClass
{
return $this->get('fieldData') ?? (object) [];
}
/**
* @param array<string, mixed>|stdClass $data
*/
public function setRawData(array|stdClass $data): self
{
return $this->set('data', $data);
}
/**
* @param array<string, mixed>|stdClass $fieldData
*/
public function setRawFieldData(array|stdClass $fieldData): self
{
return $this->set('fieldData', $fieldData);
}
}

View File

@@ -0,0 +1,55 @@
<?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\Entities;
class Preferences extends \Espo\Core\ORM\Entity
{
public const ENTITY_TYPE = 'Preferences';
/**
* For backward compatibility.
* @deprecated
* @return null
*/
public function getSmtpParams()
{
return null;
}
public function getTimeZone(): ?string
{
return $this->get('timeZone');
}
public function getLanguage(): ?string
{
return $this->get('language');
}
}

View File

@@ -0,0 +1,64 @@
<?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\Entities;
use Espo\Core\ORM\Entity;
use stdClass;
class Role extends Entity
{
public const ENTITY_TYPE = 'Role';
public function getRawData(): stdClass
{
return $this->get('data') ?? (object) [];
}
public function getRawFieldData(): stdClass
{
return $this->get('fieldData') ?? (object) [];
}
/**
* @param array<string, mixed>|stdClass $data
*/
public function setRawData(array|stdClass $data): self
{
return $this->set('data', $data);
}
/**
* @param array<string, mixed>|stdClass $fieldData
*/
public function setRawFieldData(array|stdClass $fieldData): self
{
return $this->set('fieldData', $fieldData);
}
}

View File

@@ -0,0 +1,55 @@
<?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\Entities;
use Espo\Core\Name\Field;
use Espo\Core\ORM\Entity;
class ScheduledJob extends Entity
{
public const ENTITY_TYPE = 'ScheduledJob';
public const STATUS_ACTIVE = 'Active';
public function getName(): ?string
{
return $this->get(Field::NAME);
}
public function getScheduling(): ?string
{
return $this->get('scheduling');
}
public function getJob(): ?string
{
return $this->get('job');
}
}

View File

@@ -0,0 +1,35 @@
<?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\Entities;
class ScheduledJobLogRecord extends \Espo\Core\ORM\Entity
{
public const ENTITY_TYPE = 'ScheduledJobLogRecord';
}

View File

@@ -0,0 +1,35 @@
<?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\Entities;
class Settings extends \Espo\Core\ORM\Entity
{
public const ENTITY_TYPE = 'Settings';
}

View File

@@ -0,0 +1,164 @@
<?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\Entities;
use Espo\Core\Field\LinkMultiple;
use Espo\Core\Name\Field;
use Espo\Core\ORM\Entity;
use Espo\Core\Sms\Sms as SmsInterface;
use Espo\Core\Field\DateTime;
use Espo\Repositories\Sms as SmsRepository;
use RuntimeException;
class Sms extends Entity implements SmsInterface
{
public const ENTITY_TYPE = 'Sms';
public const STATUS_ARCHIVED = 'Archived';
public const STATUS_SENT = 'Sent';
public const STATUS_SENDING = 'Sending';
public const STATUS_DRAFT = 'Draft';
public const STATUS_FAILED = 'Failed';
public function getDateSent(): ?DateTime
{
/** @var ?DateTime */
return $this->getValueObject('dateTime');
}
public function getCreatedAt(): ?DateTime
{
/** @var ?DateTime */
return $this->getValueObject(Field::CREATED_AT);
}
public function getBody(): string
{
return $this->get('body') ?? '';
}
public function getStatus(): ?string
{
return $this->get('status');
}
public function setBody(?string $body): self
{
$this->set('body', $body);
return $this;
}
public function setFromNumber(?string $number): self
{
$this->set('from', $number);
return $this;
}
public function addToNumber(string $number): self
{
$list = $this->getToNumberList();
$list[] = $number;
$this->set('to', implode(';', $list));
return $this;
}
public function getFromNumber(): ?string
{
if (!$this->hasInContainer('from') && !$this->isNew()) {
$this->getSmsRepository()->loadFromField($this);
}
return $this->get('from');
}
public function getFromName(): ?string
{
return $this->get('fromName');
}
/**
* @return string[]
*/
public function getToNumberList(): array
{
if (!$this->hasInContainer('to') && !$this->isNew()) {
$this->getSmsRepository()->loadToField($this);
}
$value = $this->get('to');
if (!$value) {
return [];
}
return explode(';', $value);
}
public function setAsSent(): self
{
$this->set('status', Sms::STATUS_SENT);
if (!$this->get('dateSent')) {
$this->set('dateSent', DateTime::createNow()->toString());
}
return $this;
}
public function setStatus(string $status): self
{
$this->set('status', $status);
return $this;
}
private function getSmsRepository(): SmsRepository
{
if (!$this->entityManager) {
throw new RuntimeException();
}
/** @var SmsRepository */
return $this->entityManager->getRepository(Sms::ENTITY_TYPE);
}
public function getTeams(): LinkMultiple
{
/** @var LinkMultiple */
return $this->getValueObject(Field::TEAMS);
}
}

View File

@@ -0,0 +1,37 @@
<?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\Entities;
use Espo\Core\ORM\Entity;
class StarSubscription extends Entity
{
public const ENTITY_TYPE = 'StarSubscription';
}

View File

@@ -0,0 +1,37 @@
<?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\Entities;
use Espo\Core\ORM\Entity;
class StreamSubscription extends Entity
{
public const ENTITY_TYPE = 'StreamSubscription';
}

View 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\Entities;
use Espo\Core\ORM\Entity;
class SystemData extends Entity
{
public const ENTITY_TYPE = 'SystemData';
public const ONLY_ID = '1';
}

View File

@@ -0,0 +1,63 @@
<?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\Entities;
use Espo\Core\Field\Link;
use Espo\Core\ORM\Entity;
class Team extends Entity
{
public const ENTITY_TYPE = 'Team';
public const RELATIONSHIP_ENTITY_TEAM = 'EntityTeam';
public const RELATIONSHIP_TEAM_USER = 'TeamUser';
public const LINK_ROLES = 'roles';
public function getWorkingTimeCalendar(): ?Link
{
/** @var ?Link */
return $this->getValueObject('workingTimeCalendar');
}
public function getLayoutSet(): ?Link
{
/** @var ?Link */
return $this->getValueObject('layoutSet');
}
/**
* @return string[]
*/
public function getPositionList(): array
{
return $this->get('positionList') ?? [];
}
}

View File

@@ -0,0 +1,56 @@
<?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\Entities;
use Espo\Core\ORM\Entity;
use UnexpectedValueException;
class Template extends Entity
{
public const ENTITY_TYPE = 'Template';
public const STATUS_ACTIVE = 'Active';
public function getTargetEntityType(): string
{
$entityType = $this->get('entityType');
if ($entityType === null) {
throw new UnexpectedValueException();
}
return $entityType;
}
public function isActive(): bool
{
return $this->get('status') === self::STATUS_ACTIVE;
}
}

View File

@@ -0,0 +1,69 @@
<?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\Entities;
use Espo\Core\Field\DateTime;
use Espo\Core\Name\Field;
class TwoFactorCode extends \Espo\Core\ORM\Entity
{
public const ENTITY_TYPE = 'TwoFactorCode';
public function isActive(): bool
{
return $this->get('isActive');
}
public function getCreatedAt(): DateTime
{
/** @var DateTime */
return $this->getValueObject(Field::CREATED_AT);
}
public function getCode(): string
{
return $this->get('code');
}
public function getAttemptsLeft(): int
{
return $this->get('attemptsLeft');
}
public function setInactive(): void
{
$this->set('isActive', false);
}
public function decrementAttemptsLeft(): void
{
$this->set('attemptsLeft', $this->getAttemptsLeft() - 1);
}
}

View File

@@ -0,0 +1,105 @@
<?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\Entities;
use Espo\Core\Field\DateTime;
use Espo\Core\Field\LinkParent;
use Espo\Core\Name\Field;
use Espo\Core\ORM\Entity;
use stdClass;
use LogicException;
class UniqueId extends Entity
{
public const ENTITY_TYPE = 'UniqueId';
public function getIdValue(): ?string
{
return $this->get(Field::NAME);
}
public function getTerminateAt(): ?DateTime
{
/** @var ?DateTime */
return $this->getValueObject('terminateAt');
}
public function getData(): stdClass
{
return $this->get('data') ?? (object) [];
}
public function getCreatedAt(): DateTime
{
/** @var ?DateTime $value */
$value = $this->getValueObject(Field::CREATED_AT);
if (!$value) {
throw new LogicException();
}
return $value;
}
/**
* @param array<string, mixed>|stdClass $data
*/
public function setData(array|stdClass $data): self
{
$this->set('data', $data);
return $this;
}
public function setTarget(?LinkParent $target): self
{
if (!$target) {
$this->setMultiple([
'targetId' => null,
'targetType' => null,
]);
} else {
$this->setMultiple([
'targetId' => $target->getId(),
'targetType' => $target->getEntityType(),
]);
}
return $this;
}
public function setTerminateAt(?DateTime $terminateAt): self
{
$this->setValueObject('terminateAt', $terminateAt);
return $this;
}
}

View File

@@ -0,0 +1,343 @@
<?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\Entities;
use Espo\Core\Entities\Person;
use Espo\Core\Field\Link;
use Espo\Core\Field\LinkMultiple;
use Espo\Core\Name\Field;
use Espo\Modules\Crm\Entities\Contact;
use RuntimeException;
class User extends Person
{
public const ENTITY_TYPE = 'User';
public const ATTR_TYPE = 'type';
public const ATTR_IS_ACTIVE = 'isActive';
public const LINK_ACCOUNTS = 'accounts';
public const LINK_CONTACT = 'contact';
public const LINK_PORTALS = 'portals';
public const LINK_TEAMS = 'teams';
public const LINK_DEFAULT_TEAM = 'defaultTeam';
public const LINK_ROLES = 'roles';
public const LINK_PORTAL_ROLES = 'portalRoles';
public const TYPE_PORTAL = 'portal';
public const TYPE_ADMIN = 'admin';
public const TYPE_SYSTEM = 'system';
public const TYPE_REGULAR = 'regular';
public const TYPE_API = 'api';
public const TYPE_SUPER_ADMIN = 'super-admin';
public const RELATIONSHIP_ENTITY_USER = 'EntityUser';
public const RELATIONSHIP_ENTITY_COLLABORATOR = 'EntityCollaborator';
public function get(string $attribute): mixed
{
if ($attribute === Field::NAME) {
return $this->getNameInternal();
}
return parent::get($attribute);
}
public function has(string $attribute): bool
{
if ($attribute === Field::NAME) {
return $this->hasNameInternal();
}
return parent::has($attribute);
}
public function isActive(): bool
{
return (bool) $this->get('isActive');
}
/**
* @deprecated Use `isPortal`.
*/
public function isPortalUser(): bool
{
return $this->isPortal();
}
public function getType(): ?string
{
return $this->get('type');
}
/**
* @param self::TYPE_* $type
*/
public function setType(string $type): self
{
return $this->set('type', $type);
}
public function setUserName(?string $userName): self
{
return $this->set('userName', $userName);
}
/**
* Is regular user.
*/
public function isRegular(): bool
{
return $this->getType() === self::TYPE_REGULAR ||
($this->has('type') && !$this->getType());
}
/**
* Is admin, super-admin or system user.
*/
public function isAdmin(): bool
{
return $this->getType() === self::TYPE_ADMIN ||
$this->isSystem() ||
$this->isSuperAdmin();
}
/**
* Is portal user.
*/
public function isPortal(): bool
{
return $this->getType() === self::TYPE_PORTAL;
}
/**
* Is API user.
*/
public function isApi(): bool
{
return $this->getType() === self::TYPE_API;
}
/**
* Is system user.
*/
public function isSystem(): bool
{
return $this->getType() === self::TYPE_SYSTEM;
}
/**
* Is super-admin user.
*/
public function isSuperAdmin(): bool
{
return $this->getType() === self::TYPE_SUPER_ADMIN;
}
public function getRoles(): LinkMultiple
{
/** @var LinkMultiple */
return $this->getValueObject('roles');
}
public function getDefaultTeam(): ?Link
{
/** @var ?Link */
return $this->getValueObject('defaultTeam');
}
public function getWorkingTimeCalendar(): ?Link
{
/** @var ?Link */
return $this->getValueObject('workingTimeCalendar');
}
public function getLayoutSet(): ?Link
{
/** @var ?Link */
return $this->getValueObject('layoutSet');
}
public function getTeams(): LinkMultiple
{
/** @var LinkMultiple */
return $this->getValueObject('teams');
}
/**
* @return string[]
*/
public function getTeamIdList(): array
{
/** @var string[] */
return $this->getLinkMultipleIdList('teams');
}
public function setDefaultTeam(?Link $defaultTeam): self
{
$this->setValueObject('defaultTeam', $defaultTeam);
return $this;
}
public function setTeams(LinkMultiple $teams): self
{
$this->setValueObject('teams', $teams);
return $this;
}
public function getPortals(): LinkMultiple
{
/** @var LinkMultiple */
return $this->getValueObject('portals');
}
public function setPortals(LinkMultiple $portals): self
{
$this->setValueObject('portals', $portals);
return $this;
}
public function setRoles(LinkMultiple $roles): self
{
$this->setValueObject('roles', $roles);
return $this;
}
public function loadAccountField(): void
{
if (!$this->entityManager) {
throw new RuntimeException("No entity manager");
}
if ($this->get('contactId')) {
$contact = $this->entityManager->getEntityById(Contact::ENTITY_TYPE, $this->get('contactId'));
if ($contact && $contact->get('accountId')) {
$this->set('accountId', $contact->get('accountId'));
$this->set('accountName', $contact->get('accountName'));
}
}
}
public function setTitle(?string $title): self
{
$this->set('title', $title);
return $this;
}
public function getTitle(): ?string
{
return $this->get('title');
}
public function getUserName(): ?string
{
return $this->get('userName');
}
public function getAuthMethod(): ?string
{
return $this->get('authMethod');
}
public function getContactId(): ?string
{
return $this->get('contactId');
}
public function getContact(): ?Contact
{
/** @var ?Contact */
return $this->relations->getOne('contact');
}
/**
* Get a portal ID of the currently logged user.
*/
public function getPortalId(): ?string
{
return $this->get('portalId');
}
public function getAccounts(): LinkMultiple
{
/** @var LinkMultiple $value */
$value = $this->getValueObject('accounts');
return $value;
}
public function getAvatarId(): ?string
{
return $this->get('avatarId');
}
public function getAvatarColor(): ?string
{
return $this->get('avatarColor');
}
/**
* Get a password hash.
*/
public function getPassword(): string
{
return $this->get('password') ?? '';
}
private function getNameInternal(): ?string
{
if (!$this->hasInContainer(Field::NAME) || !$this->getFromContainer(Field::NAME)) {
if ($this->get('userName')) {
return $this->get('userName');
}
}
return $this->getFromContainer(Field::NAME);
}
private function hasNameInternal(): bool
{
if ($this->hasInContainer(Field::NAME)) {
return true;
}
if ($this->has('userName')) {
return true;
}
return false;
}
}

View File

@@ -0,0 +1,45 @@
<?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\Entities;
class UserData extends \Espo\Core\ORM\Entity
{
public const ENTITY_TYPE = 'UserData';
public function getAuth2FA(): bool
{
return $this->get('auth2FA');
}
public function getAuth2FAMethod(): ?string
{
return $this->get('auth2FAMethod');
}
}

View File

@@ -0,0 +1,71 @@
<?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\Entities;
use Espo\Core\Field\LinkParent;
use Espo\Core\Name\Field;
use Espo\Core\ORM\Entity;
class UserReaction extends Entity
{
const ENTITY_TYPE = 'UserReaction';
public function getType(): string
{
return $this->get('type');
}
public function getParent(): LinkParent
{
/** @var LinkParent */
return $this->getValueObject(Field::PARENT);
}
public function setType(string $type): self
{
$this->set('type', $type);
return $this;
}
public function setParent(Note $note): self
{
$this->relations->set(Field::PARENT, $note);
return $this;
}
public function setUser(User $user): self
{
$this->relations->set('user', $user);
return $this;
}
}

View File

@@ -0,0 +1,77 @@
<?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\Entities;
use Espo\Core\ORM\Entity;
class Webhook extends Entity
{
public const ENTITY_TYPE = 'Webhook';
public function getEvent(): string
{
return $this->get('event') ?? '';
}
public function getSecretKey(): ?string
{
return $this->get('secretKey');
}
public function getUrl(): ?string
{
return $this->get('url');
}
public function isActive(): bool
{
return $this->get('isActive');
}
public function getUserId(): ?string
{
return $this->get('userId');
}
public function getTargetEntityType(): string
{
return $this->get('entityType');
}
public function setSkipOwn(bool $skipOwn): self
{
return $this->set('skipOwn', $skipOwn);
}
public function skipOwn(): bool
{
return (bool) $this->get('skipOwn');
}
}

View File

@@ -0,0 +1,94 @@
<?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\Entities;
use Espo\Core\Field\LinkParent;
use Espo\Core\ORM\Entity;
use stdClass;
class WebhookEventQueueItem extends Entity
{
public const ENTITY_TYPE = 'WebhookEventQueueItem';
public function setIsProcessed(bool $isProcessed = true): self
{
$this->set('isProcessed', $isProcessed);
return $this;
}
public function getEvent(): string
{
return (string) $this->get('event');
}
public function getTargetType(): ?string
{
return $this->get('targetType');
}
public function getTargetId(): ?string
{
return $this->get('targetId');
}
public function getUserId(): ?string
{
return $this->get('userId');
}
public function getData(): stdClass
{
return $this->get('data') ?? (object) [];
}
public function setEvent(string $event): self
{
return $this->set('event', $event);
}
public function setUserId(?string $userId): self
{
return $this->set('userId', $userId);
}
public function setTarget(LinkParent|Entity $target): self
{
return $this->setRelatedLinkOrEntity('target', $target);
}
/**
* @param stdClass|array<string, mixed> $data
*/
public function setData(stdClass|array $data): self
{
return $this->set('data', $data);
}
}

View File

@@ -0,0 +1,125 @@
<?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\Entities;
use Espo\Core\Field\DateTime;
use Espo\Core\Field\LinkParent;
use Espo\Core\ORM\Entity;
use stdClass;
class WebhookQueueItem extends Entity
{
public const ENTITY_TYPE = 'WebhookQueueItem';
public const STATUS_PENDING = 'Pending';
public const STATUS_SUCCESS = 'Success';
public const STATUS_FAILED = 'Failed';
public function getAttempts(): int
{
return $this->get('attempts') ?? 0;
}
public function setStatus(string $status): self
{
return $this->set('status', $status);
}
public function setData(stdClass $data): self
{
return $this->set('data', $data);
}
public function setAttempts(?int $attempts): self
{
return $this->set('attempts', $attempts);
}
public function setProcessAt(?DateTime $processAt): self
{
if (!$processAt) {
$this->set('processAt', $processAt);
return $this;
}
$this->set('processAt', $processAt->toString());
return $this;
}
public function setProcessedAt(?DateTime $processedAt): self
{
if (!$processedAt) {
$this->set('processedAt', $processedAt);
return $this;
}
$this->set('processedAt', $processedAt->toString());
return $this;
}
public function getTargetType(): ?string
{
return $this->get('targetType');
}
public function getTargetId(): ?string
{
return $this->get('targetId');
}
public function getWebhookId(): string
{
return $this->get('webhookId') ?? '';
}
public function getData(): stdClass
{
return $this->get('data') ?? (object) [];
}
public function setEvent(string $event): self
{
return $this->set('event', $event);
}
public function setWebhook(Webhook $webhook): self
{
return $this->setRelatedLinkOrEntity('webhook', $webhook);
}
public function setTarget(Entity|LinkParent $target): self
{
return $this->setRelatedLinkOrEntity('target', $target);
}
}

View File

@@ -0,0 +1,132 @@
<?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\Entities;
use Espo\Core\ORM\Entity;
use Espo\Tools\WorkingTime\Calendar\WorkingWeekday;
use Espo\Tools\WorkingTime\Calendar\TimeRange;
use Espo\Tools\WorkingTime\Calendar\Time;
use DateTimeZone;
class WorkingTimeCalendar extends Entity
{
public const ENTITY_TYPE = 'WorkingTimeCalendar';
public function getTimeZone(): ?DateTimeZone
{
$string = $this->get('timeZone');
if (!$string) {
return null;
}
return new DateTimeZone($string);
}
/**
* @return TimeRange[]
*/
public function getTimeRanges(): array
{
return self::convertRanges($this->get('timeRanges'));
}
/**
* @param int<0,6> $weekday
*/
private function hasCustomWeekdayRanges(int $weekday): bool
{
$attribute = 'weekday' . $weekday . 'TimeRanges';
return $this->get($attribute) !== null && $this->get($attribute) !== [];
}
/**
* @param int<0,6> $weekday
* @return TimeRange[]
*/
private function getWeekdayTimeRanges(int $weekday): array
{
$attribute = 'weekday' . $weekday . 'TimeRanges';
$raw = $this->hasCustomWeekdayRanges($weekday) ?
$this->get($attribute) :
$this->get('timeRanges');
return self::convertRanges($raw);
}
/**
* @return WorkingWeekday[]
*/
public function getWorkingWeekdays(): array
{
$list = [];
for ($i = 0; $i <= 6; $i++) {
if (!$this->get('weekday' . $i)) {
continue;
}
$list[] = new WorkingWeekday($i, $this->getWeekdayTimeRanges($i));
}
return $list;
}
/**
* @param array{string, string}[] $ranges
* @return TimeRange[]
*/
private static function convertRanges(array $ranges): array
{
$list = [];
foreach ($ranges as $range) {
$list[] = new TimeRange(
self::convertTime($range[0]),
self::convertTime($range[1])
);
}
return $list;
}
private static function convertTime(string $time): Time
{
/** @var int<0, 23> $h */
$h = (int) explode(':', $time)[0];
/** @var int<0, 59> $m */
$m = (int) explode(':', $time)[1];
return new Time($h, $m);
}
}

View File

@@ -0,0 +1,131 @@
<?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\Entities;
use Espo\Core\Field\Date;
use Espo\Core\Field\LinkMultiple;
use Espo\Core\ORM\Entity;
use Espo\Tools\WorkingTime\Calendar\Time;
use Espo\Tools\WorkingTime\Calendar\TimeRange;
use RuntimeException;
class WorkingTimeRange extends Entity
{
public const ENTITY_TYPE = 'WorkingTimeRange';
public const TYPE_NON_WORKING = 'Non-working';
public const TYPE_WORKING = 'Working';
/**
* @return (self::TYPE_NON_WORKING|self::TYPE_WORKING)
*/
public function getType(): string
{
$type = $this->get('type');
if (!$type) {
throw new RuntimeException();
}
return $type;
}
public function getDateStart(): Date
{
/** @var ?Date $value */
$value = $this->getValueObject('dateStart');
if (!$value) {
throw new RuntimeException();
}
return $value;
}
public function getDateEnd(): Date
{
/** @var ?Date $value */
$value = $this->getValueObject('dateEnd');
if (!$value) {
throw new RuntimeException();
}
return $value;
}
/**
* @return ?TimeRange[]
*/
public function getTimeRanges(): ?array
{
$ranges = self::convertRanges($this->get('timeRanges') ?? []);
if ($ranges === []) {
return null;
}
return $ranges;
}
/**
* @param array{string, string}[] $ranges
* @return TimeRange[]
*/
private static function convertRanges(array $ranges): array
{
$list = [];
foreach ($ranges as $range) {
$list[] = new TimeRange(
self::convertTime($range[0]),
self::convertTime($range[1])
);
}
return $list;
}
private static function convertTime(string $time): Time
{
/** @var int<0, 23> $h */
$h = (int) explode(':', $time)[0];
/** @var int<0, 59> $m */
$m = (int) explode(':', $time)[1];
return new Time($h, $m);
}
public function getUsers(): LinkMultiple
{
/** @var LinkMultiple */
return $this->getValueObject('users');
}
}