Skip to content

Commit

Permalink
formula attribute fetch phone email
Browse files Browse the repository at this point in the history
  • Loading branch information
yurikuzn committed Dec 9, 2022
1 parent 7b9c6cd commit 87c5371
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
42 changes: 42 additions & 0 deletions application/Espo/Core/Formula/AttributeFetcher.php
Expand Up @@ -29,9 +29,13 @@

namespace Espo\Core\Formula;

use Espo\Entities\EmailAddress;
use Espo\Entities\PhoneNumber;
use Espo\ORM\Entity;
use Espo\Core\ORM\Entity as CoreEntity;
use Espo\ORM\EntityManager;
use Espo\Repositories\EmailAddress as EmailAddressRepository;
use Espo\Repositories\PhoneNumber as PhoneNumberRepository;

/**
* Fetches attributes from an entity.
Expand Down Expand Up @@ -111,6 +115,44 @@ private function load(CoreEntity $entity, string $attribute): void

return;
}

if ($entity->getAttributeParam($attribute, 'isEmailAddressData')) {
/** @var ?string $fieldName */
$fieldName = $entity->getAttributeParam($attribute, 'field');

if (!$fieldName) {
return;
}

/** @var EmailAddressRepository $emailAddressRepository */
$emailAddressRepository = $this->entityManager->getRepository(EmailAddress::ENTITY_TYPE);

$data = $emailAddressRepository->getEmailAddressData($entity);

$entity->set($attribute, $data);
$entity->setFetched($attribute, $data);;

return;
}

if ($entity->getAttributeParam($attribute, 'isPhoneNumberData')) {
/** @var ?string $fieldName */
$fieldName = $entity->getAttributeParam($attribute, 'field');

if (!$fieldName) {
return;
}

/** @var PhoneNumberRepository $phoneNumberRepository */
$phoneNumberRepository = $this->entityManager->getRepository(PhoneNumber::ENTITY_TYPE);

$data = $phoneNumberRepository->getPhoneNumberData($entity);

$entity->set($attribute, $data);
$entity->setFetched($attribute, $data);;

return;
}
}

public function resetRuntimeCache(): void
Expand Down
6 changes: 5 additions & 1 deletion application/Espo/Core/Utils/Database/Orm/Fields/Email.php
Expand Up @@ -29,6 +29,8 @@

namespace Espo\Core\Utils\Database\Orm\Fields;

use Espo\ORM\Entity;

class Email extends Base
{
/**
Expand Down Expand Up @@ -174,9 +176,11 @@ protected function load($fieldName, $entityType)
'fields' => [
$fieldName => $mainFieldDefs,
$fieldName . 'Data' => [
'type' => 'text',
'type' => Entity::JSON_ARRAY,
'notStorable' => true,
'notExportable' => true,
'isEmailAddressData' => true,
'field' => $fieldName,
],
$fieldName .'IsOptedOut' => [
'type' => 'bool',
Expand Down
6 changes: 5 additions & 1 deletion application/Espo/Core/Utils/Database/Orm/Fields/Phone.php
Expand Up @@ -29,6 +29,8 @@

namespace Espo\Core\Utils\Database\Orm\Fields;

use Espo\ORM\Entity;

class Phone extends Base
{
/**
Expand Down Expand Up @@ -270,9 +272,11 @@ protected function load($fieldName, $entityType)
'fields' => [
$fieldName => $mainFieldDefs,
$fieldName . 'Data' => [
'type' => 'text',
'type' => Entity::JSON_ARRAY,
'notStorable' => true,
'notExportable' => true,
'isPhoneNumberData' => true,
'field' => $fieldName,
],
$fieldName .'IsOptedOut' => [
'type' => 'bool',
Expand Down

0 comments on commit 87c5371

Please sign in to comment.