Example #1
0
 public function importFeatures()
 {
     $count = $errors = 0;
     $hdl = $this->t1db->query("select * from caracteristique order by classement");
     while ($hdl && ($caracteristique = $this->t1db->fetch_object($hdl))) {
         $descs = $this->t1db->query_list("select * from caracteristiquedesc where caracteristique = ? order by lang asc", array($caracteristique->id));
         $idx = 0;
         $event = new FeatureCreateEvent();
         foreach ($descs as $desc) {
             try {
                 $lang = $this->getT2Lang($desc->lang);
                 if ($idx == 0) {
                     $event->setLocale($lang->getLocale())->setTitle($desc->titre);
                     $this->dispatcher->dispatch(TheliaEvents::FEATURE_CREATE, $event);
                     // Updater position
                     $update_position_event = new UpdatePositionEvent($event->getFeature()->getId(), UpdatePositionEvent::POSITION_ABSOLUTE, $caracteristique->classement);
                     $this->dispatcher->dispatch(TheliaEvents::FEATURE_UPDATE_POSITION, $update_position_event);
                     Tlog::getInstance()->info("Created feature " . $event->getFeature()->getId() . " from {$desc->titre} ({$caracteristique->id})");
                     $this->feat_corresp->addEntry($caracteristique->id, $event->getFeature()->getId());
                 }
                 $update_event = new FeatureUpdateEvent($event->getFeature()->getId());
                 $update_event->setLocale($lang->getLocale())->setTitle($desc->titre)->setChapo($desc->chapo)->setDescription($desc->description)->setPostscriptum('');
                 $this->dispatcher->dispatch(TheliaEvents::FEATURE_UPDATE, $update_event);
                 $idx++;
             } catch (ImportException $ex) {
                 Tlog::getInstance()->addError("Failed to create Feature from {$desc->titre} ({$caracteristique->id}): ", $ex->getMessage());
                 $errors++;
             }
         }
         $count++;
     }
     return new ImportChunkResult($count, $errors);
 }
Example #2
0
 /**
  * Create a new feature entry
  *
  * @param \Thelia\Core\Event\Feature\FeatureCreateEvent $event
  * @param $eventName
  * @param EventDispatcherInterface $dispatcher
  */
 public function create(FeatureCreateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
 {
     $feature = new FeatureModel();
     $feature->setDispatcher($dispatcher)->setLocale($event->getLocale())->setTitle($event->getTitle())->save();
     $event->setFeature($feature);
     // Add atribute to all product templates if required
     if ($event->getAddToAllTemplates() != 0) {
         $this->doAddToAllTemplates($feature);
     }
 }
Example #3
0
 public function testCreate()
 {
     $event = new FeatureCreateEvent();
     $event->setLocale('en_US')->setTitle('test feature')->setDispatcher($this->dispatcher);
     $action = new Feature();
     $action->create($event);
     $createdFeature = $event->getFeature();
     $this->assertInstanceOf('Thelia\\Model\\Feature', $createdFeature);
     $this->assertFalse($createdFeature->isNew());
     $this->assertEquals("en_US", $createdFeature->getLocale());
     $this->assertEquals("test feature", $createdFeature->getTitle());
     return $createdFeature;
 }
 protected function getCreationEvent($formData)
 {
     $createEvent = new FeatureCreateEvent();
     $createEvent->setTitle($formData['title'])->setLocale($formData["locale"])->setAddToAllTemplates($formData['add_to_all']);
     return $createEvent;
 }