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; }