Пример #1
0
 /**
  * Process form
  *
  * @param  CalendarEvent $entity
  * @throws \LogicException
  *
  * @return bool  True on successful processing, false otherwise
  */
 public function process(CalendarEvent $entity)
 {
     if (!$entity->getCalendar()) {
         if ($this->securityFacade->getLoggedUser() && $this->securityFacade->getOrganization()) {
             /** @var Calendar $defaultCalendar */
             $defaultCalendar = $this->manager->getRepository('OroCalendarBundle:Calendar')->findDefaultCalendar($this->securityFacade->getLoggedUser()->getId(), $this->securityFacade->getOrganization()->getId());
             $entity->setCalendar($defaultCalendar);
         } else {
             throw new \LogicException('Current user did not define');
         }
     }
     $this->form->setData($entity);
     if (in_array($this->request->getMethod(), array('POST', 'PUT'))) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             $targetEntityClass = $this->entityRoutingHelper->getEntityClassName($this->request);
             if ($targetEntityClass) {
                 $targetEntityId = $this->entityRoutingHelper->getEntityId($this->request);
                 $targetEntity = $this->entityRoutingHelper->getEntityReference($targetEntityClass, $targetEntityId);
                 $action = $this->entityRoutingHelper->getAction($this->request);
                 if ($action === 'activity') {
                     $this->activityManager->addActivityTarget($entity, $targetEntity);
                 }
                 if ($action === 'assign' && $targetEntity instanceof User && $targetEntityId !== $this->securityFacade->getLoggedUserId()) {
                     /** @var Calendar $defaultCalendar */
                     $defaultCalendar = $this->manager->getRepository('OroCalendarBundle:Calendar')->findDefaultCalendar($targetEntity->getId(), $targetEntity->getOrganization()->getId());
                     $entity->setCalendar($defaultCalendar);
                 }
             }
             $this->onSuccess($entity);
             return true;
         }
     }
     return false;
 }
Пример #2
0
 public function testPreUpdate()
 {
     $obj = new CalendarEvent();
     $this->assertNull($obj->getUpdatedAt());
     $obj->preUpdate();
     $this->assertInstanceOf('\\DateTime', $obj->getUpdatedAt());
 }
 public function testBuildView()
 {
     $firstUser = new User();
     $firstUser->setUsername('1');
     $secondUser = new User();
     $secondUser->setUsername('2');
     $firstCalendar = new Calendar();
     $firstCalendar->setOwner($firstUser);
     $secondCalendar = new Calendar();
     $secondCalendar->setOwner($secondUser);
     $firstEvent = new CalendarEvent();
     $firstEvent->setCalendar($firstCalendar);
     $secondEvent = new CalendarEvent();
     $secondEvent->setCalendar($secondCalendar);
     $formData = [$firstEvent, $secondEvent];
     $transformedData = [$firstUser, $secondUser];
     $form = $this->getMock('Symfony\\Component\\Form\\FormInterface');
     $form->expects($this->once())->method('getData')->will($this->returnValue($formData));
     $this->transformer->expects($this->once())->method('transform')->with($formData)->will($this->returnValue($transformedData));
     $converter = $this->getMock('Oro\\Bundle\\FormBundle\\Autocomplete\\ConverterInterface');
     $converter->expects($this->any())->method('convertItem')->will($this->returnCallback([$this, 'convertEvent']));
     $formView = new FormView();
     $expectedSelectedData = json_encode([$this->convertEvent($firstUser), $this->convertEvent($secondUser)]);
     $this->type->buildView($formView, $form, ['converter' => $converter]);
     $this->assertArrayHasKey('attr', $formView->vars);
     $this->assertEquals(['data-selected-data' => $expectedSelectedData], $formView->vars['attr']);
 }
