コード例 #1
0
 protected function getUpdateEvent($formData)
 {
     $changeEvent = new CategoryUpdateEvent($formData['id']);
     // Create and dispatch the change event
     $changeEvent->setLocale($formData['locale'])->setTitle($formData['title'])->setChapo($formData['chapo'])->setDescription($formData['description'])->setPostscriptum($formData['postscriptum'])->setVisible($formData['visible'])->setParent($formData['parent']);
     return $changeEvent;
 }
コード例 #2
0
ファイル: CategoryTest.php プロジェクト: badelas/thelia
 /**
  * @param CategoryModel $category
  * @depends testCreate
  */
 public function testUpdate(CategoryModel $category)
 {
     $event = new CategoryUpdateEvent($category->getId());
     $event->setLocale('en_US')->setTitle('bar')->setDescription('bar description')->setChapo('bar chapo')->setPostscriptum('bar postscriptum')->setVisible(0)->setParent(0)->setDispatcher($this->getDispatcher());
     $action = new Category();
     $action->update($event);
     $updatedCategory = $event->getCategory();
     $this->assertInstanceOf('Thelia\\Model\\Category', $updatedCategory);
     $this->assertEquals('en_US', $updatedCategory->getLocale());
     $this->assertEquals('bar', $updatedCategory->getTitle());
     $this->assertEquals('bar description', $updatedCategory->getDescription());
     $this->assertEquals('bar chapo', $updatedCategory->getChapo());
     $this->assertEquals('bar postscriptum', $updatedCategory->getPostscriptum());
     $this->assertEquals(0, $updatedCategory->getVisible());
     $this->assertEquals(0, $updatedCategory->getParent());
     return $updatedCategory;
 }
コード例 #3
0
 /**
  * @param CategoryModel $category
  * @depends testCreate
  * @return CategoryModel
  */
 public function testUpdate(CategoryModel $category)
 {
     $template = new Template();
     $template->setName('A sample template')->save();
     $event = new CategoryUpdateEvent($category->getId());
     $event->setLocale('en_US')->setTitle('bar')->setDescription('bar description')->setChapo('bar chapo')->setPostscriptum('bar postscriptum')->setVisible(0)->setParent(0)->setDefaultTemplateId($template->getId());
     $action = new Category();
     $action->update($event, null, $this->getMockEventDispatcher());
     $updatedCategory = $event->getCategory();
     $this->assertInstanceOf('Thelia\\Model\\Category', $updatedCategory);
     $this->assertEquals('en_US', $updatedCategory->getLocale());
     $this->assertEquals('bar', $updatedCategory->getTitle());
     $this->assertEquals('bar description', $updatedCategory->getDescription());
     $this->assertEquals('bar chapo', $updatedCategory->getChapo());
     $this->assertEquals('bar postscriptum', $updatedCategory->getPostscriptum());
     $this->assertEquals(0, $updatedCategory->getVisible());
     $this->assertEquals($template->getId(), $updatedCategory->getDefaultTemplateId());
     $this->assertEquals(0, $updatedCategory->getParent());
     return [$updatedCategory, $template];
 }
コード例 #4
0
ファイル: CategoryController.php プロジェクト: margery/thelia
 /**
  * @param CategoryUpdateEvent $updateEvent
  * @return null|\Symfony\Component\HttpFoundation\Response
  */
 protected function performAdditionalUpdateAction($updateEvent)
 {
     $response = null;
     if ($this->getRequest()->get('save_mode') != 'stay') {
         // Redirect to parent category list
         $category_id = $updateEvent->getCategory()->getParent();
         $response = $this->redirectToListTemplateWithId($category_id);
     }
     return $response;
 }
