/**
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function addBranchSitesAction(Request $request)
 {
     $em = $this->getDoctrine()->getEntityManager();
     $site = $this->get('sudoux.cms.site')->getSite();
     $branches = $em->getRepository('SudouxMortgageBundle:Branch')->findBy(array('site' => $site, 'active' => true, 'deleted' => false));
     $siteCount = 0;
     foreach ($branches as $branch) {
         if (!$branch->hasSite()) {
             $newSite = new Site();
             $newSite->setParentSite($site);
             $newSite->setActive(true);
             $settings = new Settings();
             $newSite->setSettings($settings);
             $newSite->setName($branch->getName());
             $settings->setBranch($branch);
             $branch->setBranchSite($newSite);
             $em->persist($branch);
             $siteEmail = $branch->getEmail();
             if (isset($siteEmail)) {
                 $settings->setWebsiteEmail($siteEmail);
             }
             $siteType = $em->getRepository('SudouxCmsSiteBundle:SiteType')->findOneBy(array('key_name' => 'branch'));
             $newSite->setSiteType($siteType);
             $parentDomain = $site->getPrimaryDomain();
             $subdomain = str_replace(' ', '', strtolower($branch->getName()));
             $subdomain = preg_replace("/[^a-z ]/", '', $subdomain);
             $subdomain .= '.' . $parentDomain->getDomain();
             $em->persist($settings);
             $em->persist($newSite);
             $subdomain = $this->getAvailableDomain($subdomain);
             $domain = new Domain();
             $domain->setDomain($subdomain);
             $domain->setDescription(sprintf('Primary domain for %s', $newSite->getName()));
             $domain->setSite($newSite);
             $newSite->setPrimaryDomain($domain);
             $em->persist($domain);
             $siteCount++;
         }
     }
     $em->flush();
     $session = $request->getSession();
     $session->getFlashBag()->add('success', $siteCount . ' branch sites have been created.');
     return $this->redirect($this->generateUrl('sudoux_cms_admin_internal_tools'));
 }
Пример #2
0
 /**
  * @param LifecycleEventArgs $args
  */
 public function postPersist(LifecycleEventArgs $args)
 {
     $this->em = $args->getEntityManager();
     $entity = $args->getEntity();
     if ($entity instanceof LoanOfficer || $entity instanceof Branch) {
         $site = $entity->getSite();
         $autoCreateSites = $site->getSettings()->getInheritedAutoCreateSites();
         if ($autoCreateSites) {
             if ($entity instanceof LoanOfficer) {
                 if (!$entity->hasSite()) {
                     $newSite = new Site();
                     $newSite->setParentSite($site);
                     $newSite->setActive(true);
                     $settings = new Settings();
                     $newSite->setSettings($settings);
                     $newSite->setName($entity->getFullName());
                     $settings->setLoanOfficer($entity);
                     $entity->setOfficerSite($newSite);
                     $this->em->persist($entity);
                     $siteEmail = $entity->getEmail();
                     if (isset($siteEmail)) {
                         $settings->setWebsiteEmail($siteEmail);
                     }
                     $siteType = $this->em->getRepository('SudouxCmsSiteBundle:SiteType')->findOneBy(array('key_name' => 'loan_officer'));
                     $newSite->setSiteType($siteType);
                     $parentDomain = $site->getPrimaryDomain();
                     $subdomain = str_replace(' ', '', strtolower($entity->getFullName()));
                     $subdomain = preg_replace("/[^a-z ]/", '', $subdomain);
                     $subdomain .= '.' . $parentDomain->getDomain();
                     $this->em->persist($settings);
                     $this->em->persist($newSite);
                     $subdomain = $this->getAvailableDomain($subdomain);
                     $domain = new Domain();
                     $domain->setDomain($subdomain);
                     $domain->setDescription(sprintf('Primary domain for %s', $newSite->getName()));
                     $domain->setSite($newSite);
                     $this->em->persist($domain);
                     $newSite->setPrimaryDomain($domain);
                     $this->em->flush();
                 }
             }
             if ($entity instanceof Branch) {
                 if (!$entity->hasSite()) {
                     $newSite = new Site();
                     $newSite->setParentSite($site);
                     $newSite->setActive(true);
                     $settings = new Settings();
                     $newSite->setSettings($settings);
                     $newSite->setName($entity->getName());
                     $settings->setBranch($entity);
                     $entity->setBranchSite($newSite);
                     $this->em->persist($entity);
                     $siteEmail = $entity->getEmail();
                     if (isset($siteEmail)) {
                         $settings->setWebsiteEmail($siteEmail);
                     }
                     $siteType = $this->em->getRepository('SudouxCmsSiteBundle:SiteType')->findOneBy(array('key_name' => 'branch'));
                     $newSite->setSiteType($siteType);
                     $parentDomain = $site->getPrimaryDomain();
                     $subdomain = str_replace(' ', '', strtolower($entity->getName()));
                     $subdomain = preg_replace("/[^a-z ]/", '', $subdomain);
                     $subdomain .= '.' . $parentDomain->getDomain();
                     $this->em->persist($settings);
                     $this->em->persist($newSite);
                     $subdomain = $this->getAvailableDomain($subdomain);
                     $domain = new Domain();
                     $domain->setDomain($subdomain);
                     $domain->setDescription(sprintf('Primary domain for %s', $newSite->getName()));
                     $domain->setSite($newSite);
                     $this->em->persist($domain);
                     $newSite->setPrimaryDomain($domain);
                     $this->em->flush();
                 }
             }
         }
     }
 }