Пример #4
0
 /**
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $owner = $this->getReference('simple_user');
     $calendar = $manager->getRepository('Oro\\Bundle\\CalendarBundle\\Entity\\Calendar')->findOneBy([]);
     $event = new CalendarEvent();
     $event->setTitle('test_title')->setCalendar($calendar)->setAllDay(true)->setStart(new \DateTime('now -2 days', new \DateTimeZone('UTC')))->setEnd(new \DateTime('now', new \DateTimeZone('UTC')));
     $emailTemplate1 = new EmailTemplate('no_entity_name', 'test {{ system.appFullName }} etc');
     $emailTemplate1->setOrganization($owner->getOrganization());
     $emailTemplate2 = new EmailTemplate('test_template', 'test {{ system.appFullName }} etc');
     $emailTemplate2->setEntityName('Oro\\Bundle\\CalendarBundle\\Entity\\CalendarEvent');
     $emailTemplate2->setOrganization($owner->getOrganization());
     $emailTemplate3 = new EmailTemplate('no_system', 'test {{ system.appFullName }} etc');
     $emailTemplate3->setIsSystem(false);
     $emailTemplate3->setEntityName('Entity\\Name');
     $emailTemplate3->setOrganization($owner->getOrganization());
     $emailTemplate4 = new EmailTemplate('system', 'test {{ system.appFullName }} etc');
     $emailTemplate4->setIsSystem(true);
     $emailTemplate4->setEntityName('Entity\\Name');
     $emailTemplate4->setOrganization($owner->getOrganization());
     $emailTemplate5 = new EmailTemplate('no_system_no_entity', 'test {{ system.appFullName }} etc');
     $emailTemplate5->setIsSystem(false);
     $emailTemplate5->setOrganization($owner->getOrganization());
     $manager->persist($event);
     $manager->persist($emailTemplate1);
     $manager->persist($emailTemplate2);
     $manager->persist($emailTemplate3);
     $manager->persist($emailTemplate4);
     $manager->persist($emailTemplate5);
     $manager->flush();
     $this->setReference('emailTemplate1', $emailTemplate1);
     $this->setReference('emailTemplate2', $emailTemplate2);
     $this->setReference('emailTemplate3', $emailTemplate3);
     $this->setReference('emailTemplate4', $emailTemplate4);
     $this->setReference('emailTemplate5', $emailTemplate5);
 }
Пример #5
0
 /**
  * {@inheritdoc}
  */
 public function reverseTransform($value)
 {
     if (!$value) {
         return [];
     }
     /** @var CalendarRepository $calendarRepository */
     $calendarRepository = $this->registry->getRepository('OroCalendarBundle:Calendar');
     $organizationId = $this->securityFacade->getOrganizationId();
     if (!$organizationId) {
         throw new TransformationFailedException('Can\'t get current organization');
     }
     $events = new ArrayCollection();
     /** @var User $user */
     $userIds = [];
     foreach ($value as $user) {
         $userIds[] = $user->getId();
     }
     $calendars = $calendarRepository->findDefaultCalendars($userIds, $organizationId);
     foreach ($calendars as $calendar) {
         $event = new CalendarEvent();
         $event->setCalendar($calendar);
         $events->add($event);
     }
     return $events;
 }
 /**
  * @Route("/accept/{id}",
  *      name="oro_calendar_event_accepted",
  *      requirements={"id"="\d+"}, defaults={"status"="accepted"})
  * @Route("/tentatively/{id}",
  *      name="oro_calendar_event_tentatively_accepted",
  *      requirements={"id"="\d+"}, defaults={"status"="tentatively_accepted"})
  * @Route("/decline/{id}",
  *      name="oro_calendar_event_declined",
  *      requirements={"id"="\d+"}, defaults={"status"="declined"})
  * @param CalendarEvent $entity
  * @param string $status
  * @return JsonResponse
  */
 public function changeStatus(CalendarEvent $entity, $status)
 {
     $em = $this->getDoctrine()->getManager();
     $entity->setInvitationStatus($status);
     $em->flush($entity);
     $this->get('oro_calendar.send_processor.email')->sendRespondNotification($entity);
     return new JsonResponse(['successful' => true]);
 }
