Exemplo n.º 1
0
 public function sendInvitation(Event $event, array $users = [])
 {
     foreach ($users as $key => $user) {
         $invitation = $this->om->getRepository('ClarolineAgendaBundle:EventInvitation')->findOneBy(['user' => $user, 'event' => $event]);
         if ($invitation) {
             unset($users[$key]);
             continue;
         }
         $eventInvitation = new EventInvitation($event, $user);
         $this->om->persist($eventInvitation);
     }
     $this->om->flush();
     $creator = $this->tokenStorage->getToken()->getUser();
     $message = new SendMessageEvent($creator, $this->translator->trans('send_message_content', ['%Sender%' => $creator->getUserName(), '%Start%' => $event->getStart(), '%End%' => $event->getEnd(), '%Description%' => $event->getDescription(), '%JoinAction%' => $this->container->get('router')->generate('claro_agenda_invitation_action', ['event' => $event->getId(), 'action' => EventInvitation::JOIN]), '%MaybeAction%' => $this->container->get('router')->generate('claro_agenda_invitation_action', ['event' => $event->getId(), 'action' => EventInvitation::MAYBE]), '%ResignAction%' => $this->container->get('router')->generate('claro_agenda_invitation_action', ['event' => $event->getId(), 'action' => EventInvitation::RESIGN])], 'agenda'), $this->translator->trans('send_message_object', ['%EventName%' => $event->getTitle()], 'agenda'), null, $users, false);
     $dispatcher = $this->container->get('event_dispatcher');
     $dispatcher->dispatch('claroline_message_sending_to_users', $message);
 }