/** * resize * Process resize event on scheduleInstance (add to end of event) * @Route("/admin/schedule/{id}/resize/{dayDelta}/{minuteDelta}", options={"expose"=true}) * @Template("TSKScheduleBundle:Default:drag.html.twig") * @Method("POST") */ public function resizeAction(ScheduleInstance $scheduleInstance, $dayDelta, $minuteDelta) { $end = $scheduleInstance->getEnd(); $finalEnd = $this->addInterval($end, $dayDelta, 'day'); $finalEnd = $this->addInterval($finalEnd, $minuteDelta, 'minute'); // $finalEnd = $finalEnd->add(new \DateInterval($interval)); $scheduleInstance->setEnd($finalEnd); $em = $this->getDoctrine()->getManager(); $em->persist($scheduleInstance); $em->flush(); return array('response' => '1'); $view = View::create()->setStatusCode(200)->setData($scheduleInstance)->setTemplate('TSKScheduleBundle:Default:drag.html.twig'); return $this->get('fos_rest.view_handler')->handle($view); }
/** * processEntity * This function is responsible for taking a ScheduleEntity object * and generating up to $maxInstances ScheduleInstance objects from it. * * @param ScheduleEntity $scheduleEntity * @param mixed $maxInstances * @access public * @return void */ public function processEntity(ScheduleEntity $scheduleEntity, $maxInstances = null) { if (is_null($maxInstances)) { $maxInstances = $this->maxInstances; } if ($maxInstances > $this->maxInstances) { $maxInstances = $this->maxInstances; } // get rrule $timezone = 'America/New_York'; $today = new \DateTime(); $dateTimeZone = new \DateTimeZone($timezone); if ($scheduleEntity->getRrule()) { // Handling a recurring event $rrule = new RecurrenceRule($scheduleEntity->getRrule(), $scheduleEntity->getStartAt(), $timezone); $transformer = new RecurrenceRuleTransformer($rrule); $instances = $transformer->getComputedArray($scheduleEntity->getStartAt(), $dateTimeZone, $today->add(new \DateInterval('P6M')), $dateTimeZone); $options = $scheduleEntity->getOptions(); // generate instances if (count($instances)) { $count = 0; foreach ($instances as $startDateTime) { if ($count < $maxInstances) { // compute endDateTime based on duration $endDateTime = clone $startDateTime; $endDateTime->add(new \DateInterval($scheduleEntity->getDuration())); $si = new ScheduleInstance(); $si->setScheduleEntity($scheduleEntity); $si->setUser($scheduleEntity->getUser()); $si->setSchool($scheduleEntity->getSchool()); $si->setTitle($scheduleEntity->getTitle()); $si->setStart($startDateTime); $si->setEnd($endDateTime); $si->setIsAllDay(in_array('all_day', $scheduleEntity->getOptions())); $lastEnd = $endDateTime; $this->em->persist($si); $count++; } } } else { $instances = array(null); } $lastInstance = array_pop($instances); } else { // Handling a non-recurring event $si = new ScheduleInstance(); $si->setScheduleEntity($scheduleEntity); $si->setUser($scheduleEntity->getUser()); $si->setSchool($scheduleEntity->getSchool()); $si->setTitle($scheduleEntity->getTitle()); $si->setStart($scheduleEntity->getStartAt()); $si->setEnd($scheduleEntity->getEndAt()); $si->setIsAllDay(in_array('all_day', $scheduleEntity->getOptions())); $this->em->persist($si); // $lastEnd = $lastInstance = $scheduleEntity->getStartAt()->add(new \DateInterval($scheduleEntity->getDuration())); } // update last_processed // $scheduleEntity->setLastProcessedAt(new \DateTime()); // update expireAt // $scheduleEntity->setExpiresAt($lastEnd); // update maxDateAt // $scheduleEntity->setMaxDateAt($lastInstance); // $this->em->persist($scheduleEntity); $this->em->flush(); }