コード例 #5
0
ファイル: CategoriesImport.php プロジェクト: JumBay/ImportT1
 public function import($startRecord = 0)
 {
     $count = 0;
     $errors = 0;
     $hdl = $this->t1db->query(sprintf("select * from rubrique order by parent asc limit %d, %d", intval($startRecord), $this->getChunkSize()));
     /*
             $hdl = $this->t1db
                 ->query(
                     sprintf(
                         "select * from rubrique order by parent asc limit %d, %d",
                         intval($startRecord),
                         $this->getChunkSize()
                     )
                 );
     */
     $image_import = new CategoryImageImport($this->dispatcher, $this->t1db);
     $document_import = new CategoryDocumentImport($this->dispatcher, $this->t1db);
     while ($hdl && ($rubrique = $this->t1db->fetch_object($hdl))) {
         echo "r={$rubrique->id}";
         $count++;
         try {
             $this->cat_corresp->getT2($rubrique->id);
             Tlog::getInstance()->warning("Category ID={$rubrique->id} already imported.");
             continue;
         } catch (ImportException $ex) {
             // Okay, the category was not imported.
         }
         try {
             $event = new CategoryCreateEvent();
             $idx = 0;
             $descs = $this->t1db->query_list("select * from rubriquedesc where rubrique = ? order by lang asc", array($rubrique->id));
             foreach ($descs as $objdesc) {
                 $lang = $this->getT2Lang($objdesc->lang);
                 // A title is required to create the rewritten URL
                 if (empty($objdesc->titre)) {
                     $objdesc->titre = sprintf("Untitled-%d-%s", $objdesc->id, $lang->getCode());
                 }
                 $parent = $rubrique->parent > 0 ? $rubrique->parent + 1000000 : 0;
                 if ($idx == 0) {
                     $event->setLocale($lang->getLocale())->setTitle($objdesc->titre)->setParent($parent)->setVisible($rubrique->ligne == 1 ? true : false);
                     $this->dispatcher->dispatch(TheliaEvents::CATEGORY_CREATE, $event);
                     $category_id = $event->getCategory()->getId();
                     // Update position
                     // ---------------
                     $update_position_event = new UpdatePositionEvent($category_id, UpdatePositionEvent::POSITION_ABSOLUTE, $rubrique->classement);
                     $this->dispatcher->dispatch(TheliaEvents::CATEGORY_UPDATE_POSITION, $update_position_event);
                     Tlog::getInstance()->info("Created category {$category_id} from {$objdesc->titre} ({$rubrique->id})");
                     $this->cat_corresp->addEntry($rubrique->id, $category_id);
                     // Create a product template if this categorie has declinaisons and/or caracteristiques
                     // ------------------------------------------------------------------------------------
                     $tpl_update = null;
                     $feature_list = $this->t1db->query_list("select caracteristique from rubcaracteristique where rubrique={$rubrique->id}");
                     $attribute_list = $this->t1db->query_list("select declinaison from rubdeclinaison where rubrique={$rubrique->id}");
                     if (!empty($attribute_list) || !empty($feature_list)) {
                         $tpl_create = new TemplateCreateEvent();
                         $tpl_create->setLocale($lang->getLocale())->setTemplateName($objdesc->titre . " (generated by import)");
                         $this->dispatcher->dispatch(TheliaEvents::TEMPLATE_CREATE, $tpl_create);
                         $tpl_id = $tpl_create->getTemplate()->getId();
                         $tpl_update = new TemplateUpdateEvent($tpl_id);
                         foreach ($attribute_list as $attr) {
                             try {
                                 $attribute_template = new AttributeTemplate();
                                 $id = $this->attr_corresp->getT2($attr->declinaison);
                                 $attribute_template->setAttributeId($id)->setTemplateId($tpl_id)->save();
                             } catch (\Exception $ex) {
                                 Tlog::getInstance()->addError("Failed to create template attribute for T1 caractéristique {$attr->declinaison} : ", $ex->getMessage());
                                 $errors++;
                             }
                         }
                         foreach ($feature_list as $feat) {
                             try {
                                 $feature_template = new FeatureTemplate();
                                 $id = $this->feat_corresp->getT2($feat->caracteristique);
                                 $feature_template->setFeatureId($id)->setTemplateId($tpl_id)->save();
                             } catch (\Exception $ex) {
                                 Tlog::getInstance()->addError("Failed to create template feature for T1 declinaison {$feat->caracteristique} : ", $ex->getMessage());
                                 $errors++;
                             }
                         }
                         $this->tpl_corresp->addEntry($rubrique->id, $tpl_id);
                     }
                     // Import related content
                     // ----------------------
                     $contents = $this->t1db->query_list("select * from contenuassoc where objet=? and type=0 order by classement", array($rubrique->id));
                     // type: 1 = produit, 0=rubrique
                     foreach ($contents as $content) {
                         try {
                             $content_event = new CategoryAddContentEvent($event->getCategory(), $this->content_corresp->getT2($content->contenu));
                             $this->dispatcher->dispatch(TheliaEvents::CATEGORY_ADD_CONTENT, $content_event);
                         } catch (\Exception $ex) {
                             Tlog::getInstance()->addError("Failed to create associated content {$content->contenu} for category {$category_id}: ", $ex->getMessage());
                             $errors++;
                         }
                     }
                     // Import images and documents
                     // ---------------------------
                     $image_import->importMedia($rubrique->id, $category_id);
                     $document_import->importMedia($rubrique->id, $category_id);
                 }
                 // Update the newly created category
                 $update_event = new CategoryUpdateEvent($category_id);
                 $update_event->setTitle($objdesc->titre)->setParent($parent)->setLocale($lang->getLocale())->setVisible($rubrique->ligne == 1 ? true : false)->setChapo($objdesc->chapo)->setDescription($objdesc->description)->setPostscriptum($objdesc->postscriptum);
                 $this->dispatcher->dispatch(TheliaEvents::CATEGORY_UPDATE, $update_event);
                 // Create a product template name in this language
                 // -----------------------------------------------
                 if ($tpl_update !== null) {
                     $tpl_update->setLocale($lang->getLocale())->setTemplateName($objdesc->titre . " (generated by import)");
                     $this->dispatcher->dispatch(TheliaEvents::TEMPLATE_UPDATE, $tpl_update);
                 }
                 // Update the rewritten URL
                 $this->updateRewrittenUrl($event->getCategory(), $lang->getLocale(), $objdesc->lang, "rubrique", "%id_rubrique={$rubrique->id}");
                 $idx++;
             }
         } catch (\Exception $ex) {
             Tlog::getInstance()->addError("Failed to import category ID={$rubrique->id}: ", $ex->getMessage());
             $errors++;
         }
     }
     return new ImportChunkResult($count, $errors);
 }
