/** * Run tests to ensure the output is correct for set/getSchedulePeriod * * @return void */ public function testSchedulePeriod() { $schedulePeriod = $this->getMock('\\OpenSkedge\\AppBundle\\Entity\\SchedulePeriod'); $availSchedule = new AvailabilitySchedule(); $availSchedule->setSchedulePeriod($schedulePeriod); $this->assertInstanceOf('\\OpenSkedge\\AppBundle\\Entity\\SchedulePeriod', $availSchedule->getSchedulePeriod()); }
/** * Creates a new AvailabilitySchedule entity. * * @param Request $request The user's request object * @param integer $spid Schedule period ID from route * * @return Symfony\Component\HttpFoundation\Response */ public function newAction(Request $request, $spid) { $em = $this->getDoctrine()->getManager(); $schedulePeriod = $em->getRepository('OpenSkedgeBundle:SchedulePeriod')->find($spid); if (!$schedulePeriod instanceof SchedulePeriod) { throw $this->createNotFoundException('Unable to find SchedulePeriod entity.'); } $user = $this->getUser(); $existing = $em->getRepository('OpenSkedgeBundle:AvailabilitySchedule')->findBy(array('user' => $user->getId(), 'schedulePeriod' => $spid)); // If an availability schedule already exists for the given schedule period, give an error. if (!empty($existing)) { $request->getSession()->getFlashBag()->add('error', 'Availability schedule could not be created! You already have an availability schedule for the schedule period you selected.'); return $this->redirect($this->generateUrl('user_schedules')); } $appSettings = $this->get('app_settings')->getAppSettings(); $resolution = $request->query->get('timeresolution', $appSettings->getDefaultTimeResolution()); $entity = new AvailabilitySchedule(); $entity->setSchedulePeriod($schedulePeriod); $entity->setUser($user); if ($request->getMethod() == 'POST') { $data = $request->request->get('day'); for ($i = 0; $i < 7; $i++) { $entity->setDay($i, $data[$i]); } $entity->setLastUpdated(); $em->persist($entity); $em->flush(); $mailer = $this->container->get('notify_mailer'); $mailer->notifyAvailabilitySchedulePost($entity); return $this->redirect($this->generateUrl('user_schedule_view', array('uid' => $user->getId(), 'spid' => $spid))); } $dtUtils = $this->get('dt_utils'); $startIndex = $dtUtils->getIndexFromTime($appSettings->getStartHour()); $endIndex = $dtUtils->getIndexFromTime($appSettings->getEndHour()) - 1; if ($endIndex === -1) { // Midnight end hour $endIndex = 95; } return $this->render('OpenSkedgeBundle:AvailabilitySchedule:new.html.twig', array('avail' => $entity, 'htime' => $dtUtils->timeStrToDateTime($appSettings->getStartHour()), 'resolution' => $resolution, 'create' => true, 'startIndex' => $startIndex, 'endIndex' => $endIndex)); }