Exemplo n.º 1
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;
 }
Exemplo n.º 2
0
 public function action_publish()
 {
     $examgroup_id = $this->request->param('examgroup_id');
     $examgroups = ORM::factory('examgroup', $examgroup_id);
     $examgroups->publish = 1;
     $examgroups->save();
     $users = Model_Examgroup::get_students($examgroup_id, 'object');
     $feed = new Feed_Exam();
     $feed->set_action('publish_result');
     $feed->set_respective_id($examgroup_id);
     $feed->set_actor_id(Auth::instance()->get_user()->id);
     $feed->save();
     $feed->subscribe_users($users);
     Request::current()->redirect('examresult/edit/examgroup_id/' . $examgroup_id);
     exit;
 }