/**
  * @return array
  * @View()
  */
 public function postAdvicesAction()
 {
     $request = $this->get('request');
     if ($request->getMethod() == 'POST') {
         $params = $request->request->all();
         $repository = $this->getDoctrine()->getManager()->getRepository('FreedomObjectiveBundle:Objective');
         $objective = $repository->find($params['idObjective']);
         //If objective is public or we have the rigth to see it then :
         $advice = new Advice();
         $advice->setName(htmlentities($params['message']));
         $advice->setObjective($objective);
         $advice->setUser($this->getUser());
         $em = $this->getDoctrine()->getManager();
         $em->persist($advice);
         $em->flush();
         //We choose what we want to return
         $repositoryAdvice = $this->getDoctrine()->getManager()->getRepository('FreedomObjectiveBundle:Advice');
         $adviceArray = $repositoryAdvice->myFindOne($advice->getId());
     }
     return $adviceArray;
 }
Пример #2
0
 /**
  * Delete a Advice entity.
  *
  * @View(statusCode=204)
  *
  * @param Request $request
  * @param $entity
  * @internal param $id
  *
  * @return Response
  */
 public function deleteAction(Request $request, Objective $objective, Advice $entity)
 {
     $user = $this->getUser();
     if ($user == $entity->getUser() or $user == $entity->getObjective()->getUser()) {
         try {
             $em = $this->getDoctrine()->getManager();
             $em->remove($entity);
             $em->flush();
             return null;
         } catch (\Exception $e) {
             return FOSView::create($e->getMessage(), Codes::HTTP_INTERNAL_SERVER_ERROR);
         }
     } else {
         throw $this->createNotFoundException('No rights for this advice : ' . $entity);
     }
 }