/**
  * @Route("/event/update/{id}", name="oro_system_calendar_event_update", requirements={"id"="\d+"})
  * @Template
  */
 public function updateAction(CalendarEvent $entity)
 {
     $calendar = $entity->getSystemCalendar();
     if (!$calendar) {
         // an event must belong to system calendar
         throw $this->createNotFoundException('Not system calendar event.');
     }
     $this->checkPermissionByConfig($calendar);
     $securityFacade = $this->getSecurityFacade();
     if (!$calendar->isPublic() && !$securityFacade->isGranted('VIEW', $calendar)) {
         // an user must have permissions to view system calendar
         throw new AccessDeniedException();
     }
     $isGranted = $calendar->isPublic() ? $securityFacade->isGranted('oro_public_calendar_event_management') : $securityFacade->isGranted('oro_system_calendar_event_management');
     if (!$isGranted) {
         throw new AccessDeniedException();
     }
     return $this->update($entity, $this->get('router')->generate('oro_system_calendar_event_update', ['id' => $entity->getId()]));
 }
 public function testSetCalendar()
 {
     $calendar = new Calendar();
     $systemCalendar = new SystemCalendar();
     $obj = new CalendarEvent();
     $this->assertNull($obj->getCalendar());
     $this->assertNull($obj->getSystemCalendar());
     $obj->setCalendar($calendar);
     $this->assertSame($calendar, $obj->getCalendar());
     $this->assertNull($obj->getSystemCalendar());
     $obj->setSystemCalendar($systemCalendar);
     $this->assertNull($obj->getCalendar());
     $this->assertSame($systemCalendar, $obj->getSystemCalendar());
     $obj->setCalendar($calendar);
     $this->assertSame($calendar, $obj->getCalendar());
     $this->assertNull($obj->getSystemCalendar());
     $obj->setCalendar(null);
     $this->assertNull($obj->getCalendar());
     $obj->setSystemCalendar($systemCalendar);
     $this->assertNull($obj->getCalendar());
     $this->assertSame($systemCalendar, $obj->getSystemCalendar());
     $obj->setSystemCalendar(null);
     $this->assertNull($obj->getCalendar());
     $this->assertNull($obj->getSystemCalendar());
 }
 /**
  * @param CalendarEvent $entity
  *
  * @throws \LogicException
  */
 protected function ensureCalendarSet(CalendarEvent $entity)
 {
     if ($entity->getCalendar() || $entity->getSystemCalendar()) {
         return;
     }
     if (!$this->securityFacade->getLoggedUser() || !$this->securityFacade->getOrganization()) {
         throw new \LogicException('Both logged in user and organization must be defined.');
     }
     /** @var Calendar $defaultCalendar */
     $defaultCalendar = $this->manager->getRepository('OroCalendarBundle:Calendar')->findDefaultCalendar($this->securityFacade->getLoggedUser()->getId(), $this->securityFacade->getOrganization()->getId());
     $entity->setCalendar($defaultCalendar);
 }