public function testCreate() { $attribute = AttributeQuery::create()->findOne(); $event = new AttributeAvCreateEvent(); $event->setAttributeId($attribute->getId())->setLocale('en_US')->setTitle('foo')->setDispatcher($this->getMock("Symfony\\Component\\EventDispatcher\\EventDispatcherInterface")); $action = new AttributeAv(); $action->create($event); $attributeAvCreated = $event->getAttributeAv(); $this->assertInstanceOf('Thelia\\Model\\AttributeAv', $attributeAvCreated); $this->assertEquals('en_US', $attributeAvCreated->getLocale()); $this->assertEquals('foo', $attributeAvCreated->getTitle()); $this->assertNull($attributeAvCreated->getDescription()); $this->assertNull($attributeAvCreated->getPostscriptum()); $this->assertNull($attributeAvCreated->getChapo()); $this->assertEquals($attribute, $attributeAvCreated->getAttribute()); return $attributeAvCreated; }
public function importAttributesAv() { $count = $errors = 0; $hdl = $this->t1db->query("select * from declidisp"); while ($hdl && ($declidisp = $this->t1db->fetch_object($hdl))) { $descs = $this->t1db->query_list("select * from declidispdesc where declidisp = ? order by lang asc", array($declidisp->id)); $idx = 0; $event = new AttributeAvCreateEvent(); foreach ($descs as $desc) { try { $lang = $this->getT2Lang($desc->lang); $attribute_id = $this->attr_corresp->getT2($declidisp->declinaison); if ($idx == 0) { $event->setAttributeId($attribute_id)->setLocale($lang->getLocale())->setTitle($desc->titre); $this->dispatcher->dispatch(TheliaEvents::ATTRIBUTE_AV_CREATE, $event); // Updater position $update_position_event = new UpdatePositionEvent($event->getAttributeAv()->getId(), UpdatePositionEvent::POSITION_ABSOLUTE, $desc->classement); $this->dispatcher->dispatch(TheliaEvents::ATTRIBUTE_AV_UPDATE_POSITION, $update_position_event); $this->attr_av_corresp->addEntry($declidisp->id, $event->getAttributeAv()->getId()); } $update_event = new AttributeAvUpdateEvent($event->getAttributeAv()->getId()); $update_event->setAttributeId($attribute_id)->setLocale($lang->getLocale())->setTitle($desc->titre)->setChapo('')->setDescription('')->setPostscriptum(''); $this->dispatcher->dispatch(TheliaEvents::ATTRIBUTE_AV_UPDATE, $update_event); $idx++; } catch (\Exception $ex) { Tlog::getInstance()->addError(Translator::getInstance()->trans("Failed to create Attribute Av: %ex", array("%ex" => $ex->getMessage())), [], ImportT1::DOMAIN); $errors++; } $count++; } } return new ImportChunkResult($count, $errors); }
/** * Create a new attribute entry * * @param AttributeAvCreateEvent $event */ public function create(AttributeAvCreateEvent $event) { $attribute = new AttributeAvModel(); $attribute->setDispatcher($event->getDispatcher())->setAttributeId($event->getAttributeId())->setLocale($event->getLocale())->setTitle($event->getTitle())->save(); $event->setAttributeAv($attribute); }
protected function getCreationEvent($formData) { $createEvent = new AttributeAvCreateEvent(); $createEvent->setAttributeId($formData['attribute_id'])->setTitle($formData['title'])->setLocale($formData["locale"]); return $createEvent; }
/** * Create a new attribute entry * * @param AttributeAvCreateEvent $event * @param $eventName * @param EventDispatcherInterface $dispatcher */ public function create(AttributeAvCreateEvent $event, $eventName, EventDispatcherInterface $dispatcher) { $attribute = new AttributeAvModel(); $attribute->setDispatcher($dispatcher)->setAttributeId($event->getAttributeId())->setLocale($event->getLocale())->setTitle($event->getTitle())->save(); $event->setAttributeAv($attribute); }