Esempio n. 1
0
 protected function getUpdateEvent($formData)
 {
     $changeEvent = new AttributeAvUpdateEvent($formData['id']);
     // Create and dispatch the change event
     $changeEvent->setLocale($formData["locale"])->setTitle($formData['title'])->setChapo($formData['chapo'])->setDescription($formData['description'])->setPostscriptum($formData['postscriptum']);
     return $changeEvent;
 }
Esempio n. 2
0
 /**
  * Change a product attribute
  *
  * @param \Thelia\Core\Event\Attribute\AttributeAvUpdateEvent $event
  */
 public function update(AttributeAvUpdateEvent $event)
 {
     if (null !== ($attribute = AttributeAvQuery::create()->findPk($event->getAttributeAvId()))) {
         $attribute->setDispatcher($event->getDispatcher())->setLocale($event->getLocale())->setTitle($event->getTitle())->setDescription($event->getDescription())->setChapo($event->getChapo())->setPostscriptum($event->getPostscriptum())->save();
         $event->setAttributeAv($attribute);
     }
 }
Esempio n. 3
0
 /**
  * Process the attributes values (fix it in future version to integrate it in the attribute form as a collection)
  *
  * @see \Thelia\Controller\Admin\AbstractCrudController::performAdditionalUpdateAction()
  */
 protected function performAdditionalUpdateAction($updateEvent)
 {
     $attr_values = $this->getRequest()->get('attribute_values', null);
     if ($attr_values !== null) {
         foreach ($attr_values as $id => $value) {
             $event = new AttributeAvUpdateEvent($id);
             $event->setTitle($value);
             $event->setLocale($this->getCurrentEditionLocale());
             $this->dispatch(TheliaEvents::ATTRIBUTE_AV_UPDATE, $event);
         }
     }
     return null;
 }
Esempio n. 4
0
 /**
  * @param AttributeAvModel $attributeAv
  * @depends testCreate
  */
 public function testUpdate(AttributeAvModel $attributeAv)
 {
     $event = new AttributeAvUpdateEvent($attributeAv->getId());
     $event->setLocale($attributeAv->getLocale())->setTitle('bar')->setDescription('bar description')->setChapo('bar chapo')->setPostscriptum('bar postscriptum')->setDispatcher($this->getMock("Symfony\\Component\\EventDispatcher\\EventDispatcherInterface"));
     $action = new AttributeAv();
     $action->update($event);
     $updatedAttributeAv = $event->getAttributeAv();
     $this->assertInstanceOf('Thelia\\Model\\AttributeAv', $updatedAttributeAv);
     $this->assertEquals('bar', $updatedAttributeAv->getTitle());
     $this->assertEquals('bar description', $updatedAttributeAv->getDescription());
     $this->assertEquals('bar chapo', $updatedAttributeAv->getChapo());
     $this->assertEquals('bar postscriptum', $updatedAttributeAv->getPostscriptum());
     return $updatedAttributeAv;
 }
Esempio n. 5
0
 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);
 }