From a89ecc9e07b7ae0d53e9cddf02c25be42e907e73 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Thu, 1 May 2014 14:54:22 +0300 Subject: [PATCH] email 2 --- application/Espo/Core/Acl.php | 2 +- .../Espo/Resources/i18n/en_US/Email.json | 3 +- .../Espo/Resources/i18n/en_US/Global.json | 4 +- .../Espo/Resources/layouts/Email/filters.json | 3 +- .../Espo/Resources/layouts/Email/list.json | 2 +- .../metadata/clientDefs/EmailAddress.json | 3 - .../Resources/metadata/entityDefs/Email.json | 19 +++++-- application/Espo/Services/Email.php | 57 +++++++++++++++++++ 8 files changed, 76 insertions(+), 17 deletions(-) delete mode 100644 application/Espo/Resources/metadata/clientDefs/EmailAddress.json diff --git a/application/Espo/Core/Acl.php b/application/Espo/Core/Acl.php index 8f7589a548..55d3ba547b 100644 --- a/application/Espo/Core/Acl.php +++ b/application/Espo/Core/Acl.php @@ -213,7 +213,7 @@ class Acl 'delete' => 'own', ); $this->data['EmailAddress'] = array( - 'read' => 'all', + 'read' => 'no', 'edit' => 'no', 'delete' => 'no', ); diff --git a/application/Espo/Resources/i18n/en_US/Email.json b/application/Espo/Resources/i18n/en_US/Email.json index 61ca9691cc..2035ee6bf6 100644 --- a/application/Espo/Resources/i18n/en_US/Email.json +++ b/application/Espo/Resources/i18n/en_US/Email.json @@ -14,7 +14,8 @@ "attachments": "Attachments", "selectTemplate": "Select Template", "fromEmailAddress": "Email From", - "toEmailAddresses": "Email To" + "toEmailAddresses": "Email To", + "emailAddress": "Email Address" }, "links": { }, diff --git a/application/Espo/Resources/i18n/en_US/Global.json b/application/Espo/Resources/i18n/en_US/Global.json index 54e6997706..1b45f2d7ae 100644 --- a/application/Espo/Resources/i18n/en_US/Global.json +++ b/application/Espo/Resources/i18n/en_US/Global.json @@ -6,7 +6,6 @@ "Role": "Role", "EmailTemplate": "Email Template", "OutboundEmail": "Outbound Email", - "EmailAddress": "Email Address", "ScheduledJob": "Scheduled Job" }, "scopeNamesPlural": { @@ -16,8 +15,7 @@ "Role": "Roles", "EmailTemplate": "Email Templates", "OutboundEmail": "Outbound Emails", - "ScheduledJob": "Scheduled Jobs", - "EmailAddress": "Email Addresses" + "ScheduledJob": "Scheduled Jobs" }, "labels": { "Merge": "Merge", diff --git a/application/Espo/Resources/layouts/Email/filters.json b/application/Espo/Resources/layouts/Email/filters.json index 38ff90849e..7201b0f87e 100644 --- a/application/Espo/Resources/layouts/Email/filters.json +++ b/application/Espo/Resources/layouts/Email/filters.json @@ -2,6 +2,5 @@ "dateSent", "parent", "body", - "fromEmailAddress", - "toEmailAddresses" + "emailAddress" ] diff --git a/application/Espo/Resources/layouts/Email/list.json b/application/Espo/Resources/layouts/Email/list.json index 03ac598936..4c185b6b8c 100644 --- a/application/Espo/Resources/layouts/Email/list.json +++ b/application/Espo/Resources/layouts/Email/list.json @@ -1,6 +1,6 @@ [ {"name":"name","width":30,"link":true}, {"name":"dateSent"}, - {"name":"from"}, + {"name":"fromEmailAddress"}, {"name":"status"} ] diff --git a/application/Espo/Resources/metadata/clientDefs/EmailAddress.json b/application/Espo/Resources/metadata/clientDefs/EmailAddress.json deleted file mode 100644 index 1bd5d759c5..0000000000 --- a/application/Espo/Resources/metadata/clientDefs/EmailAddress.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "controller": "Controllers.Record" -} diff --git a/application/Espo/Resources/metadata/entityDefs/Email.json b/application/Espo/Resources/metadata/entityDefs/Email.json index 02d0ce7217..1e5dea05e6 100644 --- a/application/Espo/Resources/metadata/entityDefs/Email.json +++ b/application/Espo/Resources/metadata/entityDefs/Email.json @@ -16,13 +16,7 @@ "type": "varchar", "db": false, "required": true - }, - "fromEmailAddress": { - "type": "link" }, - "toEmailAddresses": { - "type": "linkMultiple" - }, "to": { "type": "varchar", "db": false, @@ -36,6 +30,19 @@ "type": "varchar", "db": false }, + "emailAddress": { + "type": "base", + "db": false + }, + "fromEmailAddress": { + "type": "link" + }, + "toEmailAddresses": { + "type": "linkMultiple" + }, + "ccEmailAddresses": { + "type": "linkMultiple" + }, "bodyPlain": { "type": "text", "readOnly": true diff --git a/application/Espo/Services/Email.php b/application/Espo/Services/Email.php index 2c6cdb8701..659d31592f 100644 --- a/application/Espo/Services/Email.php +++ b/application/Espo/Services/Email.php @@ -115,5 +115,62 @@ class Email extends Record } return $entity; } + + public function findEntities($params) + { + $searchByEmailAddress = false; + if (!empty($params['where']) && is_array($params['where'])) { + foreach ($params['where'] as $i => $p) { + if ($p['field'] == 'emailAddress') { + $searchByEmailAddress = true; + $emailAddress = $this->getEntityManager()->getRepository('EmailAddress')->where(array( + 'lower' => strtolower($p['value']) + ))->findOne(); + unset($params['where'][$i]); + $emailAddressId = null; + if ($emailAddress) { + $emailAddressId = $emailAddress->id; + } + } + + } + } + + $selectParams = $this->getSelectManager($this->entityName)->getSelectParams($params, true); + + if ($searchByEmailAddress) { + if ($emailAddressId) { + $pdo = $this->getEntityManager()->getPDO(); + + $selectParams['customJoin'] = " + LEFT JOIN email_email_address + ON + email_email_address.email_id = email.id AND + email_email_address.deleted = 0 + "; + $selectParams['customWhere'] = " + AND + ( + email.from_email_address_id = ".$pdo->quote($emailAddressId)." OR + email_email_address.email_address_id = ".$pdo->quote($emailAddressId)." + ) + "; + } else { + $selectParams['customWhere'] = ' AND 0'; + } + + } + + $collection = $this->getRepository()->find($selectParams); + + foreach ($collection as $e) { + $this->loadParentNameFields($e); + } + + return array( + 'total' => $this->getRepository()->count($selectParams), + 'collection' => $collection, + ); + } }