/** * @param AjaxFileUploaderControl $control * @param FileUpload $file */ public function handleFileUpload(AjaxFileUploaderControl $control, $fileName) { /** @var FileEntity $fileEntity */ $fileEntity = $this->fileRepository->createNew(); $fileEntity->setFile(new \SplFileInfo($this->ajaxDir . '/' . $fileName)); $this->fileRepository->save($fileEntity); $this->categoryEntity->items[] = $photoEntity = new ItemEntity($this->categoryEntity->extendedPage); $photoEntity->route->setPhoto($fileEntity); $photoEntity->route->setParent($this->categoryEntity->route); $photoEntity->setCategory($this->categoryEntity); $this->itemRepository->save($photoEntity); }
public function handleSave(Form $form) { /** @var $entity CategoryEntity */ $entity = $form->data; $data = $form->getValues(); foreach ($data['_photos'] as $fileEntity) { if ($fileEntity) { $entity->items[] = $photoEntity = new ItemEntity($form->data->extendedPage); $photoEntity->route->setPhoto($fileEntity); $photoEntity->route->setParent($entity->route); $photoEntity->setCategory($entity); } } parent::handleSave($form); }
/** * Delete a Item * * @param ItemEntity the Item object */ public function delete(ItemEntity $item) { $sql = "delete from Item where Id = :id"; $stmt = $this->db->prepare($sql); $result = $stmt->execute(["id" => $item->getId()]); if (!$result) { throw new Exception("could not delete record"); } }