* Just add elements to the form as needed and return the list of IDs. The * system will call disabledIf and handle other behaviour for each returned * ID. * @return array Array of string IDs of added items, empty array if none */ function add_completion_rules() { return array(); } /** * Called during validation. Override to indicate, based on the data, whether * a custom completion rule is enabled (selected). * * @param array $data Input data (not yet validated) * @return bool True if one or more rules is enabled, false if none are; * default returns false */ function completion_rule_enabled($data) { return false; } function standard_hidden_coursemodule_elements(){ $mform =& $this->_form; $mform->addElement('hidden', 'course', 0); $mform->setType('course', PARAM_INT); $mform->addElement('hidden', 'coursemodule', 0); $mform->setType('coursemodule', PARAM_INT); $mform->addElement('hidden', 'section', 0); $mform->setType('section', PARAM_INT); $mform->addElement('hidden', 'module', 0); $mform->setType('module', PARAM_INT); $mform->addElement('hidden', 'modulename', ''); $mform->setType('modulename', PARAM_PLUGIN); $mform->addElement('hidden', 'instance', 0); $mform->setType('instance', PARAM_INT); $mform->addElement('hidden', 'add', 0); $mform->setType('add', PARAM_ALPHA); $mform->addElement('hidden', 'update', 0); $mform->setType('update', PARAM_INT); $mform->addElement('hidden', 'return', 0); $mform->setType('return', PARAM_BOOL); $mform->addElement('hidden', 'sr', 0); $mform->setType('sr', PARAM_INT); } public function standard_grading_coursemodule_elements() { global $COURSE, $CFG; $mform =& $this->_form; $isupdate = !empty($this->_cm); $gradeoptions = array('isupdate' => $isupdate, 'currentgrade' => false, 'hasgrades' => false, 'canrescale' => $this->_features->canrescale, 'useratings' => $this->_features->rating); if ($this->_features->hasgrades) { if (!$this->_features->rating || $this->_features->gradecat) { $mform->addElement('header', 'modstandardgrade', get_string('grade')); } //if supports grades and grades arent being handled via ratings if (!$this->_features->rating) { if ($isupdate) { $gradeitem = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => $this->_cm->modname, 'iteminstance' => $this->_cm->instance, 'itemnumber' => 0, 'courseid' => $COURSE->id)); if ($gradeitem) { $gradeoptions['currentgrade'] = $gradeitem->grademax; $gradeoptions['currentgradetype'] = $gradeitem->gradetype; $gradeoptions['currentscaleid'] = $gradeitem->scaleid; $gradeoptions['hasgrades'] = $gradeitem->has_grades(); } } $mform->addElement('modgrade', 'grade', get_string('grade'), $gradeoptions); $mform->addHelpButton('grade', 'modgrade', 'grades'); $mform->setDefault('grade', $CFG->gradepointdefault); } if ($this->_features->advancedgrading and !empty($this->current->_advancedgradingdata['methods']) and !empty($this->current->_advancedgradingdata['areas'])) { if (count($this->current->_advancedgradingdata['areas']) == 1) { // if there is just one gradable area (most cases), display just the selector // without its name to make UI simplier $areadata = reset($this->current->_advancedgradingdata['areas']); $areaname = key($this->current->_advancedgradingdata['areas']); $mform->addElement('select', 'advancedgradingmethod_'.$areaname, get_string('gradingmethod', 'core_grading'), $this->current->_advancedgradingdata['methods']); $mform->addHelpButton('advancedgradingmethod_'.$areaname, 'gradingmethod', 'core_grading'); if (!$this->_features->rating) { $mform->hideIf('advancedgradingmethod_'.$areaname, 'grade[modgrade_type]', 'eq', 'none'); } } else { // the module defines multiple gradable areas, display a selector // for each of them together with a name of the area $areasgroup = array(); foreach ($this->current->_advancedgradingdata['areas'] as $areaname => $areadata) { $areasgroup[] = $mform->createElement('select', 'advancedgradingmethod_'.$areaname, $areadata['title'], $this->current->_advancedgradingdata['methods']); $areasgroup[] = $mform->createElement('static', 'advancedgradingareaname_'.$areaname, '', $areadata['title']); } $mform->addGroup($areasgroup, 'advancedgradingmethodsgroup', get_string('gradingmethods', 'core_grading'), array(' ', ''), false); } } if ($this->_features->gradecat) { $mform->addElement('select', 'gradecat', get_string('gradecategoryonmodform', 'grades'), grade_get_categories_menu($COURSE->id, $this->_outcomesused)); $mform->addHelpButton('gradecat', 'gradecategoryonmodform', 'grades'); if (!$this->_features->rating) { $mform->hideIf('gradecat', 'grade[modgrade_type]', 'eq', 'none'); } } // Grade to pass. $mform->addElement('text', 'gradepass', get_string('gradepass', 'grades')); $mform->addHelpButton('gradepass', 'gradepass', 'grades'); $mform->setDefault('gradepass', ''); $mform->setType('gradepass', PARAM_RAW); if (!$this->_features->rating) { $mform->hideIf('gradepass', 'grade[modgrade_type]', 'eq', 'none'); } else { $mform->hideIf('gradepass', 'assessed', 'eq', '0'); } } } /** * Add an editor for an activity's introduction field. * @deprecated since MDL-49101 - use moodleform_mod::standard_intro_elements() instead. * @param null $required Override system default for requiremodintro * @param null $customlabel Override default label for editor * @throws coding_exception */ protected function add_intro_editor($required=null, $customlabel=null) { $str = "Function moodleform_mod::add_intro_editor() is deprecated, use moodleform_mod::standard_intro_elements() instead."; debugging($str, DEBUG_DEVELOPER); $this->standard_intro_elements($customlabel); } /** * Add an editor for an activity's introduction field. * * @param null $customlabel Override default label for editor * @throws coding_exception */ protected function standard_intro_elements($customlabel=null) { global $CFG; $required = $CFG->requiremodintro; $mform = $this->_form; $label = is_null($customlabel) ? get_string('moduleintro') : $customlabel; $mform->addElement('editor', 'introeditor', $label, array('rows' => 10), array('maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean' => true, 'context' => $this->context, 'subdirs' => true)); $mform->setType('introeditor', PARAM_RAW); // no XSS prevention here, users must be trusted if ($required) { $mform->addRule('introeditor', get_string('required'), 'required', null, 'client'); } // If the 'show description' feature is enabled, this checkbox appears below the intro. // We want to hide that when using the singleactivity course format because it is confusing. if ($this->_features->showdescription && $this->courseformat->has_view_page()) { $mform->addElement('advcheckbox', 'showdescription', get_string('showdescription')); $mform->addHelpButton('showdescription', 'showdescription'); } } /** * Overriding formslib's add_action_buttons() method, to add an extra submit "save changes and return" button. * * @param bool $cancel show cancel button * @param string $submitlabel null means default, false means none, string is label text * @param string $submit2label null means default, false means none, string is label text * @return void */ function add_action_buttons($cancel=true, $submitlabel=null, $submit2label=null) { if (is_null($submitlabel)) { $submitlabel = get_string('savechangesanddisplay'); } if (is_null($submit2label)) { $submit2label = get_string('savechangesandreturntocourse'); } $mform = $this->_form; // elements in a row need a group $buttonarray = array(); // Label for the submit button to return to the course. // Ignore this button in single activity format because it is confusing. if ($submit2label !== false && $this->courseformat->has_view_page()) { $buttonarray[] = &$mform->createElement('submit', 'submitbutton2', $submit2label); } if ($submitlabel !== false) { $buttonarray[] = &$mform->createElement('submit', 'submitbutton', $submitlabel); } if ($cancel) { $buttonarray[] = &$mform->createElement('cancel'); } $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false); $mform->setType('buttonar', PARAM_RAW); $mform->closeHeaderBefore('buttonar'); } /** * Get the list of admin settings for this module and apply any locked settings. * This cannot happen in apply_admin_defaults because we do not the current values of the settings * in that function because set_data has not been called yet. * * @return void */ protected function apply_admin_locked_flags() { global $OUTPUT; if (!$this->applyadminlockedflags) { return; } $settings = get_config($this->_modname); $mform = $this->_form; $lockedicon = html_writer::tag('span', $OUTPUT->pix_icon('t/locked', get_string('locked', 'admin')), array('class' => 'action-icon')); $isupdate = !empty($this->_cm); foreach ($settings as $name => $value) { if (strpos('_', $name) !== false) { continue; } if ($mform->elementExists($name)) { $element = $mform->getElement($name); $lockedsetting = $name . '_locked'; if (!empty($settings->$lockedsetting)) { // Always lock locked settings for new modules, // for updates, only lock them if the current value is the same as the default (or there is no current value). $value = $settings->$name; if ($isupdate && isset($this->current->$name)) { $value = $this->current->$name; } if ($value == $settings->$name) { $mform->setConstant($name, $settings->$name); $element->setLabel($element->getLabel() . $lockedicon); // Do not use hardfreeze because we need the hidden input to check dependencies. $element->freeze(); } } } } } /** * Get the list of admin settings for this module and apply any defaults/advanced/locked settings. * * @param $datetimeoffsets array - If passed, this is an array of fieldnames => times that the * default date/time value should be relative to. If not passed, all * date/time fields are set relative to the users current midnight. * @return void */ public function apply_admin_defaults($datetimeoffsets = array()) { // This flag triggers the settings to be locked in apply_admin_locked_flags(). $this->applyadminlockedflags = true; $settings = get_config($this->_modname); $mform = $this->_form; $usermidnight = usergetmidnight(time()); $isupdate = !empty($this->_cm); foreach ($settings as $name => $value) { if (strpos('_', $name) !== false) { continue; } if ($mform->elementExists($name)) { $element = $mform->getElement($name); if (!$isupdate) { if ($element->getType() == 'date_time_selector') { $enabledsetting = $name . '_enabled'; if (empty($settings->$enabledsetting)) { $mform->setDefault($name, 0); } else { $relativetime = $usermidnight; if (isset($datetimeoffsets[$name])) { $relativetime = $datetimeoffsets[$name]; } $mform->setDefault($name, $relativetime + $settings->$name); } } else { $mform->setDefault($name, $settings->$name); } } $advancedsetting = $name . '_adv'; if (!empty($settings->$advancedsetting)) { $mform->setAdvanced($name); } } } } /** * Allows modules to modify the data returned by form get_data(). * This method is also called in the bulk activity completion form. * * Only available on moodleform_mod. * * @param stdClass $data passed by reference */ public function data_postprocessing($data) { } /** * Return submitted data if properly submitted or returns NULL if validation fails or * if there is no submitted data. * * Do not override this method, override data_postprocessing() instead. * * @return object submitted data; NULL if not valid or not submitted or cancelled */ public function get_data() { $data = parent::get_data(); if ($data) { // Convert the grade pass value - we may be using a language which uses commas, // rather than decimal points, in numbers. These need to be converted so that // they can be added to the DB. if (isset($data->gradepass)) { $data->gradepass = unformat_float($data->gradepass); } $this->data_postprocessing($data); } return $data; } }