Example #1
0
 /**
  * Changes object position, selecting absolute ou relative change.
  *
  * @param ModelCriteria       $query
  * @param UpdatePositionEvent $event
  *
  * @return null
  */
 protected function genericUpdatePosition(ModelCriteria $query, UpdatePositionEvent $event)
 {
     if (null !== ($object = $query->findPk($event->getObjectId()))) {
         $object->setDispatcher($event->getDispatcher());
         $mode = $event->getMode();
         if ($mode == UpdatePositionEvent::POSITION_ABSOLUTE) {
             $object->changeAbsolutePosition($event->getPosition());
         } elseif ($mode == UpdatePositionEvent::POSITION_UP) {
             $object->movePositionUp();
         } elseif ($mode == UpdatePositionEvent::POSITION_DOWN) {
             $object->movePositionDown();
         }
     }
 }
Example #2
0
 /**
  * Changes object position, selecting absolute ou relative change.
  *
  * @param ModelCriteria       $query
  * @param UpdatePositionEvent $event
  * @param EventDispatcherInterface $dispatcher
  *
  * @return null
  */
 protected function genericUpdatePosition(ModelCriteria $query, UpdatePositionEvent $event, EventDispatcherInterface $dispatcher = null)
 {
     if (null !== ($object = $query->findPk($event->getObjectId()))) {
         //for backward compatibility
         $object->setDispatcher($dispatcher !== null ? $dispatcher : $event->getDispatcher());
         $mode = $event->getMode();
         if ($mode == UpdatePositionEvent::POSITION_ABSOLUTE) {
             $object->changeAbsolutePosition($event->getPosition());
         } elseif ($mode == UpdatePositionEvent::POSITION_UP) {
             $object->movePositionUp();
         } elseif ($mode == UpdatePositionEvent::POSITION_DOWN) {
             $object->movePositionDown();
         }
     }
 }
Example #3
0
 public function updatePosition(UpdatePositionEvent $event)
 {
     if (null !== ($folder = FolderQuery::create()->findPk($event->getObjectId()))) {
         $folder->setDispatcher($event->getDispatcher());
         switch ($event->getMode()) {
             case UpdatePositionEvent::POSITION_ABSOLUTE:
                 $folder->changeAbsolutePosition($event->getPosition());
                 break;
             case UpdatePositionEvent::POSITION_DOWN:
                 $folder->movePositionDown();
                 break;
             case UpdatePositionEvent::POSITION_UP:
                 $folder->movePositionUp();
                 break;
         }
     }
 }
Example #4
0
 /**
  * @param ModelCriteria $query
  * @param UpdatePositionEvent $event
  * @param EventDispatcherInterface|null $dispatcher
  *
  * @since 2.3
  */
 protected function genericUpdateDelegatePosition(ModelCriteria $query, UpdatePositionEvent $event, EventDispatcherInterface $dispatcher = null)
 {
     if (null !== ($object = $query->findOne())) {
         if (!isset(class_uses($object)['Thelia\\Model\\Tools\\PositionManagementTrait'])) {
             throw new \InvalidArgumentException("Your model does not implement the PositionManagementTrait trait");
         }
         //$object->setDispatcher($dispatcher !== null ? $dispatcher : $event->getDispatcher());
         $mode = $event->getMode();
         if ($mode == UpdatePositionEvent::POSITION_ABSOLUTE) {
             $object->changeAbsolutePosition($event->getPosition());
         } elseif ($mode == UpdatePositionEvent::POSITION_UP) {
             $object->movePositionUp();
         } elseif ($mode == UpdatePositionEvent::POSITION_DOWN) {
             $object->movePositionDown();
         }
     }
 }
Example #5
0
 public function testUpdatePositionWithSpecificPosition()
 {
     $content = ContentQuery::create()->filterByFolder($this->getFolderForPositionTest())->filterByPosition(1, Criteria::GREATER_THAN)->findOne();
     if (null === $content) {
         $this->fail('use fixtures before launching test, there is no content in database');
     }
     $event = new UpdatePositionEvent($content->getId(), UpdatePositionEvent::POSITION_ABSOLUTE, 1);
     $event->setDispatcher($this->dispatcher);
     $contentAction = new Content($this->getContainer());
     $contentAction->updatePosition($event);
     $updatedContent = ContentQuery::create()->findPk($content->getId());
     $this->assertEquals(1, $updatedContent->getPosition(), sprintf("new position is 1, new position expected is %d for content %d", $updatedContent->getPosition(), $updatedContent->getId()));
 }
Example #6
0
 /**
  * Handle import category change position event
  *
  * @param \Thelia\Core\Event\UpdatePositionEvent $updatePositionEvent
  */
 public function importCategoryChangePosition(UpdatePositionEvent $updatePositionEvent)
 {
     $this->handler->getCategory($updatePositionEvent->getObjectId(), true);
     $this->genericUpdatePosition(new ImportCategoryQuery(), $updatePositionEvent);
 }
Example #7
0
 /**
  * @param UpdatePositionEvent $event
  * @return null|\Symfony\Component\HttpFoundation\Response
  */
 protected function performAdditionalUpdatePositionAction($event)
 {
     $category = CategoryQuery::create()->findPk($event->getObjectId());
     $response = null;
     if ($category != null) {
         // Redirect to parent category list
         $category_id = $category->getParent();
         $response = $this->redirectToListTemplateWithId($category_id);
     }
     return $response;
 }
Example #8
0
 public function testUpdatePositionWithSpecificPosition()
 {
     $this->resetBrandPosition();
     $brand = BrandQuery::create()->filterByPosition(1, Criteria::GREATER_THAN)->findOne();
     if (null === $brand) {
         $this->fail('use fixtures before launching test, there is no brand in database');
     }
     $event = new UpdatePositionEvent($brand->getId(), UpdatePositionEvent::POSITION_ABSOLUTE, 1);
     $event->setDispatcher($this->dispatcher);
     $brandAction = new Brand($this->getContainer());
     $brandAction->updatePosition($event);
     $updatedBrand = BrandQuery::create()->findPk($brand->getId());
     $this->assertEquals(1, $updatedBrand->getPosition(), sprintf("new position is 1, new position expected is %d for brand %d", $updatedBrand->getPosition(), $updatedBrand->getId()));
 }
Example #9
0
 /**
  * Handle import category change position event
  *
  * @param UpdatePositionEvent $updatePositionEvent
  * @param $eventName
  * @param EventDispatcherInterface $dispatcher
  */
 public function importCategoryChangePosition(UpdatePositionEvent $updatePositionEvent, $eventName, EventDispatcherInterface $dispatcher)
 {
     $this->handler->getCategory($updatePositionEvent->getObjectId(), true);
     $this->genericUpdatePosition(new ImportCategoryQuery(), $updatePositionEvent, $dispatcher);
 }
 /**
  * @param ModelCriteria $query
  * @param               $object_id
  * @param null          $mode
  * @param null          $position
  */
 public function __construct(ModelCriteria $query, $object_id, $mode, $position = null)
 {
     parent::__construct($object_id, $mode, $position);
     $this->setQuery($query);
 }