Skip to content

Commit

Permalink
fixed edit action
Browse files Browse the repository at this point in the history
  • Loading branch information
Fafnur committed Mar 31, 2016
1 parent ac6a245 commit 0084106
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions Controller/ContentBlockController.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function createAction($name)
{
$em = $this->getDoctrine()->getManager();
$repository = $em->getRepository('GlavwebContentBlockBundle:ContentBlock');
$contentBlock = $repository->findByName($name);
$contentBlock = $repository->findOneByName($name);

if(empty($contentBlock)) {
$contentBlock = new ContentBlock();
Expand All @@ -83,36 +83,34 @@ public function showAction($name)
{
$em = $this->getDoctrine()->getManager();
$repository = $em->getRepository('GlavwebContentBlockBundle:ContentBlock');
$contentBlock = $repository->findByName($name);
$contentBlock = $repository->findOneByName($name);

if(empty($contentBlock)) {
$contentBlock = new ContentBlock();
$contentBlock->setName($name);
$contentBlock->setBody($name);
$em->persist($contentBlock);
$em->flush();
$status = 200;
} else {
$status = 400;
}

return new JsonResponse(array(
'contentBlock' => $contentBlock
), $status);
'contentBlock' => $contentBlock->getBody()
));
}

/**
* @Route("/api/content-block/{name}/{content}", name="content_block_edit", requirements={"_method": "PUT"})
* @Route("/api/content-block/{name}", name="content_block_edit", requirements={"_method": "PUT"})
*
* @param string $name
* @param string $content
* @param Request $request
* @return JsonResponse
*/
public function editAction($name, $content)
public function editAction($name, Request $request)
{
$em = $this->getDoctrine()->getManager();
$repository = $em->getRepository('GlavwebContentBlockBundle:ContentBlock');
$contentBlock = $repository->findByName($name);
$contentBlock = $repository->findOneByName($name);
$content = $request->request->get('content', '');

if(!empty($contentBlock)) {
$contentBlock->setBody($content);
Expand All @@ -134,7 +132,7 @@ public function removeAction($name)
{
$em = $this->getDoctrine()->getManager();
$repository = $em->getRepository('GlavwebContentBlockBundle:ContentBlock');
$contentBlock = $repository->findByName($name);
$contentBlock = $repository->findOneByName($name);

if(!empty($contentBlock)) {
$em->remove($contentBlock);
Expand Down

0 comments on commit 0084106

Please sign in to comment.