Exemplo n.º 1
0
 /**
  * @Route("/schedule/{day}", defaults={"day" = "current"}, name="user_schedule")
  * @Template()
  */
 public function scheduleAction($day = 'current')
 {
     if (!$this->getUserLayer()->isStudent()) {
         return $this->createAccessDeniedResponse();
     }
     /** @var $em EntityManager */
     $em = $this->getDoctrine()->getManager();
     /** @var $myCourses Course[] */
     $courses = $em->getRepository('EtuUserBundle:Course')->findByUser($this->getUser());
     // Builder to create the schedule
     $builder = new ScheduleBuilder();
     foreach ($courses as $course) {
         $builder->addCourse($course);
     }
     $days = array(Course::DAY_MONDAY, Course::DAY_TUESDAY, Course::DAY_WENESDAY, Course::DAY_THURSDAY, Course::DAY_FRIDAY, Course::DAY_SATHURDAY);
     if (!in_array($day, $days)) {
         if (date('w') == 0) {
             // Sunday
             $day = Course::DAY_MONDAY;
         } else {
             $day = $days[date('w') - 1];
         }
     }
     return array('courses' => $builder->build(), 'currentDay' => $day);
 }
Exemplo n.º 2
0
 /**
  * @Route("/user/{login}/schedule/{day}", defaults={"day" = "current"}, name="user_view_schedule")
  * @Template()
  */
 public function scheduleAction($login, $day = 'current')
 {
     if (!$this->getUserLayer()->isConnected()) {
         return $this->createAccessDeniedResponse();
     }
     /** @var $em EntityManager */
     $em = $this->getDoctrine()->getManager();
     if ($login != $this->getUser()->getLogin()) {
         /** @var $user User */
         $user = $em->getRepository('EtuUserBundle:User')->findOneBy(array('login' => $login));
         if (!$user) {
             throw $this->createNotFoundException('Login "' . $login . '" not found');
         }
     } else {
         $user = $this->getUser();
     }
     $from = null;
     if (in_array($this->getRequest()->get('from'), array('search', 'profile', 'trombi', 'admin'))) {
         $from = $this->getRequest()->get('from');
     }
     /** @var $courses Course[] */
     $courses = $em->getRepository('EtuUserBundle:Course')->findByUser($user);
     // Builder to create the schedule
     $builder = new ScheduleBuilder();
     foreach ($courses as $course) {
         $builder->addCourse($course);
     }
     $days = array(Course::DAY_MONDAY, Course::DAY_TUESDAY, Course::DAY_WENESDAY, Course::DAY_THURSDAY, Course::DAY_FRIDAY, Course::DAY_SATHURDAY);
     if (!in_array($day, $days)) {
         if (date('w') == 0) {
             // Sunday
             $day = Course::DAY_MONDAY;
         } else {
             $day = $days[date('w') - 1];
         }
     }
     return array('courses' => $builder->build(), 'currentDay' => $day, 'user' => $user, 'from' => $from);
 }