/** * Permite registrar invitaciones de usuarios a proyectos * @author Cesar Giraldo <*****@*****.**> 18/01/2016 */ public function addAction(Request $request, $id) { $closeFancy = false; $em = $this->getDoctrine()->getManager(); $project = $em->getRepository('BackendBundle:Project')->find($id); if (!$project || $project && !$this->container->get('access_control')->isAllowedProject($project->getId())) { $this->get('session')->getFlashBag()->add('messageError', $this->get('translator')->trans('backend.project.not_found_message')); $closeFancy = true; } $projectInvitation = new Entity\ProjectInvitation(); $projectInvitation->setProject($project); $form = $this->createForm(ProjectInvitationType::class, $projectInvitation); $form->handleRequest($request); if ($form->isSubmitted()) { $em = $this->getDoctrine()->getManager(); $parameters = $request->request->get('project_invitation'); $user = $em->getRepository('BackendBundle:User')->find($parameters['userId']); if ($user) { //verificamos que el usuario no este asociado al proyecto actual $search = array('user' => $user->getId(), 'project' => $project->getId()); $existsRelationship = $em->getRepository('BackendBundle:UserProject')->findOneBy($search); if (!$existsRelationship) { //verificamos si este usuario tenia invitaciones pendientes y las cancelamos $this->cancelPendingInvitations($user, $project); $projectInvitation->setUser($user); $projectInvitation->setProject($project); $projectInvitation->setUserOwner($this->getUser()); $em->persist($projectInvitation); $em->flush(); //enviamos el correo de notificacion $this->get('email_manager')->sendProjectInvitationEmail($projectInvitation); $this->get('session')->getFlashBag()->add('messageSuccess', $this->get('translator')->trans('backend.user_project.message_invitation_send')); $closeFancy = true; } else { $this->get('session')->getFlashBag()->add('messageError', $this->get('translator')->trans('backend.user_project.already_assigned_message')); } } else { $this->get('session')->getFlashBag()->add('messageError', $this->get('translator')->trans('backend.user.not_found_message')); } } return $this->render('BackendBundle:ProjectTeam:addCollaborator.html.twig', array('project' => $project, 'form' => $form->createView(), 'menu' => self::MENU, 'closeFancy' => $closeFancy)); }
/** * Permite enviar a un usuario el correo de invitacion a un proyecto * @author Cesar Giraldo <*****@*****.**> 20/01/2016 * @param Entity\ProjectInvitation $projectInvitation */ public function sendProjectInvitationEmail(Entity\ProjectInvitation $projectInvitation) { $message = \Swift_Message::newInstance()->setSubject($this->translator->trans('backend.project_invitation_email.subject'))->setFrom(self::SENDER_GENERAL_EMAILS)->setTo($projectInvitation->getuser()->getEmail())->setBody($this->container->get('templating')->render('BackendBundle:Email:projectInvitation.html.twig', array('projectInvitation' => $projectInvitation)), 'text/html'); $this->mailer->send($message); }