Пример #1
0
 public function executeCopyProduct($request)
 {
     $product = $this->getRoute()->getObject();
     # copy product main information
     $newProduct = $product->copy();
     $newProduct['code'] = $product['code'] . '_new_' . rand(1, 100000);
     ## copy product Translations
     $transArr = $product->Translation->toArray();
     foreach ($transArr as $index => &$transVal) {
         unset($transVal['id']);
     }
     $newProduct->Translation->fromArray($transArr);
     $newProduct->save();
     # copy product connections with ProductGroups
     foreach ($product->ProductGroups as $prodGroup) {
         $rel = new ProductVsProductGroup();
         $rel['group_id'] = $prodGroup['group_id'];
         $rel['product_id'] = $newProduct['id'];
         $rel->save();
     }
     # copy product connections with ParameterProductOptions
     foreach ($product->ParameterProductOptions as $prodGroup) {
         $rel = new ParameterProductOption();
         $rel['option_id'] = $prodGroup['option_id'];
         $rel['product_id'] = $newProduct['id'];
         $rel->save();
     }
     # copy product connections with ParameterProductValues and their Translations
     foreach ($product->ParameterProductValues as $prodValue) {
         $rel = new ParameterProductValue();
         $arr = $prodValue->toArray();
         $arr['Translation'] = $prodValue->Translation->toArray();
         foreach ($arr['Translation'] as $lang => &$transArr) {
             unset($transArr['id']);
         }
         unset($arr['id']);
         $rel->fromArray($arr);
         $rel['product_id'] = $newProduct['id'];
         $rel->save();
     }
     $this->redirect(array('sf_route' => $this->helper->getEditRoute(), 'sf_subject' => $newProduct));
 }
Пример #2
0
 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;
 }
Пример #3
0
 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;
     }
 }
Пример #4
0
 public function updateProductGroupConnections($connections)
 {
     $this->deleteProductGroupConnections();
     foreach ($connections as $conn) {
         $rel = new ProductVsProductGroup();
         $rel->fromArray(array('group_id' => $conn, 'product_id' => $this->getId()));
         $rel->save();
     }
     $this->save();
 }