Esempio n. 1
0
 public function sendShareNotification(User $by, Share $share)
 {
     $template = 'HomefinanceBundle:mailer:administration_shared.txt.twig';
     $context = array('by' => $by, 'share' => $share);
     $this->sendMessage($template, $context, $share->getUser()->getEmail());
 }
 /**
  * @Route("/administrations/{slug}/shares/new", name="share_administration_add")
  * @param Request $request
  * @param $slug
  * @return Response
  */
 public function newShareAction(Request $request, $slug)
 {
     $user = $this->getUser();
     $accessManager = $this->get('homefinance.administration.access_manager');
     $administration = $accessManager->getAdministrationBySlugWithAccess($slug, $user, Permission::FULL_ACCESS);
     $share = new Share();
     $share->setAdministration($administration);
     $form = $this->createForm('share_edit', $share);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $share->setPermission($form->get('permission')->getData());
         $userManager = $this->get('homefinance.user.manager');
         $share->setUser($userManager->createOrFindUserByEmail($form->get('email')->getData()));
         $doNotSave = false;
         if ($administration->getOwner() == $share->getUser()) {
             $doNotSave = true;
         } else {
             foreach ($administration->getShares() as $s) {
                 if ($s->getId() && $s->getUser() == $share->getUser()) {
                     $doNotSave = true;
                     break;
                 }
             }
         }
         if (!$doNotSave) {
             $event = new ShareEvent($share, $user);
             $this->get('event_dispatcher')->dispatch(AdministrationEvents::ADMINISTRATION_SHARED, $event);
             $em = $this->getDoctrine()->getManager();
             $em->persist($share);
             $em->flush();
             $this->addFlash('success', 'administration.share.added');
         }
         return $this->redirect($this->generateUrl('share_administration', array('slug' => $administration->getSlug())));
     }
     return $this->render('HomefinanceBundle:Administration:new_share.html.twig', array('form' => $form->createView()));
 }