protected function build($countryslug, Request $request, Application $app) { $this->parameters = array('country' => null, 'parentAreas' => array()); $cr = new CountryRepository(); // we accept both ID and Slug. Slug is proper one to use, but some JS may need to load by ID. $this->parameters['country'] = intval($countryslug) ? $cr->loadById($countryslug) : $cr->loadByTwoCharCode($countryslug); if (!$this->parameters['country']) { return false; } // check this country is or was valid for this site $countryInSiteRepo = new CountryInSiteRepository(); if (!$countryInSiteRepo->isCountryInSite($this->parameters['country'], $app['currentSite'])) { return false; } return true; }
protected function build($slug, Request $request, Application $app) { $this->parameters = array(); $gr = new CountryRepository(); // we must accept both ID and Slug. Slug is proper one to use, but some JS needs to load by ID. $this->parameters['country'] = intval($slug) ? $gr->loadById($slug) : $gr->loadByTwoCharCode($slug); if (!$this->parameters['country']) { return false; } // check this country is or was valid for this site $countryInSiteRepo = new CountryInSiteRepository(); if (!$countryInSiteRepo->isCountryInSite($this->parameters['country'], $app['currentSite'])) { return false; } $areaRepoBuilder = new AreaRepositoryBuilder(); $areaRepoBuilder->setSite($app['currentSite']); $areaRepoBuilder->setCountry($this->parameters['country']); $areaRepoBuilder->setNoParentArea(true); $areaRepoBuilder->setIncludeDeleted(false); $this->parameters['childAreas'] = $areaRepoBuilder->fetchAll(); return true; }
function countries(Request $request, Application $app) { $crb = new CountryRepositoryBuilder(); $crb->setSiteInformation($app['currentSite']); $countries = $crb->fetchAll(); if ($request->request->get('submitted') == 'yes' && $request->request->get('CSFRToken') == $app['websession']->getCSFRToken()) { $in = is_array($request->request->get('country')) ? $request->request->get('country') : null; $cisr = new CountryInSiteRepository(); $countriesCount = 0; $timezones = array(); foreach ($countries as $country) { if (isset($in[$country->getTwoCharCode()]) && $in[$country->getTwoCharCode()] == 'yes') { $cisr->addCountryToSite($country, $app['currentSite'], $app['currentUser']); $countriesCount++; foreach (explode(",", $country->getTimezones()) as $timeZone) { $timezones[] = $timeZone; } } else { $cisr->removeCountryFromSite($country, $app['currentSite'], $app['currentUser']); } } $app['currentSite']->setCachedTimezonesAsList($timezones); $app['currentSite']->setCachedIsMultipleCountries($countriesCount > 1); $siteRepository = new SiteRepository(); $siteRepository->editCached($app['currentSite']); return $app->redirect('/admin/'); } return $app['twig']->render('site/admin/countries.html.twig', array('countries' => $countries)); }