/** * @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; }
/** * @param array $sections */ public function saveSections($sections) { foreach ($sections as $section) { $oldSection = $this->sectionFetcher->getSection($section->getCodeSection()); if (!$oldSection) { $this->em->persist($section); $this->em->flush(); } else { $section->setGuide($oldSection->getGuide()); $section->setToken($oldSection->getToken()); $section->setLogoUrl($oldSection->getLogoUrl()); $section->setAddedAt($oldSection->getAddedAt()); $section->setActivated($oldSection->isActivated()); $section->setUpdatedAt(); $this->em->merge($section); $this->em->flush(); } } }
public function checkSection($codeSection) { return $this->sectionFetcher->getSection($codeSection) ? true : false; }