/**
  * @param Site $site
  * @param $losId
  * @param $groupLosId
  * @return mixed
  * @throws \Doctrine\ORM\NonUniqueResultException
  */
 public function findOneMilestoneByLosId(Site $site, $losId, $groupLosId)
 {
     //$siteIds = $site->getParentSiteIds();
     //array_push($siteIds, $site->getId());
     $q = $this->createQueryBuilder('m')->innerJoin('m.milestone_group', 'g')->where('m.los_id = :los_id')->andWhere('g.site = :site_id')->andWhere('g.los_id = :group_los_id')->setParameter('group_los_id', $groupLosId)->setParameter('site_id', $site->getId())->setParameter('los_id', $losId)->getQuery();
     return $q->getOneOrNullResult();
 }
 public function getGlobals()
 {
     if (isset($this->site)) {
         $siteIds = $this->site->getChildSiteIds();
         array_push($siteIds, $this->site->getId());
         $connection = $this->container->get('doctrine')->getConnection();
         $sql = "SELECT s.name, t.name AS type, d.domain, (SELECT COUNT(l.id) FROM lead l WHERE l.lead_status_id = 1 AND l.site_id=s.id) AS leads, ";
         $sql .= "(SELECT COUNT(a.id) FROM loan_application a WHERE a.status <= 1 AND a.deleted = 0 AND a.site_id=s.id) AS loans FROM site s ";
         $sql .= "INNER JOIN domain d ON s.primary_domain_id=d.id ";
         $sql .= "LEFT JOIN site_type t ON s.site_type_id=t.id ";
         $sql .= sprintf("WHERE s.id IN (%s) ", implode(',', $siteIds));
         $sql .= "GROUP BY s.id";
         $stmt = $connection->prepare($sql);
         //echo $sql; exit;
         $stmt->execute();
         $siteSummary = $stmt->fetchAll();
         // get loans
         $qb = $this->em->createQueryBuilder()->select('count(l.id)')->from('SudouxMortgageBundle:LoanApplication', 'l')->where('l.status = 0 OR l.status = 1')->andWhere('l.site IN (:site_ids)')->andWhere('l.deleted = 0')->setParameter('site_ids', $siteIds);
         $newLoans = $qb->getQuery()->getSingleScalarResult();
         // get docs
         return array('newLoans' => $newLoans, 'siteSummary' => $siteSummary);
     } else {
         return array();
     }
 }
 /**
  * @param Site $site
  * @return array
  */
 public function findAllByParentSites(Site $site)
 {
     $siteIds = $site->getParentSiteIds();
     array_push($siteIds, $site->getId());
     $q = $this->createQueryBuilder('q')->where('q.site IN (:site_ids)')->setParameter('site_ids', $siteIds)->getQuery();
     $results = $q->getResult();
     return $results;
 }
 /**
  * @param Site $site
  * @param $limit
  * @param $offset
  * @return array
  */
 public function findBySiteNotSentToLos(Site $site, $limit, $offset)
 {
     $losConnection = $site->getSettings()->getInheritedLos();
     $siteIds = $site->getChildSiteIds();
     array_push($siteIds, $site->getId());
     if (isset($losConnection)) {
         $q = $this->createQueryBuilder('d')->leftJoin('d.loan', 'l')->where('l.site IN (:site_ids)')->andWhere('d.los_id IS NULL')->andWhere('l.los_id IS NOT NULL')->andWhere('l.deleted = 0')->setParameter('site_ids', $siteIds)->setFirstResult($offset)->setMaxResults($limit)->getQuery();
         return $q->getResult();
     } else {
         return;
     }
 }
Esempio n. 5
0
 /**
  * @param Site $site
  */
 protected function setLosSync(Site $site)
 {
     $losConnection = $site->getSettings()->getInheritedLos();
     if (isset($losConnection)) {
         $losProvider = $losConnection->getLosProvider();
         $losClass = $losProvider->getClassName();
         if ($losClass == 'Sudoux\\MortgageBundle\\Model\\Los\\Encompass') {
             $this->losSync = new Encompass($losConnection, $this->twig, $this->container);
         } elseif ($losClass == 'Sudoux\\MortgageBundle\\Model\\Los\\MortgageBuilder') {
             $this->losSync = new MortgageBuilder($losConnection, $this->twig, $this->container);
         } elseif ($losClass == 'Sudoux\\MortgageBundle\\Model\\Los\\Destiny') {
             $this->losSync = new Destiny($losConnection, $this->twig, $this->container);
         } elseif ($losClass == 'Sudoux\\MortgageBundle\\Model\\Los\\Vantage') {
             $this->losSync = new Vantage($losConnection, $this->twig, $this->container);
         } elseif ($losClass == 'Sudoux\\MortgageBundle\\Model\\Los\\LendingQb') {
             $this->losSync = new Vantage($losConnection, $this->twig, $this->container);
         } else {
             throw new \Exception('LOS not found');
         }
         //$this->losSync = new LosSync($this->losConnection, $twig, $em, $this->site);
     }
 }
 /**
  * @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'));
 }
Esempio n. 7
0
 public function hasSite()
 {
     $hasSite = false;
     if (isset($this->branch_site)) {
         $active = $this->branch_site->getActive();
         $deleted = $this->branch_site->getDeleted();
         if ($active && !$deleted) {
             $hasSite = true;
         }
     }
     return $hasSite;
 }
 /**
  * @param Site $site
  * @return mixed
  */
 public function countBySite(Site $site)
 {
     $siteIds = $site->getParentSiteIds();
     array_push($siteIds, $site->getId());
     $q = $this->createQueryBuilder('o')->select('count(o.id)')->where('o.site IN (:site_ids)')->setParameter('site_ids', $siteIds)->getQuery();
     return $q->getSingleScalarResult();
 }
