/** * Adds all the standard elements to a form to edit the settings for an activity module. */ function standard_coursemodule_elements() { global $COURSE, $CFG, $DB; $mform =& $this->_form; $this->_outcomesused = false; if ($this->_features->outcomes) { if ($outcomes = grade_outcome::fetch_all_available($COURSE->id)) { $this->_outcomesused = true; $mform->addElement('header', 'modoutcomes', get_string('outcomes', 'grades')); foreach ($outcomes as $outcome) { $mform->addElement('advcheckbox', 'outcome_' . $outcome->id, $outcome->get_name()); } } } if ($this->_features->rating) { require_once $CFG->dirroot . '/rating/lib.php'; $rm = new rating_manager(); $mform->addElement('header', 'modstandardratings', get_string('ratings', 'rating')); $permission = CAP_ALLOW; $rolenamestring = null; if (!empty($this->_cm)) { $context = context_module::instance($this->_cm->id); $rolenames = get_role_names_with_caps_in_context($context, array('moodle/rating:rate', 'mod/' . $this->_cm->modname . ':rate')); $rolenamestring = implode(', ', $rolenames); } else { $rolenamestring = get_string('capabilitychecknotavailable', 'rating'); } $mform->addElement('static', 'rolewarning', get_string('rolewarning', 'rating'), $rolenamestring); $mform->addHelpButton('rolewarning', 'rolewarning', 'rating'); $mform->addElement('select', 'assessed', get_string('aggregatetype', 'rating'), $rm->get_aggregate_types()); $mform->setDefault('assessed', 0); $mform->addHelpButton('assessed', 'aggregatetype', 'rating'); $mform->addElement('modgrade', 'scale', get_string('scale'), false); $mform->disabledIf('scale', 'assessed', 'eq', 0); $mform->addHelpButton('scale', 'modgrade', 'grades'); $mform->setDefault('scale', $CFG->gradepointdefault); $mform->addElement('checkbox', 'ratingtime', get_string('ratingtime', 'rating')); $mform->disabledIf('ratingtime', 'assessed', 'eq', 0); $mform->addElement('date_time_selector', 'assesstimestart', get_string('from')); $mform->disabledIf('assesstimestart', 'assessed', 'eq', 0); $mform->disabledIf('assesstimestart', 'ratingtime'); $mform->addElement('date_time_selector', 'assesstimefinish', get_string('to')); $mform->disabledIf('assesstimefinish', 'assessed', 'eq', 0); $mform->disabledIf('assesstimefinish', 'ratingtime'); } //doing this here means splitting up the grade related settings on the lesson settings page //$this->standard_grading_coursemodule_elements(); $mform->addElement('header', 'modstandardelshdr', get_string('modstandardels', 'form')); $mform->addElement('modvisible', 'visible', get_string('visible')); if (!empty($this->_cm)) { $context = context_module::instance($this->_cm->id); if (!has_capability('moodle/course:activityvisibility', $context)) { $mform->hardFreeze('visible'); } } if ($this->_features->idnumber) { $mform->addElement('text', 'cmidnumber', get_string('idnumbermod')); $mform->setType('cmidnumber', PARAM_RAW); $mform->addHelpButton('cmidnumber', 'idnumbermod'); } if ($this->_features->groups) { $options = array(NOGROUPS => get_string('groupsnone'), SEPARATEGROUPS => get_string('groupsseparate'), VISIBLEGROUPS => get_string('groupsvisible')); $mform->addElement('select', 'groupmode', get_string('groupmode', 'group'), $options, NOGROUPS); $mform->addHelpButton('groupmode', 'groupmode', 'group'); } if ($this->_features->groupings) { // Groupings selector - used to select grouping for groups in activity. $options = array(); if ($groupings = $DB->get_records('groupings', array('courseid' => $COURSE->id))) { foreach ($groupings as $grouping) { $options[$grouping->id] = format_string($grouping->name); } } core_collator::asort($options); $options = array(0 => get_string('none')) + $options; $mform->addElement('select', 'groupingid', get_string('grouping', 'group'), $options); $mform->addHelpButton('groupingid', 'grouping', 'group'); } if (!empty($CFG->enableavailability)) { // Add special button to end of previous section if groups/groupings // are enabled. if ($this->_features->groups || $this->_features->groupings) { $mform->addElement('static', 'restrictgroupbutton', '', html_writer::tag('button', get_string('restrictbygroup', 'availability'), array('id' => 'restrictbygroup', 'disabled' => 'disabled'))); } // Availability field. This is just a textarea; the user interface // interaction is all implemented in JavaScript. $mform->addElement('header', 'availabilityconditionsheader', get_string('restrictaccess', 'availability')); // Note: This field cannot be named 'availability' because that // conflicts with fields in existing modules (such as assign). // So it uses a long name that will not conflict. $mform->addElement('textarea', 'availabilityconditionsjson', get_string('accessrestrictions', 'availability')); // The _cm variable may not be a proper cm_info, so get one from modinfo. if ($this->_cm) { $modinfo = get_fast_modinfo($COURSE); $cm = $modinfo->get_cm($this->_cm->id); } else { $cm = null; } \core_availability\frontend::include_all_javascript($COURSE, $cm); } // Conditional activities: completion tracking section if (!isset($completion)) { $completion = new completion_info($COURSE); } if ($completion->is_enabled()) { $mform->addElement('header', 'activitycompletionheader', get_string('activitycompletion', 'completion')); // Unlock button for if people have completed it (will // be removed in definition_after_data if they haven't) $mform->addElement('submit', 'unlockcompletion', get_string('unlockcompletion', 'completion')); $mform->registerNoSubmitButton('unlockcompletion'); $mform->addElement('hidden', 'completionunlocked', 0); $mform->setType('completionunlocked', PARAM_INT); $trackingdefault = COMPLETION_TRACKING_NONE; // If system and activity default is on, set it. if ($CFG->completiondefault && $this->_features->defaultcompletion) { $trackingdefault = COMPLETION_TRACKING_MANUAL; } $mform->addElement('select', 'completion', get_string('completion', 'completion'), array(COMPLETION_TRACKING_NONE => get_string('completion_none', 'completion'), COMPLETION_TRACKING_MANUAL => get_string('completion_manual', 'completion'))); $mform->setDefault('completion', $trackingdefault); $mform->addHelpButton('completion', 'completion', 'completion'); // Automatic completion once you view it $gotcompletionoptions = false; if (plugin_supports('mod', $this->_modname, FEATURE_COMPLETION_TRACKS_VIEWS, false)) { $mform->addElement('checkbox', 'completionview', get_string('completionview', 'completion'), get_string('completionview_desc', 'completion')); $mform->disabledIf('completionview', 'completion', 'ne', COMPLETION_TRACKING_AUTOMATIC); $gotcompletionoptions = true; } // Automatic completion once it's graded if (plugin_supports('mod', $this->_modname, FEATURE_GRADE_HAS_GRADE, false)) { $mform->addElement('checkbox', 'completionusegrade', get_string('completionusegrade', 'completion'), get_string('completionusegrade_desc', 'completion')); $mform->disabledIf('completionusegrade', 'completion', 'ne', COMPLETION_TRACKING_AUTOMATIC); $mform->addHelpButton('completionusegrade', 'completionusegrade', 'completion'); $gotcompletionoptions = true; // If using the rating system, there is no grade unless ratings are enabled. if ($this->_features->rating) { $mform->disabledIf('completionusegrade', 'assessed', 'eq', 0); } } // Automatic completion according to module-specific rules $this->_customcompletionelements = $this->add_completion_rules(); foreach ($this->_customcompletionelements as $element) { $mform->disabledIf($element, 'completion', 'ne', COMPLETION_TRACKING_AUTOMATIC); } $gotcompletionoptions = $gotcompletionoptions || count($this->_customcompletionelements) > 0; // Automatic option only appears if possible if ($gotcompletionoptions) { $mform->getElement('completion')->addOption(get_string('completion_automatic', 'completion'), COMPLETION_TRACKING_AUTOMATIC); } // Completion expected at particular date? (For progress tracking) $mform->addElement('date_selector', 'completionexpected', get_string('completionexpected', 'completion'), array('optional' => true)); $mform->addHelpButton('completionexpected', 'completionexpected', 'completion'); $mform->disabledIf('completionexpected', 'completion', 'eq', COMPLETION_TRACKING_NONE); } $this->standard_hidden_coursemodule_elements(); }
public function validation($data, $files) { global $CFG; $errors = array(); // Availability: Check availability field does not have errors. if (!empty($CFG->enableavailability)) { \core_availability\frontend::report_validation_errors($data, $errors); } // Validate section name if 'Use default section name' is unchecked. if (empty($data['usedefaultname'])) { // Make sure the trimmed value of section name is not empty. $trimmedname = trim($data['name']); if (empty($trimmedname)) { $errors['name_group'] = get_string('required'); } } return $errors; }
public function validation($data, $files) { global $CFG; $errors = array(); // Availability: Check availability field does not have errors. if (!empty($CFG->enableavailability)) { \core_availability\frontend::report_validation_errors($data, $errors); } return $errors; }
function definition() { global $DB, $COURSE; $mform =& $this->_form; $unlock_system = $DB->get_record('content_unlock_system', array('id' => $this->unlocksystemid)); // Conditions $mform->addElement('header', 'availabilityconditionsheader', get_string('restrictaccess', 'availability')); $mform->addElement('textarea', 'availabilityconditionsjson', get_string('accessrestrictions', 'availability')); $mform->setDefault('availabilityconditionsjson', $unlock_system->restrictions); \core_availability\frontend::include_all_javascript($COURSE, null); $mform->addElement('html', '<hr></hr>'); $connective = $DB->get_field('content_unlock_system', 'connective', array('id' => $this->unlocksystemid)); $connectives_array = array(AND_CONNECTIVE => 'E', OR_CONNECTIVE => 'Ou'); $select = $mform->addElement('select', 'connective', 'Conectivo', $connectives_array); $mform->addRule('connective', null, 'required', null, 'client'); $select->setSelected($connective); $html = '<table> <tr> <th>Descrição</th> <th>Remover</th> </tr>'; $conditions = $DB->get_records('content_unlock_condition', array('unlocksystemid' => $this->unlocksystemid)); foreach ($conditions as $condition) { if ($condition->type == 0) { $block_info = null; if (isset($condition->prpointsystemid)) { $block_id = $DB->get_field('points_system', 'blockinstanceid', array('id' => $condition->prpointsystemid)); $block_info = $DB->get_record('block_instances', array('id' => $block_id)); $points_system_name = $DB->get_field('points_system', 'name', array('id' => $condition->prpointsystemid)); } else { $block_info = $DB->get_record('block_instances', array('id' => $condition->prblockid)); } $instance = block_instance('game_points', $block_info); $url = new moodle_url('/blocks/game_content_unlock/conditiondelete.php', array('conditionid' => $condition->id, 'courseid' => $COURSE->id)); $html .= '<tr><td>Os pontos ' . ($condition->prgrupal ? 'grupais' : 'individuais') . ' do aluno no' . (isset($condition->prblockid) ? ' bloco ' . $instance->title : ' sistema de pontos ' . (empty($points_system_name) ? $condition->prpointsystemid : $points_system_name . ' (' . $condition->prpointsystemid . ')') . ' (bloco ' . $instance->title . ')') . ' devem ser maiores ou iguais a ' . $condition->prpoints . ' pontos' . '</td><td>' . html_writer::link($url, 'Remover') . '</td></tr>'; } else { if ($condition->type == 1) { $unlock_system = $DB->get_record('content_unlock_system', array('id' => $condition->urunlocksystemid)); $course = $DB->get_record('course', array('id' => $COURSE->id)); $info = get_fast_modinfo($course); $cm = $info->get_cm($unlock_system->coursemoduleid); $block_info = $DB->get_record('block_instances', array('id' => $unlock_system->blockinstanceid)); $instance = block_instance('game_content_unlock', $block_info); $url = new moodle_url('/blocks/game_content_unlock/conditiondelete.php', array('conditionid' => $condition->id, 'courseid' => $COURSE->id)); $html .= '<tr><td>O aluno ' . ($condition->urmust ? 'deve' : 'não deve') . ' ter ' . ($unlock_system->coursemodulevisibility ? 'desbloqueado' : 'bloqueado') . ' o recurso/atividade ' . $cm->name . ' (bloco ' . $instance->title . ')' . '</td><td>' . html_writer::link($url, 'Remover') . '</td></tr>'; } else { $achievement = $DB->get_record('achievements', array('id' => $condition->arachievementid)); $block_info = $DB->get_record('block_instances', array('id' => $achievement->blockinstanceid)); $instance = block_instance('game_achievements', $block_info); $url = new moodle_url('/blocks/game_content_unlock/conditiondelete.php', array('conditionid' => $condition->id, 'courseid' => $COURSE->id)); $html .= '<tr><td>O aluno deve ter atingido a conquista ' . (isset($achievement->name) ? $achievement->name . ' (' . $achievement->id . ')' : $achievement->id) . ' (bloco ' . $instance->title . ')</td><td>' . html_writer::link($url, 'Remover') . '</td></tr>'; } } } $url = new moodle_url('/blocks/game_content_unlock/conditionadd.php', array('unlocksystemid' => $this->unlocksystemid, 'courseid' => $COURSE->id)); $html .= '</table>' . html_writer::link($url, 'Adicionar restrição'); $mform->addElement('html', $html); // Advanced conditions $mform->addElement('html', '<hr></hr>'); $advconnective = $DB->get_field('content_unlock_system', 'advconnective', array('id' => $this->unlocksystemid)); $select = $mform->addElement('select', 'advconnective', 'Conectivo de restrições avançadas', $connectives_array); $mform->addRule('advconnective', null, 'required', null, 'client'); $select->setSelected($advconnective); $html = '<table> <tr> <th>' . get_string('conditionmanagesql', 'block_game_content_unlock') . '</th> <th>' . get_string('conditionmanagetrueif', 'block_game_content_unlock') . '</th> <th>' . get_string('conditionmanagedelete', 'block_game_content_unlock') . '</th> </tr>'; $conditions = $DB->get_records('content_unlock_advcondition', array('unlocksystemid' => $this->unlocksystemid)); foreach ($conditions as $condition) { $url = new moodle_url('/blocks/game_content_unlock/advancedconditiondelete.php', array('conditionid' => $condition->id, 'courseid' => $COURSE->id)); if ($condition->trueif == 0) { $trueif = get_string('advancedconditionaddtrueifzero', 'block_game_content_unlock'); } else { if ($condition->trueif == 1) { $trueif = get_string('advancedconditionaddtrueifnotzero', 'block_game_content_unlock'); } else { $trueif = get_string('advancedconditionaddtrueifegthan', 'block_game_content_unlock') . ' ' . $condition->count; } } $html .= '<tr> <td>' . get_string('advancedconditionaddselect', 'block_game_content_unlock') . ' ' . $condition->whereclause . '</td> <td>' . $trueif . '</td> <td>' . html_writer::link($url, get_string('conditionmanagedelete', 'block_game_content_unlock')) . '</td> </tr>'; } $url = new moodle_url('/blocks/game_content_unlock/advancedconditionadd.php', array('unlocksystemid' => $this->unlocksystemid, 'courseid' => $COURSE->id)); $html .= '</table>' . html_writer::link($url, get_string('conditionmanageadd', 'block_game_content_unlock')); $mform->addElement('html', $html); $mform->addElement('hidden', 'unlocksystemid'); $mform->addElement('hidden', 'courseid'); $this->add_action_buttons(); }