/**
  * @Route("/create", name="oro_calendar_event_create")
  * @Template("OroCalendarBundle:CalendarEvent:update.html.twig")
  * @Acl(
  *      id="oro_calendar_event_create",
  *      type="entity",
  *      class="OroCalendarBundle:CalendarEvent",
  *      permission="CREATE",
  *      group_name=""
  * )
  */
 public function createAction()
 {
     $entity = new CalendarEvent();
     $startTime = new \DateTime('now', new \DateTimeZone('UTC'));
     $entity->setStart($startTime);
     $entity->setEnd($startTime->add(new \DateInterval('PT1H')));
     $formAction = $this->get('oro_entity.routing_helper')->generateUrlByRequest('oro_calendar_event_create', $this->getRequest());
     return $this->update($entity, $formAction);
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $user = $manager->getRepository('OroUserBundle:User')->findOneByUsername('admin');
     $organization = $manager->getRepository('OroOrganizationBundle:Organization')->getFirst();
     $calendar = $manager->getRepository('OroCalendarBundle:Calendar')->findDefaultCalendar($user->getId(), $organization->getId());
     $calendarEvent = new CalendarEvent();
     $calendarEvent->setCalendar($calendar);
     $calendarEvent->setTitle(self::CALENDAR_EVENT_TITLE);
     $calendarEvent->setStart(new \DateTime('tomorrow'));
     $calendarEvent->setEnd(new \DateTime('tomorrow + 1hour'));
     $calendarEvent->setAllDay(false);
     $manager->persist($calendarEvent);
     $manager->flush();
 }
 /**
  * @Route("/{id}/event/create", name="oro_system_calendar_event_create", requirements={"id"="\d+"})
  * @Template("OroCalendarBundle:SystemCalendarEvent:update.html.twig")
  */
 public function createAction(SystemCalendar $calendar)
 {
     $this->checkPermissionByConfig($calendar);
     $securityFacade = $this->getSecurityFacade();
     $isGranted = $calendar->isPublic() ? $securityFacade->isGranted('oro_public_calendar_event_management') : $securityFacade->isGranted('oro_system_calendar_event_management');
     if (!$isGranted) {
         throw new AccessDeniedException();
     }
     $entity = new CalendarEvent();
     $startTime = new \DateTime('now', new \DateTimeZone('UTC'));
     $endTime = new \DateTime('now', new \DateTimeZone('UTC'));
     $endTime->add(new \DateInterval('PT1H'));
     $entity->setStart($startTime);
     $entity->setEnd($endTime);
     $entity->setSystemCalendar($calendar);
     return $this->update($entity, $this->get('router')->generate('oro_system_calendar_event_create', ['id' => $calendar->getId()]));
 }
 protected function loadCalendars()
 {
     /** @var \Oro\Bundle\OrganizationBundle\Entity\Organization $organization */
     $organization = $this->getReference('default_organization');
     /** @var \Oro\Bundle\UserBundle\Entity\User[] $users */
     $users = $this->user->findAll();
     foreach ($users as $user) {
         //get default calendar, each user has default calendar after creation
         $calendar = $this->calendar->findDefaultCalendar($user->getId(), $organization->getId());
         $this->setSecurityContext($calendar->getOwner());
         /** @var CalendarEvent $event */
         $days = $this->getDatePeriod();
         foreach ($days as $day) {
             /** @var \DateTime $day */
             if (!$this->isWeekend($day)) {
                 //work day
                 if (mt_rand(0, 1)) {
                     $event = new CalendarEvent();
                     $event->setTitle('Work Reminder');
                     $day->setTime(8, 0, 0);
                     $event->setStart(clone $day);
                     $day->setTime(18, 0, 0);
                     $event->setEnd(clone $day);
                     $event->setAllDay(true);
                     $calendar->addEvent($event);
                 }
                 //call
                 if (mt_rand(0, 1)) {
                     $event = new CalendarEvent();
                     $event->setTitle('Client Call');
                     $day->setTime(11, 0, 0);
                     $event->setStart(clone $day);
                     $day->setTime(12, 0, 0);
                     $event->setEnd(clone $day);
                     $event->setAllDay(false);
                     $calendar->addEvent($event);
                 }
                 //meeting
                 if (mt_rand(0, 1)) {
                     $event = new CalendarEvent();
                     $event->setTitle('Meeting');
                     $day->setTime(16, 0, 0);
                     $event->setStart(clone $day);
                     $day->setTime(18, 0, 0);
                     $event->setEnd(clone $day);
                     $event->setAllDay(false);
                     $calendar->addEvent($event);
                 }
                 //lunch
                 if (mt_rand(0, 1)) {
                     $event = new CalendarEvent();
                     $event->setTitle('Lunch');
                     $day->setTime(12, 0, 0);
                     $event->setStart(clone $day);
                     $day->setTime(12, 30, 0);
                     $event->setEnd(clone $day);
                     $event->setAllDay(false);
                     $calendar->addEvent($event);
                 }
                 //business trip
                 if (mt_rand(0, 1)) {
                     $event = new CalendarEvent();
                     $event->setTitle('Business trip');
                     $day->setTime(0, 0, 0);
                     $event->setStart(clone $day);
                     $day->setTime(0, 0, 0);
                     $day->add(\DateInterval::createFromDateString('+3 days'));
                     $event->setEnd(clone $day);
                     $event->setAllDay(true);
                     $calendar->addEvent($event);
                 }
             } else {
                 $event = new CalendarEvent();
                 $event->setTitle('Weekend');
                 $day->setTime(8, 0, 0);
                 $event->setStart(clone $day);
                 $day->setTime(18, 0, 0);
                 $event->setEnd(clone $day);
                 $event->setAllDay(true);
                 $calendar->addEvent($event);
             }
         }
         $this->persist($this->container->get('doctrine.orm.entity_manager'), $calendar);
     }
     $this->flush($this->container->get('doctrine.orm.entity_manager'));
 }
