protected function migrateItem($item)
 {
     if (!isset($item['configuration'])) {
         return;
     }
     $configuration = unserialize($item['configuration']);
     if (empty($item['content_id'])) {
         return;
     }
     if (!$configuration instanceof Configuration) {
         throw new Exception('can\'t convert to Configuration');
     }
     switch ($configuration->getType()) {
         case 'text':
             $itemType = $this->migrateText($item, $configuration->getData());
             break;
         case 'picturepicture':
             $itemType = $this->migratePicturePicture($item, $configuration->getData());
             break;
         case 'picture':
             $itemType = $this->migratePicture($item, $configuration->getData());
             break;
         case 'textpicture':
             $itemType = $this->migrateTextPicture($item, $configuration->getData());
             break;
         case 'video':
             $itemType = $this->migrateVideo($item, $configuration->getData());
             break;
         default:
             throw new Exception(sprintf('unknown type [%s]', $configuration->getType()));
     }
     $grid = $this->getGrid($item);
     $gridItem = new Item();
     $gridItem->setGrid($grid);
     $gridItem->setOrder($item['order']);
     $gridItem->setItemType($itemType);
     $this->getManager()->persist($gridItem);
     $this->getManager()->flush();
 }
Example #2
0
 /**
  * @param Grid|null $originalResource
  * @return Grid
  */
 public function duplicate($originalResource)
 {
     if (!$originalResource) {
         return null;
     }
     /** @var Grid $newGrid */
     $newGrid = $this->createNew();
     /** @var Item $item */
     foreach ($originalResource->getItems() as $item) {
         $newItemType = $this->itemTypeFactory->duplicate($item->getItemType());
         $newItem = new Item();
         $newItem->setOrder($item->getOrder());
         $newItem->setConfiguration($item->getConfiguration());
         $newItem->setType($item->getType());
         $newItem->setItemType($newItemType);
         $newGrid->addItem($newItem);
     }
     return $newGrid;
 }
Example #3
0
 /**
  * @param $grid
  * @return Grid
  */
 protected function createGrid($grid)
 {
     $gridEntity = new Grid();
     foreach ($grid as $fields) {
         $itemEntity = new Item();
         $type = $fields['type'];
         unset($fields['type']);
         $itemEntity->setItemType($this->createItemType($type, $fields));
         $gridEntity->addItem($itemEntity);
     }
     return $gridEntity;
 }