mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-29 15:36:07 +00:00
dev
This commit is contained in:
@@ -19,16 +19,32 @@ class Sender
|
||||
protected $config;
|
||||
|
||||
protected $transport;
|
||||
|
||||
protected $isGlobal = false;
|
||||
|
||||
public function __construct($config)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->transport = new SmtpTransport();
|
||||
$this->setupGlobal();
|
||||
$this->config = $config;
|
||||
$this->useGlobal();
|
||||
}
|
||||
|
||||
public function useSmtp($smtp)
|
||||
{
|
||||
$this->isGlobal = false;
|
||||
|
||||
// TODO setup smtp
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function setupGlobal()
|
||||
public function useGlobal()
|
||||
{
|
||||
if ($this->isGlobal) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->transport = new SmtpTransport();
|
||||
|
||||
$config = $this->config;
|
||||
|
||||
$opts = array(
|
||||
@@ -48,6 +64,8 @@ class Sender
|
||||
|
||||
$options = new SmtpOptions($opts);
|
||||
$this->transport->setOptions($options);
|
||||
|
||||
$this->isGlobal = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -119,11 +137,9 @@ class Sender
|
||||
}
|
||||
$parts[] = $attachment;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$body->setParts($parts);
|
||||
}
|
||||
|
||||
$body->setParts($parts);
|
||||
$message->setBody($body);
|
||||
|
||||
try {
|
||||
@@ -133,7 +149,8 @@ class Sender
|
||||
} catch (\Exception $e) {
|
||||
throw new Error($e->getMessage(), 500);
|
||||
}
|
||||
|
||||
|
||||
$this->useGlobal();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -89,6 +89,32 @@ class Activities extends \Espo\Core\Services\Base
|
||||
";
|
||||
}
|
||||
|
||||
if ($scope == 'Account') {
|
||||
$tQu = $qu;
|
||||
$qu = "
|
||||
SELECT meeting.id AS 'id', meeting.name AS 'name', meeting.date_start AS 'dateStart', meeting.date_end AS 'dateEnd', 'Meeting' AS '_scope',
|
||||
meeting.assigned_user_id AS assignedUserId, TRIM(CONCAT(user.first_name, ' ', user.last_name)) AS assignedUserName,
|
||||
meeting.parent_type AS 'parentType', meeting.parent_id AS 'parentId', meeting.status AS status
|
||||
FROM `meeting`
|
||||
LEFT JOIN `user` ON user.id = meeting.assigned_user_id
|
||||
JOIN contact_meeting ON
|
||||
meeting.id = contact_meeting.meeting_id AND
|
||||
contact_meeting.deleted = 0
|
||||
JOIN contact ON
|
||||
contact_meeting.contact_id = contact.id AND
|
||||
contact.deleted = 0
|
||||
WHERE
|
||||
meeting.deleted = 0 AND
|
||||
meeting.status {$op} ('". implode("', '", $notIn) . "') AND
|
||||
contact.account_id = ".$this->getPDO()->quote($id)."
|
||||
";
|
||||
$qu = "
|
||||
{$tQu}
|
||||
UNION
|
||||
{$qu}
|
||||
";
|
||||
}
|
||||
|
||||
return $qu;
|
||||
}
|
||||
|
||||
@@ -137,32 +163,76 @@ class Activities extends \Espo\Core\Services\Base
|
||||
";
|
||||
}
|
||||
|
||||
if ($scope == 'Account') {
|
||||
$tQu = $qu;
|
||||
$qu = "
|
||||
SELECT call.id AS 'id', call.name AS 'name', call.date_start AS 'dateStart', call.date_end AS 'dateEnd', 'Call' AS '_scope',
|
||||
call.assigned_user_id AS assignedUserId, TRIM(CONCAT(user.first_name, ' ', user.last_name)) AS assignedUserName,
|
||||
call.parent_type AS 'parentType', call.parent_id AS 'parentId', call.status AS status
|
||||
FROM `call`
|
||||
LEFT JOIN `user` ON user.id = call.assigned_user_id
|
||||
JOIN call_contact ON
|
||||
call.id = call_contact.call_id AND
|
||||
call_contact.deleted = 0
|
||||
JOIN contact ON
|
||||
call_contact.contact_id = contact.id AND
|
||||
contact.deleted = 0
|
||||
WHERE
|
||||
call.deleted = 0 AND
|
||||
call.status {$op} ('". implode("', '", $notIn) . "') AND
|
||||
contact.account_id = ".$this->getPDO()->quote($id)."
|
||||
";
|
||||
$qu = "
|
||||
{$tQu}
|
||||
UNION
|
||||
{$qu}
|
||||
";
|
||||
}
|
||||
|
||||
return $qu;
|
||||
}
|
||||
|
||||
protected function getEmailQuery($scope, $id, $op = 'IN', $notIn = array())
|
||||
{
|
||||
$qu = "
|
||||
SELECT email.id AS 'id', email.name AS 'name', email.date_sent AS 'dateStart', '' AS 'dateEnd', 'Email' AS '_scope',
|
||||
email.assigned_user_id AS assignedUserId, TRIM(CONCAT(user.first_name, ' ', user.last_name)) AS assignedUserName,
|
||||
email.parent_type AS 'parentType', email.parent_id AS 'parentId', email.status AS status
|
||||
SELECT DISTINCT
|
||||
email.id AS 'id', email.name AS 'name', email.date_sent AS 'dateStart', '' AS 'dateEnd', 'Email' AS '_scope',
|
||||
email.assigned_user_id AS assignedUserId, TRIM(CONCAT(user.first_name, ' ', user.last_name)) AS assignedUserName,
|
||||
email.parent_type AS 'parentType', email.parent_id AS 'parentId', email.status AS status
|
||||
FROM `email`
|
||||
LEFT JOIN `user` ON user.id = email.assigned_user_id
|
||||
";
|
||||
|
||||
if ($this->isPerson($scope)) {
|
||||
$qu .= "
|
||||
JOIN email_email_address ON
|
||||
email_email_address.email_id = email.id AND
|
||||
email_email_address.deleted = 0
|
||||
JOIN entity_email_address ON
|
||||
entity_email_address.email_address_id = email_email_address.email_address_id AND
|
||||
entity_email_address.entity_id = ".$this->getPDO()->quote($id)." AND
|
||||
entity_email_address.entity_type = ".$this->getPDO()->quote($scope)." AND
|
||||
entity_email_address.deleted = 0
|
||||
";
|
||||
}
|
||||
|
||||
|
||||
$qu .= "
|
||||
WHERE email.deleted = 0
|
||||
";
|
||||
|
||||
$qu .= "
|
||||
AND email.parent_type = ".$this->getPDO()->quote($scope)." AND email.parent_id = ".$this->getPDO()->quote($id)."
|
||||
";
|
||||
|
||||
if (!$this->isPerson($scope)) {
|
||||
$qu .= "
|
||||
AND email.parent_type = ".$this->getPDO()->quote($scope)." AND email.parent_id = ".$this->getPDO()->quote($id)."
|
||||
";
|
||||
}
|
||||
|
||||
if (!empty($notIn)) {
|
||||
$qu .= "
|
||||
AND email.status {$op} ('". implode("', '", $notIn) . "')
|
||||
";
|
||||
}
|
||||
|
||||
|
||||
return $qu;
|
||||
}
|
||||
|
||||
14
application/Espo/Modules/Crm/Services/Call.php
Normal file
14
application/Espo/Modules/Crm/Services/Call.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Espo\Modules\Crm\Services;
|
||||
|
||||
use \Espo\ORM\Entity;
|
||||
|
||||
use \Espo\Core\Exceptions\Error;
|
||||
use \Espo\Core\Exceptions\Forbidden;
|
||||
|
||||
class Call extends Meeting
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -43,10 +43,34 @@ class Lead extends \Espo\Services\Record
|
||||
$entityManager->getRepository('Contact')->relate($contact, 'opportunities', $opportunity);
|
||||
}
|
||||
$lead->set('createdContactId', $contact->id);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
$lead->set('status', 'Converted');
|
||||
$entityManager->saveEntity($lead);
|
||||
|
||||
if ($meetings = $lead->get('meetings')) {
|
||||
foreach ($meetings as $meeting) {
|
||||
if (!empty($contact)) {
|
||||
$entityManager->getRepository('Meeting')->relate($meeting, 'contacts', $contact);
|
||||
}
|
||||
if (!empty($opportunity)) {
|
||||
$entityManager->getRepository('Opportunity')->relate($opportunity, 'meetings', $meeting);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($calls = $lead->get('calls')) {
|
||||
foreach ($calls as $call) {
|
||||
if (!empty($contact)) {
|
||||
$entityManager->getRepository('Call')->relate($call, 'contacts', $contact);
|
||||
}
|
||||
if (!empty($opportunity)) {
|
||||
$entityManager->getRepository('Opportunity')->relate($opportunity, 'calls', $call);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $lead;
|
||||
}
|
||||
|
||||
33
application/Espo/Modules/Crm/Services/Meeting.php
Normal file
33
application/Espo/Modules/Crm/Services/Meeting.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Espo\Modules\Crm\Services;
|
||||
|
||||
use \Espo\ORM\Entity;
|
||||
|
||||
use \Espo\Core\Exceptions\Error;
|
||||
use \Espo\Core\Exceptions\Forbidden;
|
||||
|
||||
class Meeting extends \Espo\Services\Record
|
||||
{
|
||||
protected function storeEntity(Entity $entity)
|
||||
{
|
||||
$assignedUserId = $entity->get('assignedUserId');
|
||||
if ($assignedUserId && $entity->has('usersIds')) {
|
||||
$usersIds = $entity->get('usersIds');
|
||||
if (!is_array($usersIds)) {
|
||||
$usersIds = array();
|
||||
}
|
||||
if (!in_array($assignedUserId, $usersIds)) {
|
||||
$usersIds[] = $assignedUserId;
|
||||
$entity->set('usersIds', $usersIds);
|
||||
$hash = $entity->get('usersNames');
|
||||
if ($hash instanceof \stdClass) {
|
||||
$hash->assignedUserId = $entity->get('assignedUserName');
|
||||
$entity->set('usersNames', $hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
return parent::storeEntity($entity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -343,8 +343,11 @@ abstract class Mapper implements IMapper
|
||||
}
|
||||
$dataArr = array();
|
||||
|
||||
|
||||
|
||||
$sql = $this->composeSelectQuery($this->toDb($relEntity->getEntityName()), $selectPart, $joinsPart, $wherePart, $orderPart, $offset, $limit);
|
||||
|
||||
|
||||
$ps = $this->pdo->query($sql);
|
||||
if ($ps) {
|
||||
if (!$totalCount) {
|
||||
|
||||
@@ -186,7 +186,7 @@ class Repository
|
||||
$entityName = $entity->relations[$relationName]['entity'];
|
||||
$this->handleSelectParams($params, $entityName);
|
||||
|
||||
$this->mapper->countRelated($entity, $relationName, $params);
|
||||
return $this->mapper->countRelated($entity, $relationName, $params);
|
||||
}
|
||||
|
||||
public function relate(Entity $entity, $relationName, $foreign)
|
||||
|
||||
@@ -24,7 +24,18 @@ class Email extends Record
|
||||
$entity = parent::createEntity($data);
|
||||
|
||||
if ($entity && $entity->get('status') == 'Sending') {
|
||||
$sent = $this->getMailSender()->send($entity);
|
||||
$emailSender = $this->getMailSender();
|
||||
|
||||
if (strtolower($this->getUser()->get('emailAddress')) == strtolower($entity->get('from'))) {
|
||||
//$emailSender->useSmtp(); // TODO use smtp
|
||||
} else {
|
||||
if (!$this->getConfig()->get('outboundEmailIsShared')) {
|
||||
throw new Error('Can not use system smtp. outboundEmailIsShared is false.');
|
||||
}
|
||||
}
|
||||
|
||||
$emailSender->send($entity);
|
||||
|
||||
$this->getEntityManager()->saveEntity($entity);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user