function bindNewsEntity($newsEntity) { if ($newsEntity != null) { $newsDto = new NewsDto(); $newsDto->setNewsId($newsEntity->getNewsId()); $newsDto->setNewsHeading($newsEntity->getNewsHeading()); $newsDto->setDataContent(bindDataContentEntity($newsEntity->getDataContent())); $newsDto->setNewsDate($newsEntity->getNewsDate()); return $newsDto; } else { return null; } }
$newsListDto = new NewsListDto(); $newsListDto = $newsListDto->bindXml($app); foreach ($newsListDto->getNewss() as $newsDto) { $newsEntity = bindNewsDto($newsDto); $entityManager->persist($newsEntity); $entityManager->flush(); } }); $app->put('/newss/:id', function ($id) use($app) { global $entityManager; $newsEntity = $entityManager->find("NewsEntity", $id); $entityManager->flush(); $newsDto = bindNewsEntity($newsEntity); $newsDto->printData($app); }); $app->post('/newss', function () use($app) { global $entityManager; $newsDto = new NewsDto(); $newsDto->bindJson($app); $entityManager->persist($newsEntity); $entityManager->flush(); $newsDto = bindNewsEntity($newsEntity); $newsDto->printData($app); }); $app->delete('/newss/:id', function ($id) use($app) { global $entityManager; $newsEntity = $entityManager->find("NewsEntity", $id); $entityManager->remove($newsEntity); $entityManager->flush(); }); /*Referances*/