Пример #7
0
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $calendar = $manager->getRepository('Oro\\Bundle\\CalendarBundle\\Entity\\Calendar')->findOneBy([]);
     $event = new CalendarEvent();
     $event->setTitle('test_title')->setCalendar($calendar)->setAllDay(true)->setStart(new \DateTime('now -2 days', new \DateTimeZone('UTC')))->setEnd(new \DateTime('now', new \DateTimeZone('UTC')));
     $manager->persist($event);
     $this->setReference('default_activity', $event);
     $manager->flush();
 }
 /**
  * "Success" form handler
  *
  * @param CalendarEvent   $entity
  * @param ArrayCollection $originalChildren
  * @param boolean         $notify
  */
 protected function onSuccess(CalendarEvent $entity, ArrayCollection $originalChildren, $notify)
 {
     $new = $entity->getId() ? false : true;
     $this->manager->persist($entity);
     $this->manager->flush();
     if ($new) {
         $this->emailSendProcessor->sendInviteNotification($entity);
     } else {
         $this->emailSendProcessor->sendUpdateParentEventNotification($entity, $originalChildren, $notify);
     }
 }
 public function testChangeInvitationStatus()
 {
     $availableStatuses = [CalendarEvent::ACCEPTED, CalendarEvent::TENTATIVELY_ACCEPTED, CalendarEvent::DECLINED];
     foreach ($availableStatuses as $status) {
         $calendarEventId = $this->calendarEvent->getId();
         $this->client->request('GET', $this->getUrl('oro_calendar_event_' . $status, ['id' => $calendarEventId, 'status' => $status]));
         $response = $this->client->getResponse();
         $data = json_decode($response->getContent(), true);
         $this->assertTrue($data['successful']);
         $calendarEvent = $this->getCalendarEventByTitle(LoadCalendarEventData::CALENDAR_EVENT_TITLE);
         $this->assertEquals($status, $calendarEvent->getInvitationStatus());
     }
 }