Esempio n. 9
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();
                 }
             }
         }
     }
 }
Esempio n. 10
0
 /**
  * @param ExecutionContext $context
  */
 public function isLoanOfficerValid(ExecutionContext $context)
 {
     $losConn = $this->site->getSettings()->getInheritedLos();
     if (isset($losConn)) {
         // make sure they enter an los id
         if (empty($this->los_id)) {
             $context->addViolationAtSubPath('los_id', 'This field is required.', array(), null);
         }
     }
 }
 /**
  * @param Site $site
  * @param User $user
  * @return array
  */
 public function findNewMessagesCountByUserQuery(Site $site, User $user)
 {
     $q = $this->createQueryBuilder('l')->select('count(t.id) as messages')->join('l.message_thread', 't')->join('t.message', 'm')->where('l.site = :site')->andWhere('m.user != :user_id')->andWhere('l.user = :user_id')->andWhere('l.deleted = 0')->andWhere('m.status = 0')->setParameter('user_id', $user->getId())->setParameter('site', $site->getId());
     //echo $q->getDQL(); exit;
     return $q->getQuery()->getScalarResult();
 }
 /**
  * @param Request $request
  * @param $type
  * @param $id
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
  * @throws \Symfony\Component\Form\Exception\AlreadyBoundException
  */
 public function addAction(Request $request, $type, $id)
 {
     $siteRequest = $this->get('sudoux.cms.site');
     $site = $siteRequest->getSite();
     $em = $this->getDoctrine()->getEntityManager();
     // check the site limit
     $siteLimitWarning = $this->container->getParameter('site_limit_warning');
     $customer = $site->getInheritedCustomer();
     if (isset($customer)) {
         if ($customer->getRemainingSiteCount() == 0) {
             $request->getSession()->getFlashBag()->add('error', $this->container->getParameter('site_limit_exceeded_message'));
             return $this->redirect($this->generateUrl('sudoux_cms_admin_site'));
         } else {
             if ($customer->getRemainingSiteCount() <= $siteLimitWarning) {
                 $request->getSession()->getFlashBag()->add('warning', sprintf('You have %s sites remaining.', $customer->getRemainingSiteCount()));
             }
         }
     }
     $newSite = new Site();
     $newSite->setParentSite($site);
     $newSite->setActive(true);
     $settings = new Settings();
     $newSite->setSettings($settings);
     if ($type == 'branch') {
         $branch = $em->getRepository('SudouxMortgageBundle:Branch')->findOneBy(array('id' => $id, 'site' => $site));
         if (isset($branch)) {
             $newSite->setName($branch->getName());
             $settings->setBranch($branch);
             $branch->setBranchSite($newSite);
             $em->persist($branch);
             //$subdomain = preg_replace("/[^a-z ]/", '', strtolower($branch->getName()));
             //$domain->setDomain($subdomain . '.' . $site->getPrimaryDomain()->getDomain());
         } else {
             throw $this->createNotFoundException('Branch not found');
         }
     } elseif ($type == 'loan_officer') {
         $loanOfficer = $em->getRepository('SudouxMortgageBundle:LoanOfficer')->findOneBy(array('id' => $id, 'site' => $site));
         if (isset($loanOfficer)) {
             $newSite->setName($loanOfficer->getFullName());
             $settings->setLoanOfficer($loanOfficer);
             $loanOfficer->setOfficerSite($newSite);
             $em->persist($loanOfficer);
         } else {
             throw $this->createNotFoundException('Loan Officer not found');
         }
     } else {
         throw new AccessDeniedException();
     }
     $siteType = $em->getRepository('SudouxCmsSiteBundle:SiteType')->findOneBy(array('key_name' => $type));
     $newSite->setSiteType($siteType);
     $form = $this->createForm(new SiteType($site), $newSite);
     if ($request->getMethod() == 'POST') {
         $form->bind($request);
         $domain = $form['primary_domain']->getData();
         if (isset($domain)) {
             $violations = $this->container->get('validator')->validate($domain);
             foreach ($violations as $violation) {
                 $form['primary_domain']->get('domain')->addError(new FormError($violation->getMessage()));
             }
         }
         if ($form->isValid()) {
             $em->persist($settings);
             $domain = $newSite->getPrimaryDomain();
             $domain->setDescription(sprintf('Primary domain for %s', $newSite->getName()));
             $domain->setSite($newSite);
             $em->persist($domain);
             //$em->persist($settings);
             $em->persist($newSite);
             $em->flush();
             $configure = $form['configure']->getData();
             if ($configure) {
                 return $this->redirect(sprintf('http://%s/admin/site/settings/edit/general', $newSite->getPrimaryDomain()->getDomain()));
             } else {
                 return $this->redirect($this->generateUrl('sudoux_cms_admin_site'));
             }
         }
     }
     return $this->render('SudouxMortgageBundle:SiteAdmin:add.html.twig', array('form' => $form->createView(), 'type' => $type, 'id' => $id));
 }