From 2a0ce60f219eb535fcb0c29b6055e4e4bac82987 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Thu, 27 Mar 2014 15:42:05 +0200 Subject: [PATCH] invitation 3 --- .../Crm/EntryPoints/EventConfirmation.php | 97 +++++++++++++++++++ .../Espo/Modules/Crm/Services/Meeting.php | 13 +-- 2 files changed, 104 insertions(+), 6 deletions(-) create mode 100644 application/Espo/Modules/Crm/EntryPoints/EventConfirmation.php diff --git a/application/Espo/Modules/Crm/EntryPoints/EventConfirmation.php b/application/Espo/Modules/Crm/EntryPoints/EventConfirmation.php new file mode 100644 index 0000000000..eb4c96572f --- /dev/null +++ b/application/Espo/Modules/Crm/EntryPoints/EventConfirmation.php @@ -0,0 +1,97 @@ +getEntityManager()->getRepository('UniqueId')->where(array('name' => $uid))->findOne(); + + if (!$uniqueId) { + //throw new NotFound(); + echo "Link is not available"; + return; + } + + $data = json_decode($uniqueId->get('data')); + + $eventType = $data->eventType; + $eventId = $data->eventId; + $inviteeType = $data->inviteeType; + $inviteeId = $data->inviteeId; + $link = $data->link; + + if (!empty($eventType) && !empty($eventId) && !empty($inviteeType) && !empty($inviteeId) && !empty($link)) { + $event = $this->getEntityManager()->getEntity($eventType, $eventId); + $invitee = $this->getEntityManager()->getEntity($inviteeType, $inviteeId); + if ($event && $invitee) { + $relDefs = $event->getRelations(); + $tableName = Util::toUnderscore($relDefs[$link]['relationName']); + + $status = 'None'; + if ($action == 'accept') { + $status = 'Accepted'; + } else if ($action == 'decline') { + $status = 'Declined'; + } + + $pdo = $this->getEntityManager()->getPDO(); + $sql = " + UPDATE `{$tableName}` SET status = '{$status}' + WHERE ".strtolower($eventType)."_id = '{$eventId}' AND ".strtolower($inviteeType)."_id = '{$inviteeId}' + "; + + $sth = $pdo->prepare($sql); + $sth->execute(); + + $this->getEntityManager()->getRepository('UniqueId')->remove($uniqueId); + + echo $status; + return; + } + } + + throw new Error(); + } +} + diff --git a/application/Espo/Modules/Crm/Services/Meeting.php b/application/Espo/Modules/Crm/Services/Meeting.php index c49e566dcf..a7e382c176 100644 --- a/application/Espo/Modules/Crm/Services/Meeting.php +++ b/application/Espo/Modules/Crm/Services/Meeting.php @@ -62,13 +62,13 @@ class Meeting extends \Espo\Services\Record } if ($uid) { $siteUrl = rtrim($this->getConfig()->get('siteUrl'), '/'); - $contents = str_replace('{acceptLink}', $siteUrl . '?entryPoint=acceptEvent&uid=' . $uid->id, $contents); - $contents = str_replace('{declineLink}', $siteUrl . '?entryPoint=declineEvent&uid=' . $uid->id, $contents); + $contents = str_replace('{acceptLink}', $siteUrl . '?entryPoint=eventConfirmation&action=accept&uid=' . $uid->get('name'), $contents); + $contents = str_replace('{declineLink}', $siteUrl . '?entryPoint=eventConfirmation&action=decline&uid=' . $uid->get('name'), $contents); } return $contents; } - protected function sendInvitation(Entity $entity, Entity $invitee) + protected function sendInvitation(Entity $entity, Entity $invitee, $link) { $uid = $this->getEntityManager()->getEntity('UniqueId'); @@ -77,6 +77,7 @@ class Meeting extends \Espo\Services\Record 'eventId' => $entity->id, 'inviteeId' => $invitee->id, 'inviteeType' => $invitee->getEntityName(), + 'link' => $link ))); $this->getEntityManager()->saveEntity($uid); @@ -111,17 +112,17 @@ class Meeting extends \Espo\Services\Record { $users = $entity->get('users'); foreach ($users as $user) { - $this->sendInvitation($entity, $user); + $this->sendInvitation($entity, $user, 'users'); } $contacts = $entity->get('contacts'); foreach ($contacts as $contact) { - $this->sendInvitation($entity, $contact); + $this->sendInvitation($entity, $contact, 'contacts'); } $leads = $entity->get('leads'); foreach ($leads as $lead) { - $this->sendInvitation($entity, $lead); + $this->sendInvitation($entity, $lead, 'leads'); } return true;