Пример #10
0
 /**
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $calendar = $manager->getRepository('Oro\\Bundle\\CalendarBundle\\Entity\\Calendar')->findOneBy([]);
     $event = new CalendarEvent();
     $event->setTitle('test_title')->setCalendar($calendar)->setAllDay(true)->setStart(new \DateTime('now -2 days', new \DateTimeZone('UTC')))->setEnd(new \DateTime('now', new \DateTimeZone('UTC')));
     $emailTemplate1 = new EmailTemplate('no_entity_name', 'test {{ system.appFullName }} etc');
     $emailTemplate2 = new EmailTemplate('test_template', 'test {{ system.appFullName }} etc');
     $emailTemplate2->setEntityName('Oro\\Bundle\\CalendarBundle\\Entity\\CalendarEvent');
     $manager->persist($event);
     $manager->persist($emailTemplate1);
     $manager->persist($emailTemplate2);
     $manager->flush();
 }
Пример #11
0
 /**
  * @dataProvider supportedMethods
  */
 public function testProcessValidDataWithTargetEntityActivity($method)
 {
     $targetEntity = new User();
     ReflectionUtil::setId($targetEntity, 123);
     $organization = new Organization();
     ReflectionUtil::setId($organization, 1);
     $targetEntity->setOrganization($organization);
     $defaultCalendar = $this->getMockBuilder('Oro\\Bundle\\CalendarBundle\\Entity\\Calendar')->disableOriginalConstructor()->getMock();
     $this->entity->setCalendar($defaultCalendar);
     $this->entityRoutingHelper->expects($this->once())->method('getEntityClassName')->will($this->returnValue(get_class($targetEntity)));
     $this->entityRoutingHelper->expects($this->once())->method('getEntityId')->will($this->returnValue($targetEntity->getId()));
     $this->entityRoutingHelper->expects($this->once())->method('getAction')->will($this->returnValue('activity'));
     $this->request->setMethod($method);
     $this->form->expects($this->once())->method('setData')->with($this->identicalTo($this->entity));
     $this->form->expects($this->once())->method('submit')->with($this->identicalTo($this->request));
     $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true));
     $this->entityRoutingHelper->expects($this->once())->method('getEntityReference')->with(get_class($targetEntity), $targetEntity->getId())->will($this->returnValue($targetEntity));
     $this->activityManager->expects($this->once())->method('addActivityTarget')->with($this->identicalTo($this->entity), $this->identicalTo($targetEntity));
     $this->form->expects($this->once())->method('get')->will($this->returnValue($this->form));
     $this->form->expects($this->once())->method('getData');
     $this->om->expects($this->once())->method('persist')->with($this->identicalTo($this->entity));
     $this->om->expects($this->once())->method('flush');
     $this->assertTrue($this->handler->process($this->entity));
     $this->assertSame($defaultCalendar, $this->entity->getCalendar());
 }
 public function testTransform()
 {
     $this->assertNull($this->transformer->transform(null));
     $firstUser = new User();
     $firstUser->setUsername('1');
     $secondUser = new User();
     $secondUser->setUsername('2');
     $firstCalendar = new Calendar();
     $firstCalendar->setOwner($firstUser);
     $secondCalendar = new Calendar();
     $secondCalendar->setOwner($secondUser);
     $firstEvent = new CalendarEvent();
     $firstEvent->setCalendar($firstCalendar);
     $secondEvent = new CalendarEvent();
     $secondEvent->setCalendar($secondCalendar);
     $this->assertEquals([$firstUser, $secondUser], $this->transformer->transform([$firstEvent, $secondEvent])->toArray());
 }
 /**
  * @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()]));
 }
Пример #14
0
 /**
  * Links an event with a calendar by its alias and id
  *
  * @param CalendarEvent $event
  * @param string        $calendarAlias
  * @param int           $calendarId
  *
  * @throws \LogicException
  * @throws ForbiddenException
  */
 public function setCalendar(CalendarEvent $event, $calendarAlias, $calendarId)
 {
     if ($calendarAlias === Calendar::CALENDAR_ALIAS) {
         $calendar = $event->getCalendar();
         if (!$calendar || $calendar->getId() !== $calendarId) {
             $event->setCalendar($this->findCalendar($calendarId));
         }
     } elseif (in_array($calendarAlias, [SystemCalendar::CALENDAR_ALIAS, SystemCalendar::PUBLIC_CALENDAR_ALIAS])) {
         $systemCalendar = $this->findSystemCalendar($calendarId);
         //@TODO: Added permission verification
         if ($systemCalendar->isPublic() && !$this->calendarConfig->isPublicCalendarEnabled()) {
             throw new ForbiddenException('Public calendars are disabled.');
         }
         if (!$systemCalendar->isPublic() && !$this->calendarConfig->isSystemCalendarEnabled()) {
             throw new ForbiddenException('System calendars are disabled.');
         }
         $event->setSystemCalendar($systemCalendar);
     } else {
         throw new \LogicException(sprintf('Unexpected calendar alias: "%s". CalendarId: %d.', $calendarAlias, $calendarId));
     }
 }
Пример #15
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();
 }
Пример #16
0
 /**
  * @param CalendarEvent $calendarEvent
  * @param string        $status
  */
 protected function setDefaultEventStatus(CalendarEvent $calendarEvent, $status = CalendarEvent::NOT_RESPONDED)
 {
     if (!$calendarEvent->getInvitationStatus()) {
         $calendarEvent->setInvitationStatus($status);
     }
 }
Пример #17
0
 /**
  * @param CalendarEvent $childEvent
  *
  * @return array
  */
 protected function getParentEmail(CalendarEvent $childEvent)
 {
     if ($childEvent->getParent()) {
         return [$childEvent->getParent()->getCalendar()->getOwner()->getEmail()];
     } else {
         return [];
     }
 }
 /**
  * @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;
 }
 protected function setUpEvent(CalendarEvent $event, $id, $email)
 {
     $user = new User();
     $user->setEmail($email);
     $calendar = new Calendar();
     $calendar->setOwner($user);
     $event->setCalendar($calendar);
     ReflectionUtil::setPrivateProperty($event, 'id', $id);
     $event->setReminded(false);
 }
 /**
  * Get calendar owner
  *
  * @param CalendarEvent $activityEntity
  * @return null|User
  */
 protected function getOwner($activityEntity)
 {
     /** @var $activityEntity CalendarEvent */
     if ($activityEntity->getCalendar()) {
         return $activityEntity->getCalendar()->getOwner();
     }
     return null;
 }
