public function load_choices() { global $CFG; if (is_array($this->choices)) { return true; } require_once $CFG->dirroot . '/mod/treasurehunt/locallib.php'; $this->choices = treasurehunt_get_grading_options(); return true; }
/** * Render the info containing the current status of the treasure hunt. * * @param render_treasurehunt_info $info * @return string */ public function render_treasurehunt_info(treasurehunt_info $info) { // Create a table for the data. $o = ''; $notavailable = false; $o .= $this->output->container_start('treasurehuntinfo'); if ($info->timenow < $info->treasurehunt->allowattemptsfromdate) { $notavailable = true; $message = get_string('treasurehuntnotavailable', 'treasurehunt', userdate($info->treasurehunt->allowattemptsfromdate)); $o .= html_writer::tag('p', $message) . "\n"; if ($info->treasurehunt->cutoffdate) { $message = get_string('treasurehuntcloseson', 'treasurehunt', userdate($info->treasurehunt->cutoffdate)); $o .= html_writer::tag('p', $message) . "\n"; } } else { if ($info->treasurehunt->cutoffdate && $info->timenow > $info->treasurehunt->cutoffdate) { $message = get_string('treasurehuntclosed', 'treasurehunt', userdate($info->treasurehunt->cutoffdate)); $o .= html_writer::tag('p', $message) . "\n"; } else { if ($info->treasurehunt->allowattemptsfromdate) { $message = get_string('treasurehuntopenedon', 'treasurehunt', userdate($info->treasurehunt->allowattemptsfromdate)); $o .= html_writer::tag('p', $message) . "\n"; } if ($info->treasurehunt->cutoffdate) { $message = get_string('treasurehuntcloseson', 'treasurehunt', userdate($info->treasurehunt->cutoffdate)); $o .= html_writer::tag('p', $message) . "\n"; } } } if ($info->treasurehunt->playwithoutmoving) { $gamemode = get_string('playwithoutmoving', 'treasurehunt'); } else { $gamemode = get_string('movingplay', 'treasurehunt'); } if ($info->treasurehunt->groupmode) { $gamemode = get_string('groupmode', 'treasurehunt') . '. ' . $gamemode; } $message = get_string('gamemodeinfo', 'treasurehunt', $gamemode); $o .= html_writer::tag('p', $message) . "\n"; if ($info->treasurehunt->grade > 0) { $options = treasurehunt_get_grading_options(); $message = get_string('grademethodinfo', 'treasurehunt', $options[$info->treasurehunt->grademethod]); $o .= html_writer::tag('p', $message . $this->help_icon('grademethod', 'treasurehunt')) . "\n"; } if ($notavailable) { $urlparams = array('id' => $info->courseid); $o .= $this->output->single_button(new moodle_url('/course/view.php', $urlparams), get_string('backtocourse', 'treasurehunt'), 'get', array('class' => 'continuebutton')); } // Close the container and insert a spacer. $o .= $this->output->container_end(); return $o; }
/** * Defines forms elements */ public function definition() { $treasurehuntconfig = get_config('mod_treasurehunt'); $mform = $this->_form; // Adding the "general" fieldset, where all the common settings are showed. $mform->addElement('header', 'general', get_string('general', 'form')); // Adding the standard "name" field. $mform->addElement('text', 'name', get_string('treasurehuntname', 'treasurehunt'), array('size' => '64')); if (!empty($CFG->formatstringstriptags)) { $mform->setType('name', PARAM_TEXT); } else { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); //Aquí añadimos la regla del tamaño máximo de la cadena. $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); // Adding the standard "intro" and "introformat" fields. Esto sirve para poner la descripción, si quieres // ... que aparezca en la portada, etc. $this->standard_intro_elements(); $mform->addElement('advcheckbox', 'playwithoutmoving', get_string('playwithoutmoving', 'treasurehunt')); $mform->addHelpButton('playwithoutmoving', 'playwithoutmoving', 'treasurehunt'); // Adding the rest of treasurehunt settings, spreading all them into this fieldset // ... or adding more fieldsets ('header' elements) if needed for better logic. $mform->addElement('header', 'availability', get_string('availability', 'treasurehunt')); $mform->setExpanded('availability', true); $name = get_string('allowattemptsfromdate', 'treasurehunt'); $options = array('optional' => true, 'step' => 1); $mform->addElement('date_time_selector', 'allowattemptsfromdate', $name, $options); $mform->addHelpButton('allowattemptsfromdate', 'allowattemptsfromdate', 'treasurehunt'); $name = get_string('cutoffdate', 'treasurehunt'); $mform->addElement('date_time_selector', 'cutoffdate', $name, $options); $mform->addHelpButton('cutoffdate', 'cutoffdate', 'treasurehunt'); $name = get_string('alwaysshowdescription', 'treasurehunt'); $mform->addElement('checkbox', 'alwaysshowdescription', $name); $mform->addHelpButton('alwaysshowdescription', 'alwaysshowdescription', 'treasurehunt'); $mform->disabledIf('alwaysshowdescription', 'allowsubmissionsfromdate[enabled]', 'notchecked'); $mform->addElement('header', 'groups', get_string('groups', 'treasurehunt')); $mform->setExpanded('groups', true); $mform->addElement('advcheckbox', 'groupmode', get_string('groupmode', 'treasurehunt')); $mform->addHelpButton('groupmode', 'groupmode', 'treasurehunt'); // Add standard grading elements. Calificación. $this->standard_grading_coursemodule_elements(); // If is not an update. if (empty($this->_cm)) { $mform->setDefault('grade[modgrade_type]', 'point'); } if (isset($this->current->grade) && !($this->current->grade > 0) || empty($this->_cm)) { $mform->setDefault('grade[modgrade_point]', $treasurehuntconfig->maximumgrade); } // Grading method. $mform->addElement('select', 'grademethod', get_string('grademethod', 'treasurehunt'), treasurehunt_get_grading_options()); $mform->addHelpButton('grademethod', 'grademethod', 'treasurehunt'); $mform->setDefault('grademethod', $treasurehuntconfig->grademethod); $mform->disabledIf('grademethod', 'grade[modgrade_type]', 'neq', 'point'); // Grading penalization. $mform->addElement('text', 'gradepenlocation', get_string('gradepenlocation', 'treasurehunt')); $mform->addHelpButton('gradepenlocation', 'gradepenlocation', 'treasurehunt'); $mform->setType('gradepenlocation', PARAM_FLOAT); $mform->setDefault('gradepenlocation', $treasurehuntconfig->penaltylocation); $mform->addRule('gradepenlocation', get_string('errnumeric', 'treasurehunt'), 'numeric', null, 'client'); $mform->disabledIf('gradepenlocation', 'grade[modgrade_type]', 'neq', 'point'); $mform->addElement('text', 'gradepenanswer', get_string('gradepenanswer', 'treasurehunt')); $mform->addHelpButton('gradepenanswer', 'gradepenlocation', 'treasurehunt'); $mform->setType('gradepenanswer', PARAM_FLOAT); $mform->setDefault('gradepenanswer', $treasurehuntconfig->penaltyanswer); $mform->addRule('gradepenanswer', get_string('errnumeric', 'treasurehunt'), 'numeric', null, 'client'); $mform->disabledIf('gradepenanswer', 'grade[modgrade_type]', 'neq', 'point'); // Add standard elements, common to all modules. Ajustes comunes (Visibilidad, número ID y modo grupo). $this->standard_coursemodule_elements(); // Add standard buttons, common to all modules. Botones. $this->add_action_buttons($cancel = true); }