function bindFileEntityArray($fileEntitys) { $fileDtos = new FileListDto(); $fileDtoArray = array(); foreach ($fileEntitys as $fileEntity => $value) { array_push($fileDtoArray, bindFileEntity($value)); } $fileDtos->setFiles($fileDtoArray); return $fileDtos; }
function bindImageEntity($imageEntity) { if ($imageEntity != null) { $imageDto = new ImageDto(); $imageDto->setImageId($imageEntity->getImageId()); $imageDto->setFile(bindFileEntity($imageEntity->getFile())); $imageDto->setWidth($imageEntity->getWidth()); $imageDto->setHeight($imageEntity->getHeight()); return $imageDto; } else { return null; } }
function bindPrescriptionEntity($prescriptionEntity) { if ($prescriptionEntity != null) { $prescriptionDto = new PrescriptionDto(); $prescriptionDto->setPrescriptionId($prescriptionEntity->getPrescriptionId()); $prescriptionDto->setAppointment(bindAppointmentEntity($prescriptionEntity->getAppointment())); $prescriptionDto->setDoctor(bindDoctorEntity($prescriptionEntity->getDoctor())); $prescriptionDto->setUser(bindUserEntity($prescriptionEntity->getUser())); $prescriptionDto->setFile(bindFileEntity($prescriptionEntity->getFile())); $prescriptionDto->setEffFrm($prescriptionEntity->getEffFrm()); $prescriptionDto->setEffTo($prescriptionEntity->getEffTo()); return $prescriptionDto; } else { return null; } }
$filesArray = array(); foreach ($fileListDto->getFiles() as $fileDto) { $fileEntity = bindFileDto($fileDto); $entityManager->persist($fileEntity); $entityManager->flush(); array_push($filesArray, bindFileEntity($fileEntity)); } $fileListDto = new FileListDto(); $fileListDto->setFiles($filesArray); $fileListDto->printData($app); }); $app->put('/files/:id', function ($id) use($app) { global $entityManager; $fileEntity = $entityManager->find("FileEntity", $id); $entityManager->flush(); $fileDto = bindFileEntity($fileEntity); $fileDto->printData($app); }); $app->delete('/files/:id', function ($id) use($app) { global $entityManager; $fileEntity = $entityManager->find("FileEntity", $id); $entityManager->remove($fileEntity); $entityManager->flush(); }); /*Referances*/ $app->get('/files/:id/images/files', function ($id) use($app) { global $entityManager; $imageEntities = $entityManager->getRepository("ImageEntity")->findBy(array('file' => $id)); $image = bindImageEntityArray($imageEntities); $image->printData($app); });