public function afterSave(Entity $entity) { if ($this->getConfig()->get('assignmentEmailNotifications') && $entity->has('assignedUserId') && in_array($entity->getEntityName(), $this->getConfig()->get('assignmentEmailNotificationsEntityList', array()))) { $userId = $entity->get('assignedUserId'); if (!empty($userId) && $userId != $this->getUser()->id && $entity->isFieldChanged('assignedUserId')) { $job = $this->getEntityManager()->getEntity('Job'); $job->set(array('serviceName' => 'EmailNotification', 'method' => 'notifyAboutAssignmentJob', 'data' => json_encode(array('userId' => $userId, 'assignerUserId' => $this->getUser()->id, 'entityId' => $entity->id, 'entityType' => $entity->getEntityName())), 'executeTime' => date('Y-m-d H:i:s'))); $this->getEntityManager()->saveEntity($job); } } }
protected function handleCreateRelated(Entity $entity) { $linkDefs = $this->getMetadata()->get("entityDefs." . $entity->getEntityName() . ".links", array()); $scopeNotifiedList = array(); foreach ($linkDefs as $link => $defs) { if ($defs['type'] == 'belongsTo') { if (empty($defs['foreign']) || empty($defs['entity'])) { continue; } $foreign = $defs['foreign']; $scope = $defs['entity']; $entityId = $entity->get($link . 'Id'); if (!empty($scope) && !empty($entityId)) { if (in_array($scope, $scopeNotifiedList) || !$this->isLinkObservableInStream($scope, $foreign)) { continue; } $this->getStreamService()->noteCreateRelated($entity, $scope, $entityId); $scopeNotifiedList[] = $scope; } } else { if ($defs['type'] == 'belongsToParent') { $foreign = $defs['foreign']; if (empty($defs['foreign'])) { continue; } $scope = $entity->get($link . 'Type'); $entityId = $entity->get($link . 'Id'); if (!empty($scope) && !empty($entityId)) { if (in_array($scope, $scopeNotifiedList) || !$this->isLinkObservableInStream($scope, $foreign)) { continue; } $this->getStreamService()->noteCreateRelated($entity, $scope, $entityId); $scopeNotifiedList[] = $scope; } } else { if ($defs['type'] == 'hasMany') { if (empty($defs['foreign']) || empty($defs['entity'])) { continue; } $foreign = $defs['foreign']; $scope = $defs['entity']; $entityIds = $entity->get($link . 'Ids'); if (!empty($scope) && is_array($entityIds) && !empty($entityIds)) { if (in_array($scope, $scopeNotifiedList) || !$this->isLinkObservableInStream($scope, $foreign)) { continue; } $entityId = $entityIds[0]; $this->getStreamService()->noteCreateRelated($entity, $scope, $entityId); $scopeNotifiedList[] = $scope; } } } } } }
public function getPhoneNumberData(Entity $entity) { $data = array(); $pdo = $this->getEntityManager()->getPDO(); $sql = "\n SELECT phone_number.name, phone_number.type, entity_phone_number.primary\n FROM entity_phone_number\n JOIN phone_number ON phone_number.id = entity_phone_number.phone_number_id AND phone_number.deleted = 0\n WHERE\n entity_phone_number.entity_id = " . $pdo->quote($entity->id) . " AND\n entity_phone_number.entity_type = " . $pdo->quote($entity->getEntityName()) . " AND\n entity_phone_number.deleted = 0\n ORDER BY entity_phone_number.primary DESC\n "; $sth = $pdo->prepare($sql); $sth->execute(); if ($rows = $sth->fetchAll()) { foreach ($rows as $row) { $obj = new \StdClass(); $obj->phoneNumber = $row['name']; $obj->primary = $row['primary'] == '1' ? true : false; $obj->type = $row['type']; $data[] = $obj; } } return $data; }
public function getEmailAddressData(Entity $entity) { $data = array(); $pdo = $this->getEntityManager()->getPDO(); $sql = "\n SELECT email_address.name, email_address.invalid, email_address.opt_out AS optOut, entity_email_address.primary\n FROM entity_email_address\n JOIN email_address ON email_address.id = entity_email_address.email_address_id AND email_address.deleted = 0\n WHERE\n entity_email_address.entity_id = " . $pdo->quote($entity->id) . " AND\n entity_email_address.entity_type = " . $pdo->quote($entity->getEntityName()) . " AND\n entity_email_address.deleted = 0\n ORDER BY entity_email_address.primary DESC\n "; $sth = $pdo->prepare($sql); $sth->execute(); if ($rows = $sth->fetchAll()) { foreach ($rows as $row) { $obj = new \StdClass(); $obj->emailAddress = $row['name']; $obj->primary = $row['primary'] == '1' ? true : false; $obj->optOut = $row['optOut'] == '1' ? true : false; $obj->invalid = $row['invalid'] == '1' ? true : false; $data[] = $obj; } } return $data; }
public function unfollowAllUsersFromEntity(Entity $entity) { if (empty($entity->id)) { return; } $pdo = $this->getEntityManager()->getPDO(); $sql = "\n DELETE FROM subscription\n WHERE\n entity_id = " . $pdo->quote($entity->id) . " AND entity_type = " . $pdo->quote($entity->getEntityName()) . "\n "; $sth = $pdo->prepare($sql)->execute(); }
public function sendInvitation(Entity $entity, Entity $invitee, $link) { $uid = $this->getEntityManager()->getEntity('UniqueId'); $uid->set('data', array('eventType' => $entity->getEntityName(), 'eventId' => $entity->id, 'inviteeId' => $invitee->id, 'inviteeType' => $invitee->getEntityName(), 'link' => $link)); $this->getEntityManager()->saveEntity($uid); $emailAddress = $invitee->get('emailAddress'); if (empty($emailAddress)) { return; } $email = $this->getEntityManager()->getEntity('Email'); $email->set('to', $emailAddress); $subjectTpl = $this->getTemplate('InvitationSubject'); $bodyTpl = $this->getTemplate('InvitationBody'); $subject = $this->parseInvitationTemplate($subjectTpl, $entity, $invitee, $uid); $subject = str_replace(array("\n", "\r"), '', $subject); $body = $this->parseInvitationTemplate($bodyTpl, $entity, $invitee, $uid); $email->set('subject', $subject); $email->set('body', $body); $email->set('isHtml', true); $this->getEntityManager()->saveEntity($email); $attachmentName = ucwords($this->language->translate($entity->getEntityName(), 'scopeNames')) . '.ics'; $attachment = $this->getEntityManager()->getEntity('Attachment'); $attachment->set(array('name' => $attachmentName, 'type' => 'text/calendar', 'contents' => $this->getIscContents($entity))); $email->addAttachment($attachment); $emailSender = $this->mailSender; if ($this->smtpParams) { $emailSender->useSmtp($this->smtpParams); } $emailSender->send($email); $this->getEntityManager()->removeEntity($email); }