Ejemplo n.º 1
0
 public function importAttributes()
 {
     $count = $errors = 0;
     $hdl = $this->t1db->query("select * from declinaison order by classement");
     while ($hdl && ($declinaison = $this->t1db->fetch_object($hdl))) {
         $descs = $this->t1db->query_list("select * from declinaisondesc where declinaison = ? order by lang asc", array($declinaison->id));
         $idx = 0;
         $event = new AttributeCreateEvent();
         foreach ($descs as $desc) {
             try {
                 $lang = $this->getT2Lang($desc->lang);
                 if ($idx == 0) {
                     $event->setLocale($lang->getLocale())->setTitle($desc->titre);
                     $this->dispatcher->dispatch(TheliaEvents::ATTRIBUTE_CREATE, $event);
                     // Updater position
                     $update_position_event = new UpdatePositionEvent($event->getAttribute()->getId(), UpdatePositionEvent::POSITION_ABSOLUTE, $declinaison->classement);
                     $this->dispatcher->dispatch(TheliaEvents::ATTRIBUTE_UPDATE_POSITION, $update_position_event);
                     Tlog::getInstance()->info("Created attribute " . $event->getAttribute()->getId() . " from {$desc->titre} ({$declinaison->id})");
                     $this->attr_corresp->addEntry($declinaison->id, $event->getAttribute()->getId());
                 }
                 $update_event = new AttributeUpdateEvent($event->getAttribute()->getId());
                 $update_event->setLocale($lang->getLocale())->setTitle($desc->titre)->setChapo($desc->chapo)->setDescription($desc->description)->setPostscriptum('');
                 $this->dispatcher->dispatch(TheliaEvents::ATTRIBUTE_UPDATE, $update_event);
                 $idx++;
             } catch (\Exception $ex) {
                 Tlog::getInstance()->addError("Failed to create Attribute from {$desc->titre} ({$declinaison->id}): ", $ex->getMessage());
                 $errors++;
             }
             $count++;
         }
     }
     return new ImportChunkResult($count, $errors);
 }
Ejemplo n.º 2
0
 public function testCreateSimple()
 {
     $event = new AttributeCreateEvent();
     $event->setLocale('en_US')->setTitle('foo')->setDispatcher($this->getMock("Symfony\\Component\\EventDispatcher\\EventDispatcherInterface"));
     $action = new Attribute();
     $action->create($event);
     $createdAttribute = $event->getAttribute();
     $this->assertInstanceOf('Thelia\\Model\\Attribute', $createdAttribute);
     $this->assertEquals($createdAttribute->getLocale(), 'en_US');
     $this->assertEquals($createdAttribute->getTitle(), 'foo');
     return $createdAttribute;
 }
Ejemplo n.º 3
0
 public function testCreateSimple()
 {
     $event = new AttributeCreateEvent();
     $event->setLocale('en_US')->setTitle('foo');
     $action = new Attribute($this->getMockEventDispatcher());
     $action->create($event, null, $this->getMockEventDispatcher());
     $createdAttribute = $event->getAttribute();
     $this->assertInstanceOf('Thelia\\Model\\Attribute', $createdAttribute);
     $this->assertEquals($createdAttribute->getLocale(), 'en_US');
     $this->assertEquals($createdAttribute->getTitle(), 'foo');
     return $createdAttribute;
 }