protected function execute($arguments = array(), $options = array()) { // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'])->getConnection(); $request = new FetchAdXmlRequest(FetchAdXmlRequest::PILETILEVI_URL); $piletileviArray = $request->send()->getResponseArray(); $concertsArr = array(); foreach ($piletileviArray['concerts']['concert'] as $index => $concert) { $concertsArr[$index]['code'] = substr($concert['title'], 0, strpos($concert['title'], " /")); $concertsArr[$index]['piletilevi_id'] = $concert['id']; $concertsArr[$index]['availability'] = $concert['status']; if (@is_array($concert['deliveries']['zebra'])) { $concertsArr[$index]['web_sales'] = 1; } else { $concertsArr[$index]['web_sales'] = 0; } } $screenings = ScreeningTable::getScreeningsForSync()->fetchArray(); foreach ($screenings as $screening) { foreach ($concertsArr as $concert) { if ($concert['code'] == $screening['code']) { $obj = Doctrine_Query::create()->select('data.*')->from('Screening' . ' data')->where('id = ?', $screening['id'])->fetchOne(); $obj->synchronizeWithArray($concert); $obj->save(); break; } } } echo 'Sync succesful'; }
public function mapCinemas() { // Because english names are located at a different XML file $request = new FetchAdXmlRequest(self::ENG_URL); $this->enArray = $request->send()->getResponseArray(); foreach ($this->responseArray['cinema'] as $index => $cinema) { $enName = $this->validateElement($this->enArray['cinema'][$index]['name']); $estName = $this->validateElement($cinema['name']); $cinema['eventival_id'] = $this->validateElement($cinema['id']); $cinema['Translation'] = array('et' => array('name' => $estName), 'en' => array('name' => $enName)); // Extract CinemaHall data from Cinema $halls = $cinema['cinema_halls']; $enHalls = $this->enArray['cinema'][$index]['cinema_halls']; // Single and many Cinema Hall are parsed differently if (!isset($halls['cinema_hall']['id'])) { $halls = array_pop($halls); $enHalls = array_pop($enHalls); } unset($cinema['cinema_halls']); unset($cinema['name']); unset($cinema['id']); $action = $this->checkData($this->tableType, $cinema['eventival_id']); if (!$action) { $cinId = $this->createData($this->tableType, $cinema); } else { $cinId = $action; $this->updateData($this->tableType, $cinema, $cinId); } //cinema halls foreach ($halls as $index => $hall) { $enHallName = $this->validateElement($enHalls[$index]['name']); $estHallName = $this->validateElement($hall['name']); $hall['eventival_id'] = $hall['id']; $hall['cinema_id'] = $cinId; $hall['Translation'] = array('et' => array('name' => $estHallName), 'en' => array('name' => $enHallName)); unset($hall['id']); unset($hall['name']); $query = Doctrine_Query::create()->from('CinemaHall data')->select('data.id')->where('data.eventival_id = ?', $hall['eventival_id']); $dbHall = $query->fetchOne(); if ($dbHall) { $this->updateData('CinemaHall', $hall, $dbHall->getId()); } else { $this->createData('CinemaHall', $hall); } } } }
public function mapSections() { // Because english names are located at a different XML file $request = new FetchAdXmlRequest(self::ENG_URL); $this->enArray = $request->send()->getResponseArray(); foreach ($this->responseArray['section'] as $index => $section) { $enName = $this->validateElement($this->enArray['section'][$index]['name']); $enDescription = $this->validateElement($this->enArray['section'][$index]['description']); $estName = $this->validateElement($section['name']); $estDescription = $this->validateElement($section['description']); $section['eventival_id'] = $this->validateElement($section['id']); $section['Translation'] = array('et' => array('name' => $estName, 'description' => $estDescription), 'en' => array('name' => $enName, 'description' => $enDescription)); $section['title'] = $estName; unset($section['id']); unset($section['name']); unset($section['description']); $id = $this->checkData($this->tableType, $section['eventival_id']); if (!$id) { $this->createData($this->tableType, $section); } else { $this->updateData($this->tableType, $section, $id); } } }
public function mapPackage($packageID) { $url = $this->packageBaseUrl . $packageID . '.xml'; $request = new FetchAdXmlRequest($url); $xmlObj = $request->send(); $packageArray = $xmlObj->getResponseArray(); if (isset($packageArray['sections']['section']) && $packageArray['sections']['section'] != '') { // Because eventival can't take test data out of their XML feed $package['eventival_id'] = $this->validateElement($packageArray['ids']['system_id']); $package['title_original'] = $this->validateElement($packageArray['titles']['title_original']); $enName = $this->validateElement($packageArray['titles']['title_english']); $estName = $this->validateElement($packageArray['titles']['title_local']); if (isset($packageArray['publications']['en']) && !empty($packageArray['publications']['en'])) { $enDescription = $this->validateElement($packageArray['publications']['en']['description']); $estDescription = $this->validateElement($packageArray['publications']['et']['description']); } else { $enDescription = ''; $estDescription = ''; } $package['Translation'] = array('et' => array('name' => $estName, 'longdescription' => $estDescription), 'en' => array('name' => $enName, 'longdescription' => $enDescription)); $package['code'] = time(); $package['runtime'] = 0; $id = $this->checkData($this->tableType, $package['eventival_id']); if (!$id) { $id = $this->createData($this->tableType, $package); if (!is_array($packageArray['film_ids']['id'])) { //Hack for foreach $packageArray['film_ids']['id'] = array(1 => $packageArray['film_ids']['id']); } foreach ($packageArray['film_ids']['id'] as $film) { $query = Doctrine_Query::create()->from('Product data')->select('data.id')->where('data.type = ? AND data.eventival_id = ?', array('package_film', $film)); $dbFilm = $query->fetchOne(); if ($dbFilm) { $dbFilmId = $dbFilm->getId(); } else { $filmMapper = new FilmXMLMapper(); $dbFilmId = $filmMapper->mapFilm($film); sleep(1); } $package['runtime'] += Doctrine::getTable('Product')->find($dbFilmId)->getRuntime(); $query = Doctrine_Query::create()->from('ProductVsProduct')->select('product1')->where('product1 = ? AND product2 = ?', array($id, $dbFilmId)); $check = $query->fetchOne(); if (!$check) { $packageVsFilm = new ProductVsProduct(); $packageVsFilm->fromArray(array('product1' => $id, 'product2' => $dbFilmId)); $packageVsFilm->save(); } } } else { $query = Doctrine_Query::create()->from('ProductVsProduct')->select('product2')->where('product1 = ?', $id); $dbFilms = $query->fetchArray(); if (!$dbFilms) { if (!is_array($packageArray['film_ids']['id'])) { //Hack for foreach $packageArray['film_ids']['id'] = array(1 => $packageArray['film_ids']['id']); } foreach ($packageArray['film_ids']['id'] as $film) { $query = Doctrine_Query::create()->from('Product data')->select('data.id')->where('data.type = ? AND data.eventival_id = ?', array('package_film', $film)); $dbFilm = $query->fetchOne(); if ($dbFilm) { $dbFilmId = $dbFilm->getId(); } else { $filmMapper = new FilmXMLMapper(); $dbFilmId = $filmMapper->mapFilm($film); sleep(1); } $package['runtime'] += Doctrine::getTable('Product')->find($dbFilmId)->getRuntime(); $query = Doctrine_Query::create()->from('ProductVsProduct')->select('product1')->where('product1 = ? AND product2 = ?', array($id, $dbFilmId)); $check = $query->fetchOne(); if (!$check) { $packageVsFilm = new ProductVsProduct(); $packageVsFilm->fromArray(array('product1' => $id, 'product2' => $dbFilmId)); $packageVsFilm->save(); } } $query = Doctrine_Query::create()->from('ProductVsProduct')->select('product2')->where('product1 = ?', $id); $dbFilms = $query->fetchArray(); } foreach ($dbFilms as $dbFilmId) { $package['runtime'] += Doctrine::getTable('Product')->find($dbFilmId['product2'])->getRuntime(); } $this->updateData($this->tableType, $package, $id); } if (isset($packageArray['sections']['section']['id'])) { $sectionId = $packageArray['sections']['section']['id']; } else { $sectionId = $packageArray['sections']['section'][0]['id']; } // Section == ProductGroup $query = Doctrine_Query::create()->from('ProductGroup data')->select('data.id')->whereIn('data.eventival_id', $sectionId); $dbSection = $query->fetchOne(); if ($dbSection == null) { // $sectionMapper = new SectionXMLMapper(); // $dbFilmId = $sectionMapper->mapSection($section); } else { $dbSectionId = $dbSection->getId(); } if ($dbSectionId) { $query = Doctrine_Query::create()->from('ProductVsProductGroup')->select('group_id')->where('group_id = ? AND product_id = ?', array($dbSectionId, $id)); $check = $query->fetchOne(); if (!$check) { $fVs = array('group_id' => $dbSectionId, 'product_id' => $id); $filmVsSection = new ProductVsProductGroup(); $filmVsSection->fromArray($fVs); $filmVsSection->save(); } } return $id; } else { return null; } }
public function mapFilm($filmID, $type = 'ProductFilm') { $url = $this->filmBaseUrl . $filmID . '.xml'; $request = new FetchAdXmlRequest($url); $xmlObj = $request->send(); $filmArray = $xmlObj->getResponseArray(); $film['eventival_id'] = $this->validateElement($filmArray['ids']['system_id']); $film['Translation'] = array('et' => array('name' => is_array($filmArray['titles']['title_local']) ? '' : $filmArray['titles']['title_local'], 'description' => is_array($filmArray['publications']['et']['synopsis_long']) ? '' : $filmArray['publications']['et']['synopsis_long'], 'director_bio' => is_array($filmArray['publications']['et']['directors_bio']) ? '' : $filmArray['publications']['et']['directors_bio'], 'country' => is_array($filmArray['film_info']['countries']['country']) ? implode(',', $filmArray['film_info']['countries']['country']) : $filmArray['film_info']['countries']['country'], 'language' => is_array($filmArray['publications']['et']['languages']) ? implode(',', $filmArray['publications']['et']['languages']) : $filmArray['publications']['et']['languages'], 'synopsis' => is_array($filmArray['publications']['et']['synopsis_long']) ? implode(',', $filmArray['publications']['et']['synopsis_long']) : $filmArray['publications']['et']['synopsis_long']), 'en' => array('name' => is_array($filmArray['titles']['title_english']) ? '' : $filmArray['titles']['title_english'], 'description' => is_array($filmArray['publications']['en']['synopsis_long']) ? '' : $filmArray['publications']['en']['synopsis_long'], 'director_bio' => is_array($filmArray['publications']['en']['directors_bio']) ? '' : $filmArray['publications']['en']['directors_bio'], 'country' => is_array($filmArray['film_info']['countries']['country']) ? implode(',', $filmArray['film_info']['countries']['country']) : $filmArray['film_info']['countries']['country'], 'language' => is_array($filmArray['publications']['en']['languages']) ? implode(',', $filmArray['publications']['en']['languages']) : $filmArray['publications']['en']['languages'], 'synopsis' => is_array($filmArray['publications']['en']['synopsis_long']) ? implode(',', $filmArray['publications']['en']['synopsis_long']) : $filmArray['publications']['en']['synopsis_long']), 'ru' => array('name' => is_array($filmArray['titles']['title_english']) ? '' : $filmArray['titles']['title_english'], 'description' => is_array($filmArray['publications']['en']['synopsis_long']) ? '' : $filmArray['publications']['en']['synopsis_long'], 'director_bio' => is_array($filmArray['publications']['en']['directors_bio']) ? '' : $filmArray['publications']['en']['directors_bio'], 'country' => is_array($filmArray['film_info']['countries']['country']) ? implode(',', $filmArray['film_info']['countries']['country']) : $filmArray['film_info']['countries']['country'], 'language' => is_array($filmArray['publications']['en']['languages']) ? implode(',', $filmArray['publications']['en']['languages']) : $filmArray['publications']['en']['languages'], 'synopsis' => is_array($filmArray['publications']['en']['synopsis_long']) ? implode(',', $filmArray['publications']['en']['synopsis_long']) : $filmArray['publications']['en']['synopsis_long'])); $film['original_title'] = $filmArray['titles']['title_original']; $film['director_name'] = is_array($filmArray['publications']['en']['directors']) ? implode(',', $filmArray['publications']['en']['directors']) : $filmArray['publications']['en']['directors']; if ($film['director_name'] == "") { if (isset($filmArray['film_info']['directors']['director']['name']) or isset($filmArray['film_info']['directors']['director']['surname'])) { $film['director_name'] = $filmArray['film_info']['directors']['director']['name'] . ' ' . $filmArray['film_info']['directors']['director']['surname']; } } $film['director_filmography'] = is_array($filmArray['publications']['et']['directors_filmography']) ? implode(',', $filmArray['publications']['et']['directors_filmography']) : $filmArray['publications']['et']['directors_filmography']; $film['producer'] = is_array($filmArray['publications']['en']['producers']) ? implode(',', $filmArray['publications']['en']['producers']) : $filmArray['publications']['en']['producers']; $film['writer'] = is_array($filmArray['publications']['en']['writers']) ? implode(',', $filmArray['publications']['en']['writers']) : $filmArray['publications']['en']['writers']; $film['webpage'] = is_array($filmArray['film_info']['website_official']) ? '' : $filmArray['film_info']['website_official']; $film['festivals'] = is_array($filmArray['publications']['en']['synopsis_short']) ? '' : $filmArray['publications']['en']['synopsis_short']; $film['year'] = is_array($filmArray['film_info']['completion_date']['year']) ? null : $filmArray['film_info']['completion_date']['year']; $film['runtime'] = is_array($filmArray['film_info']['length']) ? null : $filmArray['film_info']['length']; $film['trailer_link'] = is_array($filmArray['film_info']['online_trailer_url']) ? null : $filmArray['film_info']['online_trailer_url']; foreach ($filmArray['publications']['en']['crew']['contact'] as $filmcrew) { if ($filmcrew['type']['id'] == 6) { $film['music'] = is_array($filmcrew['text']) ? '' : $filmcrew['text']; } if ($filmcrew['type']['id'] == 7) { $film['editor'] = is_array($filmcrew['text']) ? '' : $filmcrew['text']; } if ($filmcrew['type']['id'] == 9) { $film['production'] = is_array($filmcrew['text']) ? '' : $filmcrew['text']; } if ($filmcrew['type']['id'] == 127) { $film['world_sales'] = is_array($filmcrew['text']) ? '' : $filmcrew['text']; } if ($filmcrew['type']['id'] == 126) { $film['distributor'] = is_array($filmcrew['text']) ? '' : $filmcrew['text']; } if ($filmcrew['type']['id'] == 15) { $film['cast'] = is_array($filmcrew['text']) ? '' : $filmcrew['text']; } if ($filmcrew['type']['id'] == 5) { $film['operator'] = is_array($filmcrew['text']) ? '' : $filmcrew['text']; } } $id = $this->checkData($this->tableType, $film['eventival_id']); if (!$id) { $id = $this->createData($this->tableType, $film); } else { $this->updateData($this->tableType, $film, $id); } // Section == ProductGroup if (isset($filmArray['eventival_categorization']['sections']['section'])) { // Because eventival can't get their sections updated if (isset($filmArray['eventival_categorization']['sections']['section'][0])) { foreach ($filmArray['eventival_categorization']['sections']['section'] as $groupProduct) { $sectionId = $groupProduct['id']; $query = Doctrine_Query::create()->from('ProductGroup data')->select('data.id')->whereIn('data.eventival_id', $sectionId); $dbSection = $query->fetchOne(); if ($dbSection) { $dbSectionId = $dbSection->getId(); } if ($dbSectionId) { $query = Doctrine_Query::create()->from('ProductVsProductGroup')->select('group_id')->where('group_id = ? AND product_id = ?', array($dbSectionId, $id)); $check = $query->fetchOne(); if (!$check) { $fVs = array('group_id' => $dbSectionId, 'product_id' => $id); $filmVsSection = new ProductVsProductGroup(); $filmVsSection->fromArray($fVs); $filmVsSection->save(); } } } } else { $sectionId = $filmArray['eventival_categorization']['sections']['section']['id']; $query = Doctrine_Query::create()->from('ProductGroup data')->select('data.id')->whereIn('data.eventival_id', $sectionId); $dbSection = $query->fetchOne(); if ($dbSection) { $dbSectionId = $dbSection->getId(); } if ($dbSectionId) { $query = Doctrine_Query::create()->from('ProductVsProductGroup')->select('group_id')->where('group_id = ? AND product_id = ?', array($dbSectionId, $id)); $check = $query->fetchOne(); if (!$check) { $fVs = array('group_id' => $dbSectionId, 'product_id' => $id); $filmVsSection = new ProductVsProductGroup(); $filmVsSection->fromArray($fVs); $filmVsSection->save(); } } } } //echo $filmArray['titles']['title_original'] .' was added!<br />'; return $id; }
protected function execute($arguments = array(), $options = array()) { // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'])->getConnection(); if ($options['cinema']) { $request = new FetchAdXmlRequest(FetchAdXmlRequest::CINEMAS_URL); $xmlObj = $request->send(FetchAdXmlRequest::CINEMA); $xmlObj->mapCinemas(); } else { if ($options['section']) { $request = new FetchAdXmlRequest(FetchAdXmlRequest::SECTIONS_URL); $xmlObj = $request->send(FetchAdXmlRequest::SECTION); $xmlObj->mapSections(); } else { if ($options['film']) { $request = new FetchAdXmlRequest(FetchAdXmlRequest::FILMS_URL); $xmlObj = $request->send(FetchAdXmlRequest::FILM); $xmlObj->mapFilms(); $request = new FetchAdXmlRequest(FetchAdXmlRequest::FILMS_URL); $xmlObj = $request->send(FetchAdXmlRequest::FILM); $xmlObj->mapFilms(); } else { if ($options['package']) { $request = new FetchAdXmlRequest(FetchAdXmlRequest::PACKAGES_URL); $xmlObj = $request->send(FetchAdXmlRequest::PACKAGE); $xmlObj->mapPackages(); } else { if ($options['screening']) { $request = new FetchAdXmlRequest(FetchAdXmlRequest::SCREENINGS_URL); $xmlObj = $request->send(FetchAdXmlRequest::SCREENING); $xmlObj->mapScreenings(); } else { if ($options['all']) { $request = new FetchAdXmlRequest(FetchAdXmlRequest::CINEMAS_URL); $xmlObj = $request->send(FetchAdXmlRequest::CINEMA); $xmlObj->mapCinemas(); sleep(1); $request = new FetchAdXmlRequest(FetchAdXmlRequest::SECTIONS_URL); $xmlObj = $request->send(FetchAdXmlRequest::SECTION); $xmlObj->mapSections(); sleep(1); $request = new FetchAdXmlRequest(FetchAdXmlRequest::FILMS_URL); $xmlObj = $request->send(FetchAdXmlRequest::FILM); $xmlObj->mapFilms(); sleep(1); $request = new FetchAdXmlRequest(FetchAdXmlRequest::PACKAGES_URL); $xmlObj = $request->send(FetchAdXmlRequest::PACKAGE); $xmlObj->mapPackages(); sleep(1); $request = new FetchAdXmlRequest(FetchAdXmlRequest::SCREENINGS_URL); $xmlObj = $request->send(FetchAdXmlRequest::SCREENING); $xmlObj->mapScreenings(); } } } } } } echo 'Task succesfully completed'; }
public function mapScreenings() { //Info from piletilevi $request = new FetchAdXmlRequest(FetchAdXmlRequest::PILETILEVI_URL); $piletileviArray = $request->send()->getResponseArray(); foreach ($this->responseArray['screening'] as $index => $val) { // Getting DB ID for CinemaHall relations $hallId = $val['cinema_hall_id']; $query = Doctrine_Query::create()->from('CinemaHall data')->select('data.id')->where('data.eventival_id = ?', $hallId); $dbHall = $query->fetchOne(); if ($dbHall) { $dbHallId = $dbHall->getId(); } else { // $dbHallId = $this->mapCinemaHall($hallId); } $val['cinema_hall_id'] = $dbHallId; if (isset($val['film'])) { $filmId = $val['film']['id']; unset($val['film']); $args = array('film', $filmId); $query = $this->getProductQuery($args); $dbFilm = $query->fetchOne(); if ($dbFilm) { $dbFilmId = $dbFilm->getId(); //Hack for schelude Doctrine::getTable('Product')->find($dbFilmId)->setScheduled($val['start'])->save(); } else { $filmMapper = new FilmXMLMapper(); $dbFilmId = $filmMapper->mapFilm($filmId); Doctrine::getTable('Product')->find($dbFilmId)->setScheduled($val['start'])->save(); } $val['product_id'] = $dbFilmId; } else { if (isset($val['package'])) { $packageId = $val['package']['@attributes']['id']; unset($val['package']); $args = array('package', $packageId); $query = $this->getProductQuery($args); $dbPackage = $query->fetchOne(); if ($dbPackage) { $dbPackageId = $dbPackage->getId(); Doctrine::getTable('Product')->find($dbPackageId)->setScheduled($val['start'])->save(); } else { $packageMapper = new PackageXMLMapper(); $dbPackageId = $packageMapper->mapPackage($packageId); //Hack for schelude Doctrine::getTable('Product')->find($dbPackageId)->setScheduled($val['start'])->save(); } $val['product_id'] = $dbPackageId; } } $val['eventival_id'] = $val['id']; //From piletilevi foreach ($piletileviArray['concerts']['concert'] as $concert) { if (is_array($concert['title'])) { $code = null; } else { $code = substr($concert['title'], 0, strpos($concert['title'], " /")); } if ($val['code'] == $code) { $val['availability'] = $concert['status']; //TODO: Optimize check without notice error output if (@is_array($concert['deliveries']['zebra'])) { $val['web_sales'] = 1; } else { $val['web_sales'] = 0; } $val['piletilevi_id'] = $concert['id']; break; } } $val['start'] = strtotime($val['start']); $id = $this->checkData($this->tableType, $val['id']); unset($val['id']); unset($val['presentation']); unset($val['qa']); if (!$id) { $this->createData($this->tableType, $val); } else { $this->updateData($this->tableType, $val, $id); } } }