Пример #1
0
 /**
  * Create elements for this group.
  */
 public function _createElements()
 {
     global $COURSE, $CFG, $OUTPUT;
     $attributes = $this->getAttributes();
     if (is_null($attributes)) {
         $attributes = array();
     }
     $this->_elements = array();
     // Create main elements
     // We have to create the scale and point elements first, as we need their IDs.
     // Grade scale select box.
     $scales = get_scales_menu($COURSE->id);
     $langscale = get_string('modgradetypescale', 'grades');
     $this->scaleformelement = @MoodleQuickForm::createElement('select', 'modgrade_scale', $langscale, $scales, $attributes);
     $this->scaleformelement->setHiddenLabel = false;
     $scaleformelementid = $this->generate_modgrade_subelement_id('modgrade_scale');
     $this->scaleformelement->updateAttributes(array('id' => $scaleformelementid));
     // Maximum grade textbox.
     $langmaxgrade = get_string('modgrademaxgrade', 'grades');
     $this->maxgradeformelement = @MoodleQuickForm::createElement('text', 'modgrade_point', $langmaxgrade, array());
     $this->maxgradeformelement->setHiddenLabel = false;
     $maxgradeformelementid = $this->generate_modgrade_subelement_id('modgrade_point');
     $this->maxgradeformelement->updateAttributes(array('id' => $maxgradeformelementid));
     // Grade type select box.
     $gradetype = array('none' => get_string('modgradetypenone', 'grades'), 'scale' => get_string('modgradetypescale', 'grades'), 'point' => get_string('modgradetypepoint', 'grades'));
     $langtype = get_string('modgradetype', 'grades');
     $this->gradetypeformelement = @MoodleQuickForm::createElement('select', 'modgrade_type', $langtype, $gradetype, $attributes, true);
     $this->gradetypeformelement->setHiddenLabel = false;
     $gradetypeformelementid = $this->generate_modgrade_subelement_id('modgrade_type');
     $this->gradetypeformelement->updateAttributes(array('id' => $gradetypeformelementid));
     if ($this->isupdate && $this->hasgrades) {
         $this->gradetypeformelement->updateAttributes(array('disabled' => 'disabled'));
         $this->scaleformelement->updateAttributes(array('disabled' => 'disabled'));
         // Check box for options for processing existing grades.
         if ($this->canrescale) {
             $langrescalegrades = get_string('modgraderescalegrades', 'grades');
             $choices = array();
             $choices[''] = get_string('choose');
             $choices['no'] = get_string('no');
             $choices['yes'] = get_string('yes');
             $rescalegradesselect = @MoodleQuickForm::createElement('select', 'modgrade_rescalegrades', $langrescalegrades, $choices);
             $rescalegradesselect->setHiddenLabel = false;
             $rescalegradesselectid = $this->generate_modgrade_subelement_id('modgrade_rescalegrades');
             $rescalegradesselect->updateAttributes(array('id' => $rescalegradesselectid));
         }
     }
     // Add elements.
     if ($this->isupdate && $this->hasgrades) {
         // Set a message so the user knows why they can not alter the grade type or scale.
         if ($this->currentgradetype == 'scale') {
             $gradesexistmsg = get_string('modgradecantchangegradetyporscalemsg', 'grades');
         } else {
             $gradesexistmsg = get_string('modgradecantchangegradetypemsg', 'grades');
         }
         $gradesexisthtml = '<div class=\'alert\'>' . $gradesexistmsg . '</div>';
         $this->_elements[] = @MoodleQuickForm::createElement('static', 'gradesexistmsg', '', $gradesexisthtml);
     }
     // Grade type select box.
     $label = html_writer::tag('label', $this->gradetypeformelement->getLabel(), array('for' => $this->gradetypeformelement->getAttribute('id')));
     $this->_elements[] = @MoodleQuickForm::createElement('static', 'gradetypelabel', '', '&nbsp;' . $label);
     $this->_elements[] = $this->gradetypeformelement;
     $this->_elements[] = @MoodleQuickForm::createElement('static', 'gradetypespacer', '', '<br />');
     // Only show the grade scale select box when applicable.
     if (!$this->isupdate || !$this->hasgrades || $this->currentgradetype == 'scale') {
         $label = html_writer::tag('label', $this->scaleformelement->getLabel(), array('for' => $this->scaleformelement->getAttribute('id')));
         $this->_elements[] = @MoodleQuickForm::createElement('static', 'scalelabel', '', $label);
         $this->_elements[] = $this->scaleformelement;
         $this->_elements[] = @MoodleQuickForm::createElement('static', 'scalespacer', '', '<br />');
     }
     if ($this->isupdate && $this->hasgrades && $this->canrescale && $this->currentgradetype == 'point') {
         // We need to know how to apply any changes to maxgrade - ie to either update, or don't touch exising grades.
         $label = html_writer::tag('label', $rescalegradesselect->getLabel(), array('for' => $rescalegradesselect->getAttribute('id')));
         $labelhelp = new help_icon('modgraderescalegrades', 'grades');
         $this->_elements[] = @MoodleQuickForm::createElement('static', 'scalelabel', '', $label . $OUTPUT->render($labelhelp));
         $this->_elements[] = $rescalegradesselect;
         $this->_elements[] = @MoodleQuickForm::createElement('static', 'scalespacer', '', '<br />');
     }
     // Only show the max points form element when applicable.
     if (!$this->isupdate || !$this->hasgrades || $this->currentgradetype == 'point') {
         $label = html_writer::tag('label', $this->maxgradeformelement->getLabel(), array('for' => $this->maxgradeformelement->getAttribute('id')));
         $this->_elements[] = @MoodleQuickForm::createElement('static', 'pointlabel', '', $label);
         $this->_elements[] = $this->maxgradeformelement;
         $this->_elements[] = @MoodleQuickForm::createElement('static', 'pointspacer', '', '<br />');
     }
 }