Пример #21
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');
 }
Пример #22
0
 /**
  * @param CalendarEvent $expected
  * @param CalendarEvent $actual
  */
 protected function assertEventDataEquals(CalendarEvent $expected, CalendarEvent $actual)
 {
     $this->assertEquals($expected->getTitle(), $actual->getTitle());
     $this->assertEquals($expected->getDescription(), $actual->getDescription());
     $this->assertEquals($expected->getStart(), $actual->getStart());
     $this->assertEquals($expected->getEnd(), $actual->getEnd());
     $this->assertEquals($expected->getAllDay(), $actual->getAllDay());
 }
 /**
  * @expectedException \Oro\Bundle\SecurityBundle\Exception\ForbiddenException
  * @expectedExceptionMessage Access denied.
  */
 public function testHandleDeleteWhenSystemCalendarEventManagementNotGranted()
 {
     $calendar = new SystemCalendar();
     $event = new CalendarEvent();
     $event->setSystemCalendar($calendar);
     $this->manager->expects($this->once())->method('find')->will($this->returnValue($event));
     $this->calendarConfig->expects($this->once())->method('isSystemCalendarEnabled')->will($this->returnValue(true));
     $this->securityFacade->expects($this->once())->method('isGranted')->with('oro_system_calendar_event_management')->will($this->returnValue(false));
     $this->handler->handleDelete(1, $this->manager);
 }
Пример #24
0
 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());
 }
Пример #25
0
 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'));
 }
 /**
  * @Route("/update/{id}", name="oro_calendar_event_update", requirements={"id"="\d+"})
  * @Template
  * @Acl(
  *      id="oro_calendar_event_update",
  *      type="entity",
  *      class="OroCalendarBundle:CalendarEvent",
  *      permission="EDIT",
  *      group_name=""
  * )
  */
 public function updateAction(CalendarEvent $entity)
 {
     $formAction = $this->get('router')->generate('oro_calendar_event_update', ['id' => $entity->getId()]);
     return $this->update($entity, $formAction);
 }
Пример #27
0
 public function testIsNotUpdatedFlags()
 {
     $calendarEvent = new CalendarEvent();
     $calendarEvent->setUpdatedAt(null);
     $this->assertFalse($calendarEvent->isUpdatedAtSet());
 }
Пример #28
0
 /**
  * @return array
  */
 public function entityDataProvider()
 {
     $event = new CalendarEvent();
     $event->setReminders(new ArrayCollection([new Reminder()]));
     return [[null, false], [new \stdClass(), false], [new CalendarEvent(), false], [$event, true]];
 }
Пример #29
0
 /**
  * Adds an event to this calendar.
  *
  * @param  CalendarEvent $event
  *
  * @return self
  */
 public function addEvent(CalendarEvent $event)
 {
     $this->events[] = $event;
     $event->setCalendar($this);
     return $this;
 }
 /**
  * @param CalendarEvent $event
  *
  * @return array
  */
 protected function serializeCalendarEvent(CalendarEvent $event)
 {
     return ['id' => $event->getId(), 'title' => $event->getTitle(), 'description' => $event->getDescription(), 'start' => $event->getStart(), 'end' => $event->getEnd(), 'allDay' => $event->getAllDay(), 'backgroundColor' => $event->getBackgroundColor(), 'createdAt' => $event->getCreatedAt(), 'updatedAt' => $event->getUpdatedAt(), 'invitationStatus' => $event->getInvitationStatus(), 'parentEventId' => $event->getParent() ? $event->getParent()->getId() : null, 'calendar' => $event->getCalendar() ? $event->getCalendar()->getId() : null];
 }