예제 #1
0
 /**
  * Method to get the teacher associated with this event
  * In case- no teacher is associated, then return 0
  * @return mixed (null|Model_User)
  */
 public function associated_teacher()
 {
     $event = Event_Abstract::factory($this->eventtype, $this->id);
     if (method_exists($event, 'associated_teacher')) {
         return $event->associated_teacher();
     }
     return null;
 }
예제 #2
0
 public function action_get_avaliable_rooms()
 {
     $from = strtotime($this->request->post('date')) + $this->request->post('from') * 60;
     $to = strtotime($this->request->post('date')) + $this->request->post('to') * 60;
     $event_id = $this->request->post('event_id');
     $results = Event_Abstract::get_avaliable_rooms($from, $to, $event_id);
     $rooms = array();
     foreach ($results as $room) {
         $rooms[$room->id] = $room->room_number . ', ' . $room->room_name;
     }
     $room_id = 0;
     if ($event_id) {
         $event = ORM::factory('event', $event_id);
         $room = ORM::factory('room', $event->room_id);
         $room_id = $room->id;
     }
     $element = Form::select('room_id', $rooms, $room_id);
     echo json_encode(array('element' => $element));
 }
예제 #3
0
 public function action_edit()
 {
     $id = $this->request->param('id');
     if (!$id) {
         Request::current()->redirect('exam');
     }
     $submitted = FALSE;
     if ($this->request->method() === 'POST' && $this->request->post()) {
         if (Arr::get($this->request->post(), 'save') !== null) {
             $submitted = true;
             $exam = ORM::factory('exam');
             $validator = $exam->validator($this->request->post());
             $validator->bind(':to', $this->request->post('to'));
             $validator->bind(':total_marks', $this->request->post('total_marks'));
             if ($validator->check()) {
                 $from = strtotime($this->request->post('date')) + $this->request->post('from') * 60;
                 $to = strtotime($this->request->post('date')) + $this->request->post('to') * 60;
                 $exam = ORM::factory('exam', $id);
                 $exam->values($this->request->post());
                 $exam->save();
                 $event_exam = Event_Abstract::factory('exam', $exam->event_id);
                 $event_exam->set_values($this->request->post());
                 $event_exam->set_value('eventstart', $from);
                 $event_exam->set_value('eventend', $to);
                 $event_exam->update($exam->event_id);
                 // dispatch events for sending the notices and feeds (TODO to be refactored later)
                 if ($event_exam->is_rescheduled()) {
                     Event::instance('exam_reschedule')->set('exam', $exam)->execute();
                 }
                 if ($event_exam->is_relocated()) {
                     Event::instance('exam_relocate')->set('exam', $exam)->execute();
                 }
                 $feed = new Feed_Exam();
                 $feed->set_action('edit');
                 $feed->set_course_id($this->request->post('course_id'));
                 $feed->set_respective_id($exam->id);
                 $feed->set_actor_id(Auth::instance()->get_user()->id);
                 $feed->streams(array('course_id' => (int) $this->request->post('course_id')));
                 $feed->save();
                 Session::instance()->set('success', 'Exam edited successfully.');
                 Request::current()->redirect('exam');
                 exit;
             } else {
                 $this->_errors = $validator->errors('exam');
             }
         }
     }
     $exam = ORM::factory('exam', $id);
     $event = ORM::factory('event', $exam->event_id);
     $saved_data = array('name' => $exam->name, 'examgroup_id' => $exam->examgroup_id, 'course_id' => $exam->course_id, 'total_marks' => $exam->total_marks, 'passing_marks' => $exam->passing_marks, 'reminder' => $exam->reminder, 'reminder_days' => $exam->reminder_days, 'date' => date('Y-m-d', $event->eventstart), 'from' => date('H:i', $event->eventstart), 'to' => date('H:i', $event->eventend), 'room_id' => $event->room_id);
     $silder['start'] = ($event->eventstart - strtotime($saved_data['date'])) / 60;
     $silder['end'] = ($event->eventend - strtotime($saved_data['date'])) / 60;
     $form = $this->form('exam/edit/id/' . $id, $submitted, $saved_data);
     $event_id = $exam->event_id;
     $links = array('rooms' => Html::anchor('/room/', 'Add Rooms', array('target' => '_blank')));
     $view = View::factory('exam/form')->bind('form', $form)->bind('event_id', $event_id)->bind('links', $links)->bind('slider', $silder);
     Breadcrumbs::add(array('Exams', Url::site('exam')));
     Breadcrumbs::add(array('Edit', Url::site('exam/edit/id/' . $id)));
     $this->content = $view;
 }
예제 #4
0
 public function update($id)
 {
     parent::update($id);
 }
예제 #5
0
 public function action_schedule()
 {
     $id = $this->request->param('id');
     if (!$id) {
         Request::current()->redirect('lecture');
     }
     $lecture = ORM::factory('lecture', $id);
     $conflict_event_ids = Event_Abstract::get_room_conflict_events();
     $events = $lecture->events->find_all()->as_array();
     $view = View::factory('lecture/schedule')->bind('lecture', $lecture)->bind('events', $events)->bind('conflict_event_ids', $conflict_event_ids)->set('can_edit', Acl::instance()->is_allowed('exam_edit'));
     Breadcrumbs::add(array('Lectures', Url::site('lecture')));
     $this->content = $view;
 }
예제 #6
0
 public function add()
 {
     $this->set_value('eventtype', 'lecture');
     return parent::add();
 }