コード例 #1
0
 /**
  * @Route("/team/team/{category_id}/schedule/new")
  * @Template()
  */
 public function newAction($category_id)
 {
     $em = $this->getDoctrine()->getManager();
     $category = $em->find('ClubTeamBundle:TeamCategory', $category_id);
     $schedule = new \Club\TeamBundle\Entity\Schedule();
     $schedule->setTeamCategory($category);
     $schedule->setDescription($category->getDescription());
     $schedule->setPenalty($category->getPenalty());
     $schedule->setFirstDate(new \DateTime(date('Y-m-d 14:00:00')));
     $schedule->setEndDate(new \DateTime(date('Y-m-d 15:00:00')));
     $schedule->setMaxAttend(15);
     $res = $this->process($schedule);
     if ($res instanceof RedirectResponse) {
         return $res;
     }
     return array('category' => $category, 'form' => $res->createView());
 }
コード例 #2
0
 private function addSchedule(\DateTime $start, \DateInterval $diff, \Club\TeamBundle\Entity\Schedule $schedule)
 {
     // only count when we are in the future to get the following
     if ($start->getTimestamp() > time()) {
         $this->future_occur++;
     }
     $this->occur++;
     $parent = $schedule->getSchedule() ? $schedule->getSchedule() : $schedule;
     $res = $this->em->createQueryBuilder()->select('s')->from('ClubTeamBundle:Schedule', 's')->where('s.first_date = :date')->andWhere('(s.schedule = :id OR s.id = :id)')->setParameter('date', $start->format('Y-m-d H:i:s'))->setParameter('id', $parent->getId())->getQuery()->getResult();
     if (count($res)) {
         return;
     }
     // find new times
     $new_format = $start->format('Y-m-d') . ' ' . $schedule->getFirstDate()->format('H:i:s');
     if ($new_format == $schedule->getFirstDate()->format('Y-m-d H:i:s')) {
         return;
     }
     $new_first = new \DateTime($new_format);
     $new_end = new \DateTime($new_format);
     $new_end->add($diff);
     // make new schedule
     $new = new \Club\TeamBundle\Entity\Schedule();
     $new->setDescription($schedule->getDescription());
     $new->setMaxAttend($schedule->getMaxAttend());
     $new->setPenalty($schedule->getPenalty());
     $new->setFirstDate($new_first);
     $new->setEndDate($new_end);
     $new->setTeamCategory($schedule->getTeamCategory());
     $new->setLevel($schedule->getLevel());
     $new->setLocation($schedule->getLocation());
     $new->setSchedule($parent);
     foreach ($schedule->getInstructors() as $instructor) {
         $new->addInstructor($instructor);
     }
     foreach ($schedule->getFields() as $field) {
         $new->addField($field);
     }
     $this->em->persist($new);
     return $new;
 }