public function definition() { $mform =& $this->_form; urkund_get_form_elements($mform); $this->add_action_buttons(true); }
/** * hook to add plagiarism specific settings to a module settings page * @param object $mform - Moodle form * @param object $context - current context */ public function get_form_elements_module($mform, $context, $modulename = "") { global $DB, $PAGE, $CFG; $plagiarismsettings = $this->get_settings(); if (!$plagiarismsettings) { return; } $cmid = optional_param('update', 0, PARAM_INT); // Get cm as $this->_cm is not available here. if (!empty($modulename)) { $modname = 'urkund_enable_' . $modulename; if (empty($plagiarismsettings[$modname])) { return; // Return if urkund is not enabled for the module. } } if (!empty($cmid)) { $plagiarismvalues = $DB->get_records_menu('plagiarism_urkund_config', array('cm' => $cmid), '', 'name, value'); } // Get Defaults - cmid(0) is the default list. $plagiarismdefaults = $DB->get_records_menu('plagiarism_urkund_config', array('cm' => 0), '', 'name, value'); $plagiarismelements = $this->config_options(); if (has_capability('plagiarism/urkund:enable', $context)) { urkund_get_form_elements($mform); if ($mform->elementExists('urkund_draft_submit') && $mform->elementExists('submissiondrafts')) { $mform->disabledIf('urkund_draft_submit', 'submissiondrafts', 'eq', 0); } // Disable all plagiarism elements if use_plagiarism eg 0. foreach ($plagiarismelements as $element) { if ($element != 'use_urkund') { // Ignore this var. $mform->disabledIf($element, 'use_urkund', 'eq', 0); } } // Check if files have been submitted and we need to disable the receiver address. if ($DB->record_exists('plagiarism_urkund_files', array('cm' => $cmid, 'statuscode' => 'pending'))) { $mform->disabledIf('urkund_receiver', 'use_urkund'); } $mform->disabledIf('urkund_selectfiletypes', 'urkund_allowallfile', 'eq', 1); } else { // Add plagiarism settings as hidden vars. foreach ($plagiarismelements as $element) { $mform->addElement('hidden', $element); $mform->setType('use_urkund', PARAM_INT); $mform->setType('urkund_show_student_score', PARAM_INT); $mform->setType('urkund_show_student_report', PARAM_INT); $mform->setType('urkund_draft_submit', PARAM_INT); $mform->setType('urkund_receiver', PARAM_TEXT); $mform->setType('urkund_studentemail', PARAM_INT); } } // Now set defaults. foreach ($plagiarismelements as $element) { if (isset($plagiarismvalues[$element])) { $mform->setDefault($element, $plagiarismvalues[$element]); } else { if ($element == 'urkund_receiver') { $def = get_user_preferences($element); if (!empty($def)) { $mform->setDefault($element, $def); } else { if (isset($plagiarismdefaults[$element])) { $mform->setDefault($element, $plagiarismdefaults[$element]); } } } else { if (isset($plagiarismdefaults[$element])) { $mform->setDefault($element, $plagiarismdefaults[$element]); } } } } $mform->registerRule('urkundvalidatereceiver', null, 'urkundvalidatereceiver', $CFG->dirroot . '/plagiarism/urkund/form_customrule.php'); $mform->addRule('urkund_receiver', get_string('receivernotvalid', 'plagiarism_urkund'), 'urkundvalidatereceiver'); // Now add JS to validate receiver indicator using Ajax. if (has_capability('plagiarism/urkund:enable', $context)) { $jsmodule = array('name' => 'plagiarism_urkund', 'fullpath' => '/plagiarism/urkund/checkreceiver.js', 'requires' => array('json')); $PAGE->requires->js_init_call('M.plagiarism_urkund.init', array($context->instanceid), true, $jsmodule); } // Now set some fields as advanced options. $mform->setAdvanced('urkund_allowallfile'); $mform->setAdvanced('urkund_selectfiletypes'); // Now handle content restriction settings. if ($modulename == 'mod_assign' && $mform->elementExists("submissionplugins")) { // This should be mod_assign // I can't see a way to check if a particular checkbox exists // elementExists on the checkbox name doesn't work. $mform->disabledIf('urkund_restrictcontent', 'assignsubmission_onlinetext_enabled'); $mform->setAdvanced('urkund_restrictcontent'); } else { if ($modulename != 'mod_forum') { // Forum doesn't need any changes but all other modules should disable this. $mform->setDefault('urkund_restrictcontent', 0); $mform->hardFreeze('urkund_restrictcontent'); $mform->setAdvanced('urkund_restrictcontent'); } } }