Example #1
0
 protected function beforeCreate(Entity $entity, array $data = array())
 {
     parent::beforeCreate($entity, $data);
     if (!$this->getAcl()->check($entity, 'edit')) {
         throw new Forbidden();
     }
 }
Example #2
0
 protected function handleInput(&$data)
 {
     parent::handleInput($data);
     if (array_key_exists('password', $data)) {
         $data['password'] = $this->getCrypt()->encrypt($data['password']);
     }
 }
Example #3
0
 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);
         }
     }
 }
Example #4
0
 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));
 }
Example #5
0
 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);
     }
 }
Example #6
0
 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);
         }
     }
 }
Example #7
0
 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);
 }
Example #8
0
 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);
         }
     }
 }
Example #9
0
 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;
 }
Example #10
0
 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);
         }
     }
 }
Example #11
0
 public function afterUpdate(Entity $entity, array $data)
 {
     parent::afterUpdate($entity, $data);
     $this->clearRolesCache();
 }
Example #12
0
 public function afterCreate(Entity $entity, array $data = array())
 {
     parent::afterCreate($entity, $data);
     // TODO: Change the autogenerated stub
     if (array_key_exists('agentId', $data)) {
         $agentId = $entity->get('agentId');
         $agentEntity = $this->getEntityManager()->getEntity('Agent', $agentId);
         $agentEntity->set(array('userId' => $entity->id));
         $this->getEntityManager()->saveEntity($agentEntity);
     }
 }
Example #13
0
 public function linkEntity($id, $link, $foreignId)
 {
     if ($id == $foreignId) {
         throw new Forbidden();
     }
     return parent::linkEntity($id, $link, $foreignId);
 }
Example #14
0
 public function loadAdditionalFields(Entity $entity)
 {
     parent::loadAdditionalFields($entity);
     $this->loadRemindersField($entity);
 }
Example #15
0
 public function loadAdditionalFieldsForList(Entity $entity)
 {
     parent::loadAdditionalFields($entity);
     $this->loadEntryCountField($entity);
 }
Example #16
0
 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'));
                 }
             }
         }
     }
     $this->loadUserColumnFields($entity);
 }