コード例 #1
0
ファイル: LosSync.php プロジェクト: eric19h/turbulent-wookie
 /**
  * 
  */
 protected function prepareLosSettings(LoanApplication $application)
 {
     $settings = unserialize($this->losConnection->getSettings());
     $losSettings = array();
     if (isset($settings)) {
         foreach ($settings as $key => $value) {
             array_push($losSettings, array("Key" => $key, "Value" => $value));
         }
     }
     return $losSettings;
 }
コード例 #2
0
 /**
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function losSettingsAction(Request $request)
 {
     $siteRequest = $this->get('sudoux.cms.site');
     $site = $siteRequest->getSite();
     $em = $this->getDoctrine()->getEntityManager();
     $settings = $site->getSettings();
     $conn = $settings->getLos();
     if (!isset($conn)) {
         $conn = new LosConnection();
     }
     // deserialize and normalize settings blob
     $losSettings = $conn->getSettings();
     if (isset($losSettings)) {
         $losSettingsArray = unserialize($losSettings);
         $losSettingsText = "";
         foreach ($losSettingsArray as $key => $value) {
             $losSettingsText .= $key . ':' . $value . "\r\n";
         }
         $conn->setSettings($losSettingsText);
     }
     $conn->setSite($site);
     $form = $this->createForm(new LosConnectionType(), $conn);
     if ($request->getMethod() == 'POST') {
         $form->bindRequest($request);
         if ($form->isValid()) {
             $session = $request->getSession();
             // parse the settings
             $losSettingsText = $conn->getSettings();
             if (isset($losSettingsText)) {
                 $losSettings = array();
                 $settingsLines = explode("\r\n", $losSettingsText);
                 foreach ($settingsLines as $setting) {
                     // setup the key value pairs
                     $settingsPair = explode(':', $setting);
                     $key = trim($settingsPair[0]);
                     array_shift($settingsPair);
                     // remove the key
                     if (count($settingsPair) > 1) {
                         $value = implode(':', $settingsPair);
                     } else {
                         $value = $settingsPair[0];
                     }
                     $losSettings[$key] = trim($value);
                 }
                 $conn->setSettings(serialize($losSettings));
             }
             $em->persist($conn);
             $settings->setLos($conn);
             $em->persist($settings);
             // try to connect
             $loanUtil = $this->get('sudoux_mortgage.los_util');
             $losLogin = $loanUtil->tryLogin($site);
             if ($losLogin['success']) {
                 // update milestones
                 $job = new Job('sudoux:mortgage:los', array('upsert_milestones', sprintf('--site_id=%s', $site->getId()), '--env=' . $this->get('kernel')->getEnvironment(), '--no-debug'), true);
                 $em->persist($job);
                 $session->getFlashBag()->add('success', 'Your LOS settings have been updated.');
             } else {
                 $session->getFlashBag()->add('error', 'Failed to connect to the LOS');
             }
             $em->flush();
         }
     }
     return $this->render('SudouxMortgageBundle:SettingsAdmin:losSettings.html.twig', array('form' => $form->createView(), 'losConnection' => $conn));
 }