public function beforeSave(Entity $entity) { if (!$entity->has('executeTime')) { $entity->set('executeTime', date('Y-m-d H:i:s')); } if (!$entity->has('attempts')) { $attempts = $this->getConfig()->get('cron.attempts', 0); $entity->set('attempts', $attempts); } }
protected function fetchAutoFollowEntityTypeList(Entity $entity) { $id = $entity->id; $autoFollowEntityTypeList = []; $pdo = $this->getEntityManger()->getPDO(); $sql = "\n SELECT `entity_type` AS 'entityType' FROM `autofollow`\n WHERE `user_id` = " . $pdo->quote($id) . "\n ORDER BY `entity_type`\n "; $sth = $pdo->prepare($sql); $sth->execute(); $rows = $sth->fetchAll(); foreach ($rows as $row) { $autoFollowEntityTypeList[] = $row['entityType']; } $this->data[$id]['autoFollowEntityTypeList'] = $autoFollowEntityTypeList; $entity->set('autoFollowEntityTypeList', $autoFollowEntityTypeList); }
protected function loadPhoneNumberField(Entity $entity) { $fieldDefs = $this->getMetadata()->get('entityDefs.' . $entity->getEntityType() . '.fields', array()); if (!empty($fieldDefs['phoneNumber']) && $fieldDefs['phoneNumber']['type'] == 'phone') { $dataFieldName = 'phoneNumberData'; $entity->set($dataFieldName, $this->getEntityManager()->getRepository('PhoneNumber')->getPhoneNumberData($entity)); } }
public function save(Entity $entity, array $options = array()) { $nowString = date('Y-m-d H:i:s', time()); $restoreData = array(); if ($entity->isNew()) { if (!$entity->has('id')) { $entity->set('id', Util::generateId()); } if ($entity->hasField('createdAt')) { $entity->set('createdAt', $nowString); } if ($entity->hasField('modifiedAt')) { $entity->set('modifiedAt', $nowString); } if ($entity->hasField('createdById')) { $entity->set('createdById', $this->entityManager->getUser()->id); } if ($entity->has('modifiedById')) { $restoreData['modifiedById'] = $entity->get('modifiedById'); } if ($entity->has('modifiedAt')) { $restoreData['modifiedAt'] = $entity->get('modifiedAt'); } $entity->clear('modifiedById'); } else { if (empty($options['silent'])) { if ($entity->hasField('modifiedAt')) { $entity->set('modifiedAt', $nowString); } if ($entity->hasField('modifiedById')) { $entity->set('modifiedById', $this->entityManager->getUser()->id); } } if ($entity->has('createdById')) { $restoreData['createdById'] = $entity->get('createdById'); } if ($entity->has('createdAt')) { $restoreData['createdAt'] = $entity->get('createdAt'); } $entity->clear('createdById'); $entity->clear('createdAt'); } $this->restoreData = $restoreData; $result = parent::save($entity, $options); return $result; }
protected function beforeSave(Entity $entity, array $options) { $eaRepositoty = $this->getEntityManager()->getRepository('EmailAddress'); if ($entity->has('attachmentsIds')) { $attachmentsIds = $entity->get('attachmentsIds'); if (!empty($attachmentsIds)) { $entity->set('hasAttachment', true); } } if ($entity->has('from') || $entity->has('to') || $entity->has('cc') || $entity->has('bcc') || $entity->has('replyTo')) { if (!$entity->has('usersIds')) { $entity->loadLinkMultipleField('users'); } if ($entity->has('from')) { $from = trim($entity->get('from')); if (!empty($from)) { $ids = $eaRepositoty->getIds(array($from)); if (!empty($ids)) { $entity->set('fromEmailAddressId', $ids[0]); $this->setUsersIdsByEmailAddressId($entity, $ids[0]); } } else { $entity->set('fromEmailAddressId', null); } } if ($entity->has('to')) { $this->prepareAddressess($entity, 'to'); } if ($entity->has('cc')) { $this->prepareAddressess($entity, 'cc'); } if ($entity->has('bcc')) { $this->prepareAddressess($entity, 'bcc'); } if ($entity->has('replyTo')) { $this->prepareAddressess($entity, 'replyTo'); } $usersIds = $entity->get('usersIds'); $assignedUserId = $entity->get('assignedUserId'); if (!empty($assignedUserId) && !in_array($assignedUserId, $usersIds)) { $usersIds[] = $assignedUserId; } $entity->set('usersIds', $usersIds); } parent::beforeSave($entity, $options); $parentId = $entity->get('parentId'); $parentType = $entity->get('parentType'); if (!empty($parentId) || !empty($parentType)) { $parent = $this->getEntityManager()->getEntity($parentType, $parentId); if (!empty($parent)) { if ($parent->getEntityType() == 'Account') { $accountId = $parent->id; } else { if ($parent->has('accountId')) { $accountId = $parent->get('accountId'); } } if (!empty($accountId)) { $account = $this->getEntityManager()->getEntity('Account', $accountId); if ($account) { $entity->set('accountId', $accountId); $entity->set('accountName', $account->get('name')); } } } } }
protected function parseValue(Entity $entity, $field, $value, $params = array()) { $decimalMark = '.'; if (!empty($params['decimalMark'])) { $decimalMark = $params['decimalMark']; } $defaultCurrency = 'USD'; if (!empty($params['defaultCurrency'])) { $defaultCurrency = $params['defaultCurrency']; } $dateFormat = 'Y-m-d'; if (!empty($params['dateFormat'])) { if (!empty($this->dateFormatsMap[$params['dateFormat']])) { $dateFormat = $this->dateFormatsMap[$params['dateFormat']]; } } $timeFormat = 'H:i'; if (!empty($params['timeFormat'])) { if (!empty($this->timeFormatsMap[$params['timeFormat']])) { $timeFormat = $this->timeFormatsMap[$params['timeFormat']]; } } $fieldDefs = $entity->getFields(); if (!empty($fieldDefs[$field])) { $type = $fieldDefs[$field]['type']; switch ($type) { case Entity::DATE: $dt = \DateTime::createFromFormat($dateFormat, $value); if ($dt) { return $dt->format('Y-m-d'); } break; case Entity::DATETIME: $dt = \DateTime::createFromFormat($dateFormat . ' ' . $timeFormat, $value); if ($dt) { return $dt->format('Y-m-d H:i'); } break; case Entity::FLOAT: $currencyField = $field . 'Currency'; if ($entity->hasField($currencyField)) { if (!$entity->has($currencyField)) { $entity->set($currencyField, $defaultCurrency); } } $a = explode($decimalMark, $value); $a[0] = preg_replace('/[^A-Za-z0-9\\-]/', '', $a[0]); if (count($a) > 1) { return $a[0] . '.' . $a[1]; } else { return $a[0]; } break; } } return $value; }
protected function sendQueueItem(Entity $queueItem, Entity $massEmail, Entity $emailTemplate, $attachmetList = [], $campaign = null, $isTest = false) { $target = $this->getEntityManager()->getEntity($queueItem->get('targetType'), $queueItem->get('targetId')); if (!$target || !$target->id || !$target->get('emailAddress')) { $queueItem->set('status', 'Failed'); $this->getEntityManager()->saveEntity($queueItem); return; } $emailAddress = $target->get('emailAddress'); if (!$emailAddress) { $queueItem->set('status', 'Failed'); $this->getEntityManager()->saveEntity($queueItem); return false; } $emailAddressRecord = $this->getEntityManager()->getRepository('EmailAddress')->getByAddress($emailAddress); if ($emailAddressRecord) { if ($emailAddressRecord->get('invalid') || $emailAddressRecord->get('optOut')) { $queueItem->set('status', 'Failed'); $this->getEntityManager()->saveEntity($queueItem); return false; } } $trackingUrlList = []; if ($campaign) { $trackingUrlList = $campaign->get('trackingUrls'); } $email = $this->getPreparedEmail($queueItem, $massEmail, $emailTemplate, $target, $trackingUrlList); $params = array(); if ($massEmail->get('fromName')) { $params['fromName'] = $massEmail->get('fromName'); } if ($massEmail->get('replyToName')) { $params['replyToName'] = $massEmail->get('replyToName'); } try { $attemptCount = $queueItem->get('attemptCount'); $attemptCount++; $queueItem->set('attemptCount', $attemptCount); $message = new \Zend\Mail\Message(); $header = new \Fox\Core\Mail\Mail\Header\XQueueItemId(); $header->setId($queueItem->id); $message->getHeaders()->addHeader($header); $this->getMailSender()->useGlobal()->send($email, $params, $message, $attachmetList); $emailObject = $emailTemplate; if ($massEmail->get('storeSentEmails')) { $this->getEntityManager()->saveEntity($email); $emailObject = $email; } $queueItem->set('emailAddress', $target->get('emailAddress')); $queueItem->set('status', 'Sent'); $queueItem->set('sentAt', date('Y-m-d H:i:s')); $this->getEntityManager()->saveEntity($queueItem); if ($campaign) { $this->getCampaignService()->logSent($campaign->id, $queueItem->id, $target, $emailObject, $target->get('emailAddress')); } } catch (\Exception $e) { if ($queueItem->get('attemptCount') >= self::MAX_ATTEMPT_COUNT) { $this->setQueueItemFailed($queueItem); $queueItem->set('status', 'Failed'); } $this->getEntityManager()->saveEntity($queueItem); $GLOBALS['log']->error('MassEmail#sendQueueItem: [' . $e->getCode() . '] ' . $e->getMessage()); return false; } return true; }
protected function loadAssignedUserName(Entity $entity) { $user = $this->getEntityManager()->getEntity('User', $entity->get('assignedUserId')); if ($user) { $entity->set('assignedUserName', $user->get('name')); } }
protected function findParent(Entity $email, $emailAddress) { $contact = $this->getEntityManager()->getRepository('Contact')->where(array('emailAddress' => $emailAddress))->findOne(); if ($contact) { if (!$this->getConfig()->get('b2cMode')) { if ($contact->get('accountId')) { $email->set('parentType', 'Account'); $email->set('parentId', $contact->get('accountId')); return true; } } else { $email->set('parentType', 'Contact'); $email->set('parentId', $contact->id); return true; } } else { $account = $this->getEntityManager()->getRepository('Account')->where(array('emailAddress' => $emailAddress))->findOne(); if ($account) { $email->set('parentType', 'Account'); $email->set('parentId', $account->id); return true; } else { $lead = $this->getEntityManager()->getRepository('Lead')->where(array('emailAddress' => $emailAddress))->findOne(); if ($lead) { $email->set('parentType', 'Lead'); $email->set('parentId', $lead->id); return true; } } } }
public function loadUserColumnFields(Entity $entity) { $pdo = $this->getEntityManager()->getPDO(); $sql = "\n SELECT is_read AS 'isRead', is_important AS 'isImportant' FROM email_user\n WHERE\n deleted = 0 AND\n user_id = " . $pdo->quote($this->getUser()->id) . " AND\n email_id = " . $pdo->quote($entity->id) . "\n "; $sth = $pdo->prepare($sql); $sth->execute(); if ($row = $sth->fetch(\PDO::FETCH_ASSOC)) { $isRead = !empty($row['isRead']) ? true : false; $isImportant = !empty($row['isImportant']) ? true : false; } else { $isRead = true; $isImportant = false; } $entity->set('isRead', $isRead); $entity->set('isImportant', $isImportant); }