/** * @param Country $country * * @return array */ public function importSections(Country $country) { $sections = array(); $codeCountry = $country->getCodeCountry(); foreach ($this->filterSections($codeCountry) as $element) { $name = $element->nodeValue; $sectionCode = substr(explode(sprintf("/section/%s/", $codeCountry), $element->attributes->getNamedItem('href')->value)[1], 0, 11); $section = $this->sectionFetcher->getSection($sectionCode); if (!$section || $section && $section->isGalaxyImport()) { $sectionElementsField = $this->filterSectionDetails($codeCountry, $sectionCode, true); $sectionElementsIterator = $this->filterSectionDetails($codeCountry, $sectionCode)->getIterator(); $information = []; $keys = ["Address: ", "Telephone:", "Section website: ", "E-Mail: ", "University name: "]; $cpt = 0; foreach ($sectionElementsField as $sectionElement) { foreach ($keys as $key) { switch ($sectionElement->nodeValue) { case $keys[0]: $information[$cpt] = $this->parseAddress($sectionElementsIterator->current()->ownerDocument->saveHTML($sectionElementsIterator->current())); break; default: $information[$cpt] = $sectionElementsIterator->current()->nodeValue; } } $cpt++; $sectionElementsIterator->next(); } $section = $this->sectionCreator->createSection($sectionCode, $name, $information, $country); $sections[] = $section; } } return $sections; }
public function createCountry($codeCountry, $name, $website, $email) { $country = new Country(); $country->setCodeCountry($codeCountry); $country->setName($name); $country->setWebsite($website); $country->setEmail($email); return $country; }