Ejemplo n.º 1
0
 /**
  * @Route("/project/saveProject", name="_project_save_project")
  */
 public function saveProjectAction(Request $request)
 {
     $isNew = false;
     $ProjectTypeParams = $request->get("ProjectType");
     $user = $this->get('security.token_storage')->getToken()->getUser();
     if ($user == "anon.") {
         $user = null;
     }
     $return = ["success" => false, "error" => []];
     if (empty($request->get("projectId"))) {
         $project = new Projects();
         $isNew = true;
     } else {
         $project = $this->getDoctrine()->getRepository("AppBundle:Projects")->find($request->get("projectId"));
     }
     if (empty($project)) {
         $isNew = true;
         $project = new Projects();
         $project->setDateCreate(new \DateTime());
         $project->setVisibled(1);
         $project->setDeleted(0);
     }
     //$issue->setUserCreate($user);
     $form = $this->createForm("ProjectType", $project, array('csrf_protection' => false));
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         try {
             $em->persist($project);
             $em->flush();
             $this->addFlash('success', 'Success! Project saved.');
             if ($isNew) {
                 $projectUser = new ProjectUsers();
                 $projectUser->setProject($project);
                 $projectUser->setUser($user);
                 $projectUser->setRole($this->getDoctrine()->getRepository("AppBundle:ProjectRoles")->find(1));
                 $em->persist($projectUser);
                 $em->flush();
             }
             $return["success"] = true;
             $return["html"] = $this->get('twig')->render('AppBundle:Projects:_blocks/issue/projectForm.html.twig', ["project" => $project, "form" => $form->createView()]);
         } catch (Exception $e) {
             $return["error"][] = $e->getMessage();
         }
     } else {
         $this->addFlash('error', 'Error! Invalid form data.');
         foreach ($form->getErrors() as $error) {
             $return["error"][] = $error->getMessage();
         }
         $return["html"] = $this->get('twig')->render('AppBundle:Projects:_blocks/issue/projectForm.html.twig', ["project" => $project, "form" => $form->createView()]);
     }
     return new JsonResponse($return);
 }
Ejemplo n.º 2
0
 /**
  * Creates a form to delete a Projects entity.
  *
  * @param Projects $project The Projects entity
  *
  * @return \Symfony\Component\Form\Form The form
  */
 private function createDeleteForm(Projects $project)
 {
     return $this->createFormBuilder()->setAction($this->generateUrl('projects_delete', array('id' => $project->getId())))->setMethod('DELETE')->getForm();
 }