public function add_items_to_batch() { if (!$this->token->validate('add_items_to_batch')) { $this->error->add($this->token->getErrorMessage()); } $exporters = \Core::make('migration/manager/exporters'); $r = $this->entityManager->getRepository('\\PortlandLabs\\Concrete5\\MigrationTool\\Entity\\Export\\Batch'); $batch = $r->findOneById($this->request->request->get('batch_id')); if (!is_object($batch)) { $this->error->add(t('Invalid batch.')); } $selectedItemType = false; if ($this->request->request->has('item_type') && $this->request->request->get('item_type')) { $selectedItemType = $exporters->driver($this->request->request->get('item_type')); } if (!is_object($selectedItemType)) { $this->error->add(t('Invalid item type.')); } if (!$this->error->has()) { $values = $this->request->request->get('id'); $exportItems = $selectedItemType->getItemsFromRequest($values[$selectedItemType->getHandle()]); $collection = $batch->getObjectCollection($selectedItemType->getHandle()); if (!is_object($collection)) { $collection = new ObjectCollection(); $collection->setType($selectedItemType->getHandle()); $batch->getObjectCollections()->add($collection); } foreach ($exportItems as $item) { if (!$collection->contains($item)) { $item->setCollection($collection); $collection->getItems()->add($item); } } $this->entityManager->persist($batch); $this->entityManager->flush(); $response = new JsonResponse($exportItems); return $response; } $r = new EditResponse(); $r->setError($this->error); $r->outputJSON(); }