Esempio n. 5
0
 protected function loadCalendars()
 {
     $days = $this->getDatePeriod();
     $events = [];
     foreach ($days as $day) {
         /** @var \DateTime $day */
         if (!$this->isWeekend($day)) {
             //work day
             $event = new CalendarEvent();
             $event->setTitle('Work Reminder');
             $day->setTime(8, 0, 0);
             $event->setStart(clone $day);
             $day->setTime(18, 0, 0);
             $event->setEnd(clone $day);
             $event->setAllDay(true);
             $events['workday'][] = $event;
             //call
             $event = new CalendarEvent();
             $event->setTitle('Client Call');
             $day->setTime(11, 0, 0);
             $event->setStart(clone $day);
             $day->setTime(12, 0, 0);
             $event->setEnd(clone $day);
             $event->setAllDay(false);
             $events['call'][] = $event;
             //meeting
             $event = new CalendarEvent();
             $event->setTitle('Meeting');
             $day->setTime(16, 0, 0);
             $event->setStart(clone $day);
             $day->setTime(18, 0, 0);
             $event->setEnd(clone $day);
             $event->setAllDay(false);
             $events['meeting'][] = $event;
             //lunch
             $event = new CalendarEvent();
             $event->setTitle('Lunch');
             $day->setTime(12, 0, 0);
             $event->setStart(clone $day);
             $day->setTime(12, 30, 0);
             $event->setEnd(clone $day);
             $event->setAllDay(false);
             $events['lunch'][] = $event;
             //business trip
             $event = new CalendarEvent();
             $event->setTitle('Business trip');
             $day->setTime(0, 0, 0);
             $event->setStart(clone $day);
             $day->setTime(0, 0, 0);
             $day->add(\DateInterval::createFromDateString('+3 days'));
             $event->setEnd(clone $day);
             $event->setAllDay(true);
             $events['b_trip'][] = $event;
         } else {
             $event = new CalendarEvent();
             $event->setTitle('Weekend');
             $day->setTime(8, 0, 0);
             $event->setStart(clone $day);
             $day->setTime(18, 0, 0);
             $event->setEnd(clone $day);
             $event->setAllDay(true);
             $events['weekend'][] = $event;
         }
     }
     foreach ($this->users as $user) {
         //get default calendar, each user has default calendar after creation
         $calendar = $this->calendar->findDefaultCalendar($user->getId(), $this->organization->getId());
         $this->setSecurityContext($calendar->getOwner());
         foreach ($events as $typeEvents) {
             if (mt_rand(0, 1)) {
                 foreach ($typeEvents as $typeEvent) {
                     $calendar->addEvent(clone $typeEvent);
                 }
             }
         }
         $this->em->persist($calendar);
     }
     $this->em->flush();
     $this->em->clear('Oro\\Bundle\\CalendarBundle\\Entity\\CalendarEvent');
     $this->em->clear('Oro\\Bundle\\CalendarBundle\\Entity\\Calendar');
 }
 /**
  * @param CalendarEvent $parentCalendarEvent
  * @param User $user
  * @return CalendarEvent
  */
 protected function createChildEvent(CalendarEvent $parentCalendarEvent, User $user)
 {
     $userCalendar = $this->getDefaultUserCalendar($user);
     $childCalendarEvent = new CalendarEvent();
     $childCalendarEvent->setStart($parentCalendarEvent->getStart())->setEnd($parentCalendarEvent->getEnd())->setTitle($parentCalendarEvent->getTitle())->setCalendar($userCalendar)->setAllDay(false);
     $parentCalendarEvent->addChildEvent($childCalendarEvent);
     return $childCalendarEvent;
 }