예제 #1
0
 public function createComponentFormAddTerm($name)
 {
     Form::extensionMethod('addDatePicker', array($this, 'Form_addDatePicker'));
     Form::extensionMethod('addTimePicker', array($this, 'Form_addTimePicker'));
     Form::extensionMethod('addNumericUpDown', array($this, 'Form_addNumericUpDown'));
     $form = new LiveForm($this, $name);
     $form->getElementPrototype()->class('ajax');
     $form->addGroup('Exam room and time');
     $rooms = SchoolManager::getRooms();
     $rooms = array('0' => 'Please select') + $rooms;
     $form->addSelect('room', 'Room', $rooms)->addRule(Form::FILLED, 'Please select a room')->skipFirst();
     $form->addDatePicker('start_date', 'Date', 10)->addRule(Form::FILLED, 'Please select a starting date');
     $form->addTimePicker('start_date_time', 'Start time', 10)->addRule(Form::FILLED, 'Please select a starting time');
     $form->addGroup('Application deadline');
     $form->addDatePicker('deadline_date', 'Date', 10)->addRule(Form::FILLED, 'Please select an application deadline date');
     $form->addTimePicker('deadline_date_time', 'Time', 10)->addRule(Form::FILLED, 'Please select an application deadline time');
     $form->addGroup('Conditions');
     $form->addText('max_students', 'Student limit')->addRule(Form::FILLED, 'Please enter a student limit.')->addRule(Form::NUMERIC, 'Limit must be numeric');
     $form->addText('min_seminar_points', 'Minimum points')->addCondition(Form::FILLED)->addRule(Form::NUMERIC, 'Limit must be numeric');
     $form->addGroup('Note')->setOption('container', Html::el('fieldset')->class('no-label'));
     $form->addTextArea('note');
     $form->addHidden('course_id')->setValue($this->course_id);
     $form->addHidden('id');
     $form->addSubmit('btnSubmit', 'Save')->onClick[] = callback($this, 'FormAddTermSubmitted');
     if ($this->isSignalReceiver($this[$name])) {
         $this->template->show_popup = true;
     }
     if (isset($this->exam_id)) {
         $session = Environment::getSession('exam_terms_edit_form_' . $this->exam_id);
         if (isset($session['form_data'])) {
             $form_data = $session->form_data;
         } else {
             $form_data = ExamManager::getExam($this->exam_id);
             $form_data->start_date = $form_data->start_datetime;
             $form_data->deadline_date = $form_data->application_deadline;
             $form_data->start_date_time = $form_data->start_datetime;
             $form_data->deadline_date_time = $form_data->application_deadline;
             $session->form_data = $form_data;
         }
         $form->setDefaults($form_data);
         $form['id']->setValue($this->exam_id);
     }
     return $form;
 }