/**
  * Creates a new Project entity.
  * @author Cesar Giraldo <*****@*****.**> 12/01/2016
  */
 public function newAction(Request $request)
 {
     $project = new Entity\Project();
     $form = $this->createForm(ProjectType::class, $project);
     $form->handleRequest($request);
     $settings = new Entity\Settings();
     $settingsForm = $this->createForm(SettingType::class, $settings);
     $settingsForm->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         //creamos las configuraciones del proyecto
         $em->persist($settings);
         $project->setSettings($settings);
         $project->setUserOwner($this->getUser());
         $em->persist($project);
         //asociamos el usuario al proyecto que acaba de crear
         $userProject = new Entity\UserProject();
         $userProject->setProject($project);
         $userProject->setUser($this->getUser());
         $em->persist($userProject);
         //creamos los roles por defecto para el proyecto (P.Owner, S.Master, Desarrollador)
         $roles = array($this->get('translator')->trans('backend.user_role.product_owner') => $this->get('translator')->trans('backend.user_role.product_owner_description'), $this->get('translator')->trans('backend.user_role.scrum_master') => $this->get('translator')->trans('backend.user_role.scrum_master_description'), $this->get('translator')->trans('backend.user_role.developer') => $this->get('translator')->trans('backend.user_role.developer_description'));
         foreach ($roles as $roleName => $description) {
             $role = new Entity\Role();
             $role->setName($roleName);
             $role->setDescription($description);
             $role->setProject($project);
             $em->persist($role);
         }
         $em->flush();
         $this->get('session')->getFlashBag()->add('messageSuccess', $this->get('translator')->trans('backend.project.creation_success_message'));
         return $this->redirectToRoute('backend_projects_view', array('id' => $project->getId()));
     }
     return $this->render('BackendBundle:Project:new.html.twig', array('project' => $project, 'form' => $form->createView(), 'settings_form' => $settingsForm->createView(), 'menu' => self::MENU));
 }
 /**
  * Permite a un usuario aceptar invitaciones a proyectos
  * @author Cesar Giraldo <*****@*****.**> 22/01/2016
  * @param string $id identificador de la invitacion
  * @return type
  */
 public function acceptAction($id)
 {
     $em = $this->getDoctrine()->getManager();
     $invitation = $em->getRepository('BackendBundle:ProjectInvitation')->find($id);
     if (!$invitation || ($invitation && $invitation->getStatus() != Entity\ProjectInvitation::STATUS_ACTIVE || $invitation && $invitation->getUser()->getId() != $this->getUser()->getId())) {
         $this->get('session')->getFlashBag()->add('messageError', $this->get('translator')->trans('backend.project_invitation.invitation_not_found'));
         return $this->redirectToRoute('backend_notifications');
     }
     //asignamos el usuario al proyecto
     $userProject = new Entity\UserProject();
     $userProject->setProject($invitation->getProject());
     $userProject->setRole($invitation->getRole());
     $userProject->setUser($invitation->getUser());
     $em->persist($userProject);
     //marcamos la invitacion como aceptada
     $invitation->setStatus(Entity\ProjectInvitation::STATUS_ACCEPTED);
     $invitation->setAcceptedDate(Util::getCurrentDate());
     $em->persist($invitation);
     $em->flush();
     $this->get('session')->getFlashBag()->add('messageSuccess', $this->get('translator')->trans('backend.project_invitation.invitation_accepted_message'));
     return $this->redirectToRoute('backend_projects_view', array('id' => $invitation->getProject()->getId()));
 }