public function loadAdditionalFields($entity) { parent::loadAdditionalFields($entity); $sentCount = $this->getEntityManager()->getRepository('CampaignLogRecord')->where(array('campaignId' => $entity->id, 'action' => 'Sent'))->count(); $entity->set('sentCount', $sentCount); $openedCount = $this->getEntityManager()->getRepository('CampaignLogRecord')->where(array('campaignId' => $entity->id, 'action' => 'Opened'))->count(); $entity->set('openedCount', $openedCount); $clickedCount = $this->getEntityManager()->getRepository('CampaignLogRecord')->where(array('campaignId' => $entity->id, 'action' => 'Clicked'))->count(); $entity->set('clickedCount', $clickedCount); $optedOutCount = $this->getEntityManager()->getRepository('CampaignLogRecord')->where(array('campaignId' => $entity->id, 'action' => 'Opted Out'))->count(); $entity->set('optedOutCount', $optedOutCount); $bouncedCount = $this->getEntityManager()->getRepository('CampaignLogRecord')->where(array('campaignId' => $entity->id, 'action' => 'Bounced'))->count(); $entity->set('bouncedCount', $bouncedCount); $leadCreatedCount = $this->getEntityManager()->getRepository('Lead')->where(array('campaignId' => $entity->id))->count(); $entity->set('leadCreatedCount', $leadCreatedCount); $entity->set('revenueCurrency', $this->getConfig()->get('defaultCurrency')); $params = array('select' => array('SUM:amountConverted'), 'whereClause' => array('status' => 'Closed Won', 'campaignId' => $entity->id), 'groupBy' => array('opportunity.campaignId')); $this->getEntityManager()->getRepository('Opportunity')->handleSelectParams($params); $sql = $this->getEntityManager()->getQuery()->createSelectQuery('Opportunity', $params); $pdo = $this->getEntityManager()->getPDO(); $sth = $pdo->prepare($sql); $sth->execute(); if ($row = $sth->fetch(\PDO::FETCH_ASSOC)) { $revenue = floatval($row['SUM:amountConverted']); if ($revenue > 0) { $entity->set('revenue', $revenue); } } }
protected function handleInput(&$data) { parent::handleInput($data); if (array_key_exists('password', $data)) { $data['password'] = $this->getCrypt()->encrypt($data['password']); } }
protected function beforeCreate(Entity $entity, array $data = array()) { parent::beforeCreate($entity, $data); if (!$this->getAcl()->check($entity, 'edit')) { throw new Forbidden(); } }
protected function afterRemove(Entity $entity, array $data = array()) { parent::afterRemove($entity, $data); $existingQueueItemList = $this->getEntityManager()->getRepository('EmailQueueItem')->where(array('status' => ['Pending', 'Failed'], 'massEmailId' => $massEmail->id))->find(); foreach ($existingQueueItemList as $existingQueueItem) { $this->getEntityManager()->getMapper('RDB')->deleteFromDb('EmailQueueItem', $existingQueueItem->id); } }
public function findEntities($params) { $result = parent::findEntities($params); foreach ($result['collection'] as $entity) { $entity->clear('password'); } return $result; }
public function loadAdditionalFields(Entity $entity) { parent::loadAdditionalFields($entity); $importedCount = $this->getRepository()->countRelated($entity, 'imported'); $duplicateCount = $this->getRepository()->countRelated($entity, 'duplicates'); $updatedCount = $this->getRepository()->countRelated($entity, 'updated'); $entity->set(array('importedCount' => $importedCount, 'duplicateCount' => $duplicateCount, 'updatedCount' => $updatedCount)); }
public function createEntity($data) { $entity = parent::createEntity($data); if ($entity) { $entity->set('assignedUserId', $this->getUser()->id); $this->getEntityManager()->saveEntity($entity); } return $entity; }
public function afterCreate($entity, array $data) { parent::afterCreate($entity, $data); if (!empty($data['emailId'])) { $email = $this->getEntityManager()->getEntity('Email', $data['emailId']); if ($email && !$email->get('parentId')) { $email->set(array('parentType' => 'Case', 'parentId' => $entity->id)); $this->getEntityManager()->saveEntity($email); } } }
public function createEntity($data) { if (!empty($data['parentType']) && !empty($data['parentId'])) { $entity = $this->getEntityManager()->getEntity($data['parentType'], $data['parentId']); if ($entity) { if (!$this->getAcl()->check($entity, 'read')) { throw new Forbidden(); } } } return parent::createEntity($data); }
public function afterCreate($entity, array $data) { parent::afterCreate($entity, $data); if (!empty($data['emailId'])) { $email = $this->getEntityManager()->getEntity('Email', $data['emailId']); if ($email && !$email->get('parentId')) { if ($this->getConfig()->get('b2cMode')) { $email->set(array('parentType' => 'Contact', 'parentId' => $entity->id)); } else { if ($entity->get('accountId')) { $email->set(array('parentType' => 'Account', 'parentId' => $entity->get('accountId'))); } } $this->getEntityManager()->saveEntity($email); } } }
public function afterCreate($entity, array $data) { parent::afterCreate($entity, $data); if (!empty($data['emailId'])) { $email = $this->getEntityManager()->getEntity('Email', $data['emailId']); if ($email && !$email->get('parentId')) { $email->set(array('parentType' => 'Lead', 'parentId' => $entity->id)); $this->getEntityManager()->saveEntity($email); } } if ($entity->get('campaignId')) { $campaign = $this->getEntityManager()->getEntity('Campaign', $entity->get('campaignId')); if ($campaign) { $log = $this->getEntityManager()->getEntity('CampaignLogRecord'); $log->set(array('action' => 'Lead Created', 'actionDate' => date('Y-m-d H:i:s'), 'parentType' => 'Lead', 'parentId' => $entity->id, 'campaignId' => $campaign->id)); $this->getEntityManager()->saveEntity($log); } } }
public function getEntity($id = null) { $entity = parent::getEntity($id); if (!empty($id)) { if ($entity->get('fromEmailAddressName')) { $entity->set('from', $entity->get('fromEmailAddressName')); } $entity->loadLinkMultipleField('toEmailAddresses'); $entity->loadLinkMultipleField('ccEmailAddresses'); $entity->loadLinkMultipleField('bccEmailAddresses'); $names = $entity->get('toEmailAddressesNames'); if (!empty($names)) { $arr = array(); foreach ($names as $id => $address) { $arr[] = $address; } $entity->set('to', implode(';', $arr)); } $names = $entity->get('ccEmailAddressesNames'); if (!empty($names)) { $arr = array(); foreach ($names as $id => $address) { $arr[] = $address; } $entity->set('cc', implode(';', $arr)); } $names = $entity->get('bccEmailAddressesNames'); if (!empty($names)) { $arr = array(); foreach ($names as $id => $address) { $arr[] = $address; } $entity->set('bcc', implode(';', $arr)); } $this->loadNameHash($entity); } return $entity; }
public function linkEntity($id, $link, $foreignId) { if ($id == $foreignId) { throw new Forbidden(); } return parent::linkEntity($id, $link, $foreignId); }
public function createEntity($data) { if (!$this->getUser()->isAdmin()) { $count = $this->getEntityManager()->getRepository('EmailAccount')->where(array('assignedUserId' => $this->getUser()->id))->count(); if ($count >= $this->getConfig()->get('maxEmailAccountCount', \PHP_INT_MAX)) { throw new Forbidden(); } } $entity = parent::createEntity($data); if ($entity) { if (!$this->getUser()->isAdmin()) { $entity->set('assignedUserId', $this->getUser()->id); } $this->getEntityManager()->saveEntity($entity); } return $entity; }
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); }
protected function beforeUpdate(Entity $entity, array $data = array()) { parent::beforeUpdate($entity, $data); $entity->clear('targetType'); $entity->clear('usersIds'); $entity->clear('teamsIds'); $entity->clear('isGlobal'); }
public function afterUpdate(Entity $entity, array $data) { parent::afterUpdate($entity, $data); if (array_key_exists('rolesIds', $data) || array_key_exists('teamsIds', $data)) { $this->clearRoleCache($entity->id); } }
public function loadAdditionalFieldsForList(Entity $entity) { parent::loadAdditionalFieldsForList($entity); $userEmailAdddressIdList = []; foreach ($this->getUser()->get('emailAddresses') as $ea) { $userEmailAdddressIdList[] = $ea->id; } $status = $entity->get('status'); if (in_array($entity->get('fromEmailAddressId'), $userEmailAdddressIdList)) { $entity->loadLinkMultipleField('toEmailAddresses'); $idList = $entity->get('toEmailAddressesIds'); $names = $entity->get('toEmailAddressesNames'); if (!empty($idList)) { $arr = []; foreach ($idList as $emailAddressId) { $person = $this->getEntityManager()->getRepository('EmailAddress')->getEntityByAddressId($emailAddressId); if ($person) { $arr[] = $person->get('name'); } else { $arr[] = $names->{$emailAddressId}; } } $entity->set('personStringData', 'To: ' . implode(', ', $arr)); } } else { $fromEmailAddressId = $entity->get('fromEmailAddressId'); if (!empty($fromEmailAddressId)) { $person = $this->getEntityManager()->getRepository('EmailAddress')->getEntityByAddressId($fromEmailAddressId); if ($person) { $entity->set('personStringData', $person->get('name')); } else { $fromName = self::parseFromName($entity->get('fromString')); if (!empty($fromName)) { $entity->set('personStringData', $fromName); } else { $entity->set('personStringData', $entity->get('fromEmailAddressName')); } } } } }
public function loadAdditionalFieldsForList(Entity $entity) { parent::loadAdditionalFields($entity); $this->loadEntryCountField($entity); }
public function findEntities($params) { $result = parent::findEntities($params); return $result; }
public function afterUpdate(Entity $entity, array $data) { parent::afterUpdate($entity, $data); $this->clearRolesCache(); }
public function loadAdditionalFields(Entity $entity) { parent::loadAdditionalFields($entity); $this->loadRemindersField($entity); }
public function deleteEntity($id) { if ($id == 'system') { throw new Forbidden(); } return parent::deleteEntity($id); }