コード例 #6
0
ファイル: Category.php プロジェクト: badelas/thelia
 /**
  * Change a category
  *
  * @param \Thelia\Core\Event\Category\CategoryUpdateEvent $event
  */
 public function update(CategoryUpdateEvent $event)
 {
     if (null !== ($category = CategoryQuery::create()->findPk($event->getCategoryId()))) {
         $category->setDispatcher($event->getDispatcher())->setLocale($event->getLocale())->setTitle($event->getTitle())->setDescription($event->getDescription())->setChapo($event->getChapo())->setPostscriptum($event->getPostscriptum())->setParent($event->getParent())->setVisible($event->getVisible())->save();
         $event->setCategory($category);
     }
 }
コード例 #7
0
ファイル: CategoryController.php プロジェクト: badelas/thelia
 /**
  * @param array $data
  * @return \Symfony\Component\EventDispatcher\Event
  */
 protected function getUpdateEvent(array &$data)
 {
     $event = new CategoryUpdateEvent($data["id"]);
     $event->setLocale($data['locale'])->setParent($data['parent'])->setTitle($data['title'])->setVisible($data['visible'])->setChapo($data['chapo'])->setDescription($data['description'])->setPostscriptum($data['postscriptum']);
     $this->setLocaleIntoQuery($data["locale"]);
     return $event;
 }
コード例 #8
0
ファイル: Category.php プロジェクト: vigourouxjulien/thelia
 /**
  * Change a category
  *
  * @param \Thelia\Core\Event\Category\CategoryUpdateEvent $event
  * @param $eventName
  * @param EventDispatcherInterface $dispatcher
  */
 public function update(CategoryUpdateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
 {
     if (null !== ($category = CategoryQuery::create()->findPk($event->getCategoryId()))) {
         $category->setDispatcher($dispatcher)->setDefaultTemplateId($event->getDefaultTemplateId() == 0 ? null : $event->getDefaultTemplateId())->setLocale($event->getLocale())->setTitle($event->getTitle())->setDescription($event->getDescription())->setChapo($event->getChapo())->setPostscriptum($event->getPostscriptum())->setParent($event->getParent())->setVisible($event->getVisible())->save();
         $event->setCategory($category);
     }
 }