/**
  * Prepares the environment before running a test.
  */
 protected function setUp()
 {
     $appConfig = (include 'config/application.config.php');
     $this->setApplicationConfig($appConfig);
     parent::setUp();
     $user = new \MockUser($this->getApplication()->getServiceManager());
     $account = new Account();
     $account->setId(1)->setActive(1)->setDescription('Test Account')->setGuid('24234rr2r2r')->setName('Test Account');
     $em = $this->getMock('EntityManager', array('getRepository', 'getClassMetadata', 'persist', 'flush', 'find'), array(), '', false);
     $em->expects($this->any())->method('find')->will($this->returnValue($account));
     $this->accountController = new AccountController();
 }
Beispiel #2
0
 /**
  *
  * @param \Account\Entity\Account $account        	
  *
  * @return Report
  */
 public function setAccount($account)
 {
     $this->account = $account;
     if ($account && !$account->getReports(true)->contains($this)) {
         $account->addReports(new ArrayCollection([$this]));
     }
     return $this;
 }
 /**
  * Handle Import & Save (Stage 5)
  *
  * @param array $post        	
  * @param Form $form        	
  */
 protected function handleImport($post, $form)
 {
     $outcome = true;
     $request = $this->getRequest();
     $fields = $form->getLeadAttributes();
     $this->results['fields'] = $fields;
     $form->setData($post);
     if ($form->isValid()) {
         if (isset($post['leads'])) {
             $accountName = empty($post['Company']) ? false : $post['Company'];
             $account_id = false;
             if ($accountName) {
                 $account = $accountName ? $this->findAccount($accountName) : false;
                 if (!$account) {
                     $account = new Account();
                     $guid = IdGenerator::generate();
                     $account->setName($accountName)->setDescription($accountName);
                     $account->setGuid($guid);
                     try {
                         $em = $this->getEntityManager();
                         $em->persist($account);
                         $em->flush();
                         $account_id = $account->getId();
                     } catch (\Exception $e) {
                         $account = false;
                         $outcome = false;
                         $this->flashMessenger()->addErrorMessage($e->getMessage());
                     }
                 } else {
                     $account_id = $account->getId();
                 }
             } else {
                 $account = false;
             }
             $all_leads_json = $post['leads'];
             $all_leads = @\Zend\Json\Json::decode($all_leads_json, \Zend\Json\Json::TYPE_ARRAY);
             $leads = isset($all_leads['valid']) ? $all_leads['valid'] : false;
             $company = $post['Company'];
             if ($leads && is_array($leads)) {
                 $leads = array_values($leads);
                 try {
                     $this->createServiceEvent()->setEntityClass($this->getEntityClass())->setDescription("Lead Import");
                     $em = $this->getEntityManager();
                     for ($i = 1; $i <= count($leads); ++$i) {
                         $extract = isset($leads[$i - 1]) ? $leads[$i - 1] : false;
                         if ($extract) {
                             $lead = null;
                             $this->createServiceEvent()->setEntityClass($this->getEntityClass())->setDescription("Lead Import");
                             $entity = new Lead();
                             $lead = $this->hydrate($entity, $extract);
                             if ($lead) {
                                 try {
                                     $em = $this->getEntityManager();
                                     $em->persist($lead);
                                     $em->flush();
                                     $lead_id = $lead->getId();
                                     if ($account_id && $lead instanceof Lead) {
                                         $account = $this->findAccount($account_id, 'id');
                                         $account->addLead($lead);
                                     }
                                     $message = 'Lead #' . $lead_id . ' was imported.';
                                     $this->getServiceEvent()->setEntityId($lead_id)->setMessage($message);
                                     $this->logEvent("ImportAction.post");
                                     $em->flush();
                                     $em->clear();
                                 } catch (\Exception $e) {
                                     $this->logError($e);
                                     if ($outcome) {
                                         $this->flashMessenger()->addErrorMessage($e->getMessage());
                                     }
                                     $outcome = false;
                                     $em->clear();
                                 }
                             } elseif ($outcome) {
                                 $outcome = false;
                             }
                         }
                     }
                     $em->flush();
                     $em->clear();
                 } catch (\Exception $e) {
                     $this->logError($e);
                     if ($outcome) {
                         $this->flashMessenger()->addErrorMessage($e->getMessage());
                     }
                     $outcome = false;
                 }
             }
             if (!$outcome) {
                 $message = "One or more records could not be properly imported.";
                 $this->flashMessenger()->addErrorMessage($message);
             } else {
                 $message = count($leads) . " record(s) were imported.";
                 $this->flashMessenger()->addSuccessMessage($message);
                 $this->stage = 5;
             }
         } else {
             $outcome = false;
         }
     } else {
         $outcome = false;
     }
     return $outcome;
 }
Beispiel #4
0
 /**
  * Get ipaddress
  *
  * @return string
  */
 public function getAccountDescription()
 {
     return $this->account->getDescription();
 }