Esempio n. 1
0
 /**
  * items in the form
  *
  * @uses $USER
  */
 public function definition()
 {
     global $USER;
     $fields = field::get_for_context_level('track');
     foreach ($fields as $rec) {
         $field = new field($rec);
         if (strcmp($field->datatype, "num") == 0) {
             $fieldname = "field_{$field->shortname}";
             if (isset($this->_customdata['obj']->{$fieldname})) {
                 $formatnum = $field->format_number($this->_customdata['obj']->{$fieldname});
                 $this->_customdata['obj']->{$fieldname} = $formatnum;
             }
         }
     }
     $this->set_data($this->_customdata['obj']);
     $mform =& $this->_form;
     $mform->addElement('hidden', 'id');
     $mform->setType('id', PARAM_INT);
     $curs = array();
     if (!empty($USER->id)) {
         // TBD: and/or capability 'local/elisprogram:track_edit|view' ?
         // This is necessary for creating a new track but will prevent a parent programs from appearing
         // when the user has track edit permissions but not track creation permission -- ELIS-5954
         $contexts = get_contexts_by_capability_for_user('curriculum', 'local/elisprogram:track_create', $USER->id);
         $curs = curriculum_get_listing('name', 'ASC', 0, 0, '', '', $contexts);
     }
     if (empty($this->_customdata['obj']->id)) {
         $curid_options = array();
         if (!empty($curs)) {
             foreach ($curs as $cur) {
                 $curid_options[$cur->id] = '(' . $cur->idnumber . ') ' . $cur->name;
             }
         }
         $mform->addElement('select', 'curid', get_string('curriculum', 'local_elisprogram') . ':', $curid_options);
         $mform->addRule('curid', get_string('required'), 'required', NULL, 'client');
         $mform->addHelpButton('curid', 'trackform:curriculum_curid', 'local_elisprogram');
     } else {
         // Track editing, do not allow the user to change curriculum
         // Make sure that the parent program for this track is always included otherwise the display is messed up
         // and hitting the form Cancel button causes a DB error -- ELIS-5954
         $track = new track($this->_customdata['obj']->id);
         $curs = curriculum_get_listing('name', 'ASC', 0, 0, $track->curriculum->name);
         $mform->addElement('static', 'curidstatic', get_string('curriculum', 'local_elisprogram') . ':', $curs[$this->_customdata['obj']->curid]->name);
         $mform->addHelpButton('curidstatic', 'trackform:curriculum_curidstatic', 'local_elisprogram');
         $mform->addElement('hidden', 'curid');
         $mform->setType('curid', PARAM_INT);
     }
     $mform->addElement('text', 'idnumber', get_string('track_idnumber', 'local_elisprogram') . ':');
     $mform->setType('idnumber', PARAM_TEXT);
     $mform->addRule('idnumber', get_string('required'), 'required', NULL, 'client');
     $mform->addRule('idnumber', null, 'maxlength', 100);
     $mform->addHelpButton('idnumber', 'trackform:track_idnumber', 'local_elisprogram');
     $mform->addElement('text', 'name', get_string('track_name', 'local_elisprogram') . ':');
     $mform->setType('name', PARAM_TEXT);
     $mform->addRule('name', null, 'maxlength', 255);
     $mform->addRule('name', get_string('required'), 'required', NULL, 'client');
     $mform->addHelpButton('name', 'trackform:track_name', 'local_elisprogram');
     $mform->addElement('textarea', 'description', get_string('track_description', 'local_elisprogram') . ':');
     $mform->setType('description', PARAM_CLEAN);
     $mform->addHelpButton('description', 'trackform:track_description', 'local_elisprogram');
     $mform->addElement('date_selector', 'startdate', get_string('track_startdate', 'local_elisprogram') . ':', array('optional' => true));
     $mform->addElement('date_selector', 'enddate', get_string('track_enddate', 'local_elisprogram') . ':', array('optional' => true));
     $mform->addHelpButton('startdate', 'trackform:track_startdate', 'local_elisprogram');
     if (!empty($this->_customdata['obj']->id)) {
         $trackassignobj = new trackassignment(array('trackid' => $this->_customdata['obj']->id));
     }
     // Only show auto-create checkbox if the track does not have any classes assigned
     if (!isset($trackassignobj) || 0 == $trackassignobj->count_assigned_classes_from_track()) {
         $mform->addElement('checkbox', 'autocreate', get_string('track_autocreate', 'local_elisprogram') . ':');
         $mform->addHelpButton('autocreate', 'trackform:track_autocreate', 'local_elisprogram');
     }
     // custom fields
     $this->add_custom_fields('track', 'local/elisprogram:track_edit', 'local/elisprogram:track_view', 'curriculum');
     $this->add_action_buttons();
 }