/** * 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(); }
function definition() { global $COURSE, $CFG; $mform =& $this->_form; /// visible elements $mform->addElement('header', 'general', get_string('gradeoutcomeitem', 'grades')); $mform->addElement('text', 'itemname', get_string('itemname', 'grades')); $mform->addRule('itemname', get_string('required'), 'required', null, 'client'); $mform->addElement('text', 'iteminfo', get_string('iteminfo', 'grades')); $mform->setHelpButton('iteminfo', array('iteminfo', get_string('iteminfo', 'grades'), 'grade'), true); $mform->addElement('text', 'idnumber', get_string('idnumbermod')); $mform->setHelpButton('idnumber', array('idnumber', get_string('idnumber', 'grades'), 'grade'), true); // allow setting of outcomes on module items too $options = array(); if ($outcomes = grade_outcome::fetch_all_available($COURSE->id)) { foreach ($outcomes as $outcome) { $options[$outcome->id] = $outcome->get_name(); } } $mform->addElement('selectwithlink', 'outcomeid', get_string('outcome', 'grades'), $options, null, array('link' => $CFG->wwwroot . '/grade/edit/outcome/course.php?id=' . $COURSE->id, 'label' => get_string('outcomeassigntocourse', 'grades'))); $mform->setHelpButton('outcomeid', array('outcomeid', get_string('outcomeid', 'grades'), 'grade'), true); $mform->addRule('outcomeid', get_string('required'), 'required'); $options = array(0 => get_string('none')); if ($coursemods = get_course_mods($COURSE->id)) { foreach ($coursemods as $coursemod) { if ($mod = get_coursemodule_from_id($coursemod->modname, $coursemod->id)) { $options[$coursemod->id] = format_string($mod->name); } } } $mform->addElement('select', 'cmid', get_string('linkedactivity', 'grades'), $options); $mform->setHelpButton('cmid', array('linkedactivity', get_string('linkedactivity', 'grades'), 'grade'), true); $mform->setDefault('cmid', 0); /*$mform->addElement('text', 'gradepass', get_string('gradepass', 'grades')); $mform->setHelpButton('gradepass', array(false, get_string('gradepass', 'grades'), false, true, false, get_string('gradepasshelp', 'grades')));*/ /// hiding /// advcheckbox is not compatible with disabledIf !! $mform->addElement('checkbox', 'hidden', get_string('hidden', 'grades')); $mform->setHelpButton('hidden', array('hidden', get_string('hidden', 'grades'), 'grade')); $mform->addElement('date_time_selector', 'hiddenuntil', get_string('hiddenuntil', 'grades'), array('optional' => true)); $mform->setHelpButton('hiddenuntil', array('hiddenuntil', get_string('hiddenuntil', 'grades'), 'grade')); $mform->disabledIf('hidden', 'hiddenuntil[off]', 'notchecked'); //locking $mform->addElement('advcheckbox', 'locked', get_string('locked', 'grades')); $mform->setHelpButton('locked', array('locked', get_string('locked', 'grades'), 'grade')); $mform->addElement('date_time_selector', 'locktime', get_string('locktime', 'grades'), array('optional' => true)); $mform->setHelpButton('locktime', array('lockedafter', get_string('locktime', 'grades'), 'grade')); /// parent category related settings $mform->addElement('header', 'headerparent', get_string('parentcategory', 'grades')); $options = array(); $default = ''; $coefstring = ''; $categories = grade_category::fetch_all(array('courseid' => $COURSE->id)); foreach ($categories as $cat) { $cat->apply_forced_settings(); $options[$cat->id] = $cat->get_name(); if ($cat->is_course_category()) { $default = $cat->id; } if ($cat->is_aggregationcoef_used()) { if ($cat->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) { $coefstring = ($coefstring == '' or $coefstring == 'aggregationcoefweight') ? 'aggregationcoefweight' : 'aggregationcoef'; } else { if ($cat->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN2) { $coefstring = ($coefstring == '' or $coefstring == 'aggregationcoefextrasum') ? 'aggregationcoefextrasum' : 'aggregationcoef'; } else { if ($cat->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) { $coefstring = ($coefstring == '' or $coefstring == 'aggregationcoefextra') ? 'aggregationcoefextra' : 'aggregationcoef'; } else { if ($cat->aggregation == GRADE_AGGREGATE_SUM) { $coefstring = ($coefstring == '' or $coefstring == 'aggregationcoefextrasum') ? 'aggregationcoefextrasum' : 'aggregationcoef'; } else { $coefstring = 'aggregationcoef'; } } } } } else { $mform->disabledIf('aggregationcoef', 'parentcategory', 'eq', $cat->id); } } if (count($categories) > 1) { $mform->addElement('select', 'parentcategory', get_string('gradecategory', 'grades'), $options); $mform->disabledIf('parentcategory', 'cmid', 'noteq', 0); } if ($coefstring !== '') { if ($coefstring == 'aggregationcoefextrasum') { // advcheckbox is not compatible with disabledIf! $mform->addElement('checkbox', 'aggregationcoef', get_string($coefstring, 'grades')); } else { $mform->addElement('text', 'aggregationcoef', get_string($coefstring, 'grades')); } $mform->setHelpButton('aggregationcoef', array($coefstring, get_string($coefstring, 'grades'), 'grade'), true); } /// hidden params $mform->addElement('hidden', 'id', 0); $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'courseid', $COURSE->id); $mform->setType('courseid', PARAM_INT); /// add return tracking info $gpr = $this->_customdata['gpr']; $gpr->add_mform_elements($mform); /// mark advanced according to site settings if (isset($CFG->grade_item_advanced)) { $advanced = explode(',', $CFG->grade_item_advanced); foreach ($advanced as $el) { if ($mform->elementExists($el)) { $mform->setAdvanced($el); } } } //------------------------------------------------------------------------------- // buttons $this->add_action_buttons(); }
include_once '../../../config.php'; require_once $CFG->libdir . '/gradelib.php'; require_once $CFG->dirroot . '/grade/lib.php'; $courseid = required_param('id', PARAM_INT); // course id if (!($course = get_record('course', 'id', $courseid))) { print_error('nocourseid'); } require_login($course->id); $context = get_context_instance(CONTEXT_COURSE, $course->id); require_capability('gradereport/outcomes:view', $context); //first make sure we have proper final grades grade_regrade_final_grades($courseid); // Grab all outcomes used in course $report_info = array(); $outcomes = grade_outcome::fetch_all_available($courseid); // Get grade_items that use each outcome foreach ($outcomes as $outcomeid => $outcome) { $report_info[$outcomeid]['items'] = get_records_select('grade_items', "outcomeid = {$outcomeid} AND courseid = {$courseid}"); $report_info[$outcomeid]['outcome'] = $outcome; // Get average grades for each item if (is_array($report_info[$outcomeid]['items'])) { foreach ($report_info[$outcomeid]['items'] as $itemid => $item) { $sql = "SELECT itemid, AVG(finalgrade) AS avg, COUNT(finalgrade) AS count\n FROM {$CFG->prefix}grade_grades\n WHERE itemid = {$itemid}\n GROUP BY itemid"; $info = get_records_sql($sql); if (!$info) { unset($report_info[$outcomeid]['items'][$itemid]); continue; } else { $info = reset($info); $avg = round($info->avg, 2);
/** * 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->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')); 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 or $this->_features->groupmembersonly) { //groupings selector - used for normal grouping mode or also when restricting access with groupmembersonly $options = array(); $options[0] = get_string('none'); if ($groupings = $DB->get_records('groupings', array('courseid' => $COURSE->id))) { foreach ($groupings as $grouping) { $options[$grouping->id] = format_string($grouping->name); } } $mform->addElement('select', 'groupingid', get_string('grouping', 'group'), $options); $mform->addHelpButton('groupingid', 'grouping', 'group'); $mform->setAdvanced('groupingid'); } if ($this->_features->groupmembersonly) { $mform->addElement('checkbox', 'groupmembersonly', get_string('groupmembersonly', 'group')); $mform->addHelpButton('groupmembersonly', 'groupmembersonly', 'group'); $mform->setAdvanced('groupmembersonly'); } $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->addHelpButton('cmidnumber', 'idnumbermod'); } if (!empty($CFG->enableavailability)) { // String used by conditions $strnone = get_string('none', 'condition'); // Conditional availability // Available from/to defaults to midnight because then the display // will be nicer where it tells users when they can access it (it // shows only the date and not time). $date = usergetdate(time()); $midnight = make_timestamp($date['year'], $date['mon'], $date['mday']); // From/until controls $mform->addElement('header', 'availabilityconditionsheader', get_string('availabilityconditions', 'condition')); $mform->addElement('date_time_selector', 'availablefrom', get_string('availablefrom', 'condition'), array('optional' => true, 'defaulttime' => $midnight)); $mform->addHelpButton('availablefrom', 'availablefrom', 'condition'); $mform->addElement('date_time_selector', 'availableuntil', get_string('availableuntil', 'condition'), array('optional' => true, 'defaulttime' => $midnight)); // Conditions based on grades $gradeoptions = array(); $items = grade_item::fetch_all(array('courseid' => $COURSE->id)); $items = $items ? $items : array(); foreach ($items as $id => $item) { // Do not include grades for current item if (!empty($this->_cm) && $this->_cm->instance == $item->iteminstance && $this->_cm->modname == $item->itemmodule && $item->itemtype == 'mod') { continue; } $gradeoptions[$id] = $item->get_name(); } asort($gradeoptions); $gradeoptions = array(0 => $strnone) + $gradeoptions; $grouparray = array(); $grouparray[] =& $mform->createElement('select', 'conditiongradeitemid', '', $gradeoptions); $grouparray[] =& $mform->createElement('static', '', '', ' ' . get_string('grade_atleast', 'condition') . ' '); $grouparray[] =& $mform->createElement('text', 'conditiongrademin', '', array('size' => 3)); $grouparray[] =& $mform->createElement('static', '', '', '% ' . get_string('grade_upto', 'condition') . ' '); $grouparray[] =& $mform->createElement('text', 'conditiongrademax', '', array('size' => 3)); $grouparray[] =& $mform->createElement('static', '', '', '%'); $group = $mform->createElement('group', 'conditiongradegroup', get_string('gradecondition', 'condition'), $grouparray); // Get version with condition info and store it so we don't ask // twice if (!empty($this->_cm)) { $ci = new condition_info($this->_cm, CONDITION_MISSING_EXTRATABLE); $this->_cm = $ci->get_full_course_module(); $count = count($this->_cm->conditionsgrade) + 1; $fieldcount = count($this->_cm->conditionsfield) + 1; } else { $count = 1; $fieldcount = 1; } $this->repeat_elements(array($group), $count, array(), 'conditiongraderepeats', 'conditiongradeadds', 2, get_string('addgrades', 'condition'), true); $mform->addHelpButton('conditiongradegroup[0]', 'gradecondition', 'condition'); // Conditions based on user fields $operators = condition_info::get_condition_user_field_operators(); $useroptions = condition_info::get_condition_user_fields(); asort($useroptions); $useroptions = array(0 => $strnone) + $useroptions; $grouparray = array(); $grouparray[] =& $mform->createElement('select', 'conditionfield', '', $useroptions); $grouparray[] =& $mform->createElement('select', 'conditionfieldoperator', '', $operators); $grouparray[] =& $mform->createElement('text', 'conditionfieldvalue'); $mform->setType('conditionfieldvalue', PARAM_RAW); $group = $mform->createElement('group', 'conditionfieldgroup', get_string('userfield', 'condition'), $grouparray); $this->repeat_elements(array($group), $fieldcount, array(), 'conditionfieldrepeats', 'conditionfieldadds', 2, get_string('adduserfields', 'condition'), true); $mform->addHelpButton('conditionfieldgroup[0]', 'userfield', 'condition'); // Conditions based on completion $completion = new completion_info($COURSE); if ($completion->is_enabled()) { $completionoptions = array(); $modinfo = get_fast_modinfo($COURSE); foreach ($modinfo->cms as $id => $cm) { // Add each course-module if it: // (a) has completion turned on // (b) is not the same as current course-module if ($cm->completion && (empty($this->_cm) || $this->_cm->id != $id)) { $completionoptions[$id] = $cm->name; } } asort($completionoptions); $completionoptions = array(0 => $strnone) + $completionoptions; $completionvalues = array(COMPLETION_COMPLETE => get_string('completion_complete', 'condition'), COMPLETION_INCOMPLETE => get_string('completion_incomplete', 'condition'), COMPLETION_COMPLETE_PASS => get_string('completion_pass', 'condition'), COMPLETION_COMPLETE_FAIL => get_string('completion_fail', 'condition')); $grouparray = array(); $grouparray[] =& $mform->createElement('select', 'conditionsourcecmid', '', $completionoptions); $grouparray[] =& $mform->createElement('select', 'conditionrequiredcompletion', '', $completionvalues); $group = $mform->createElement('group', 'conditioncompletiongroup', get_string('completioncondition', 'condition'), $grouparray); $count = empty($this->_cm) ? 1 : count($this->_cm->conditionscompletion) + 1; $this->repeat_elements(array($group), $count, array(), 'conditioncompletionrepeats', 'conditioncompletionadds', 2, get_string('addcompletions', 'condition'), true); $mform->addHelpButton('conditioncompletiongroup[0]', 'completioncondition', 'condition'); } // Do we display availability info to students? $mform->addElement('select', 'showavailability', get_string('showavailability', 'condition'), array(CONDITION_STUDENTVIEW_SHOW => get_string('showavailability_show', 'condition'), CONDITION_STUDENTVIEW_HIDE => get_string('showavailability_hide', 'condition'))); $mform->setDefault('showavailability', CONDITION_STUDENTVIEW_SHOW); } // 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); $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', $this->_features->defaultcompletion ? COMPLETION_TRACKING_MANUAL : COMPLETION_TRACKING_NONE); $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; } // 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(); }
/** * Common create/update module module actions that need to be processed as soon as a module is created/updaded. * For example:create grade parent category, add outcomes, rebuild caches, regrade, save plagiarism settings... * Please note this api does not trigger events as of MOODLE 2.6. Please trigger events before calling this api. * * @param object $moduleinfo the module info * @param object $course the course of the module * * @return object moduleinfo update with grading management info */ function edit_module_post_actions($moduleinfo, $course) { global $CFG; require_once $CFG->libdir . '/gradelib.php'; $modcontext = context_module::instance($moduleinfo->coursemodule); $hasgrades = plugin_supports('mod', $moduleinfo->modulename, FEATURE_GRADE_HAS_GRADE, false); $hasoutcomes = plugin_supports('mod', $moduleinfo->modulename, FEATURE_GRADE_OUTCOMES, true); // Sync idnumber with grade_item. if ($hasgrades && ($grade_item = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => $moduleinfo->modulename, 'iteminstance' => $moduleinfo->instance, 'itemnumber' => 0, 'courseid' => $course->id)))) { if ($grade_item->idnumber != $moduleinfo->cmidnumber) { $grade_item->idnumber = $moduleinfo->cmidnumber; $grade_item->update(); } } if ($hasgrades) { $items = grade_item::fetch_all(array('itemtype' => 'mod', 'itemmodule' => $moduleinfo->modulename, 'iteminstance' => $moduleinfo->instance, 'courseid' => $course->id)); } else { $items = array(); } // Create parent category if requested and move to correct parent category. if ($items and isset($moduleinfo->gradecat)) { if ($moduleinfo->gradecat == -1) { $grade_category = new grade_category(); $grade_category->courseid = $course->id; $grade_category->fullname = $moduleinfo->name; $grade_category->insert(); if ($grade_item) { $parent = $grade_item->get_parent_category(); $grade_category->set_parent($parent->id); } $moduleinfo->gradecat = $grade_category->id; } $gradecategory = $grade_item->get_parent_category(); foreach ($items as $itemid => $unused) { $items[$itemid]->set_parent($moduleinfo->gradecat); if ($itemid == $grade_item->id) { // Use updated grade_item. $grade_item = $items[$itemid]; } if (!empty($moduleinfo->add)) { if (grade_category::aggregation_uses_aggregationcoef($gradecategory->aggregation)) { if ($gradecategory->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) { $grade_item->aggregationcoef = 1; } else { $grade_item->aggregationcoef = 0; } $grade_item->update(); } } } } require_once $CFG->libdir . '/grade/grade_outcome.php'; // Add outcomes if requested. if ($hasoutcomes && ($outcomes = grade_outcome::fetch_all_available($course->id))) { $grade_items = array(); // Outcome grade_item.itemnumber start at 1000, there is nothing above outcomes. $max_itemnumber = 999; if ($items) { foreach ($items as $item) { if ($item->itemnumber > $max_itemnumber) { $max_itemnumber = $item->itemnumber; } } } foreach ($outcomes as $outcome) { $elname = 'outcome_' . $outcome->id; if (property_exists($moduleinfo, $elname) and $moduleinfo->{$elname}) { // So we have a request for new outcome grade item? if ($items) { $outcomeexists = false; foreach ($items as $item) { if ($item->outcomeid == $outcome->id) { $outcomeexists = true; break; } } if ($outcomeexists) { continue; } } $max_itemnumber++; $outcome_item = new grade_item(); $outcome_item->courseid = $course->id; $outcome_item->itemtype = 'mod'; $outcome_item->itemmodule = $moduleinfo->modulename; $outcome_item->iteminstance = $moduleinfo->instance; $outcome_item->itemnumber = $max_itemnumber; $outcome_item->itemname = $outcome->fullname; $outcome_item->outcomeid = $outcome->id; $outcome_item->gradetype = GRADE_TYPE_SCALE; $outcome_item->scaleid = $outcome->scaleid; $outcome_item->insert(); // Move the new outcome into correct category and fix sortorder if needed. if ($grade_item) { $outcome_item->set_parent($grade_item->categoryid); $outcome_item->move_after_sortorder($grade_item->sortorder); } else { if (isset($moduleinfo->gradecat)) { $outcome_item->set_parent($moduleinfo->gradecat); } } $gradecategory = $outcome_item->get_parent_category(); if ($outcomeexists == false) { if (grade_category::aggregation_uses_aggregationcoef($gradecategory->aggregation)) { if ($gradecategory->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) { $outcome_item->aggregationcoef = 1; } else { $outcome_item->aggregationcoef = 0; } $outcome_item->update(); } } } } } if (plugin_supports('mod', $moduleinfo->modulename, FEATURE_ADVANCED_GRADING, false) and has_capability('moodle/grade:managegradingforms', $modcontext)) { require_once $CFG->dirroot . '/grade/grading/lib.php'; $gradingman = get_grading_manager($modcontext, 'mod_' . $moduleinfo->modulename); $showgradingmanagement = false; foreach ($gradingman->get_available_areas() as $areaname => $aretitle) { $formfield = 'advancedgradingmethod_' . $areaname; if (isset($moduleinfo->{$formfield})) { $gradingman->set_area($areaname); $methodchanged = $gradingman->set_active_method($moduleinfo->{$formfield}); if (empty($moduleinfo->{$formfield})) { // Going back to the simple direct grading is not a reason to open the management screen. $methodchanged = false; } $showgradingmanagement = $showgradingmanagement || $methodchanged; } } // Update grading management information. $moduleinfo->gradingman = $gradingman; $moduleinfo->showgradingmanagement = $showgradingmanagement; } rebuild_course_cache($course->id, true); if ($hasgrades) { grade_regrade_final_grades($course->id); } require_once $CFG->libdir . '/plagiarismlib.php'; plagiarism_save_form_elements($moduleinfo); return $moduleinfo; }
/** * Adds all the standard elements to a form to edit the settings for an activity module. * * @param mixed array or object describing supported features - groups, groupings, groupmembersonly, etc. */ function standard_coursemodule_elements($features = null) { global $COURSE, $CFG; $mform =& $this->_form; // deal with legacy $supportgroups param if ($features === true or $features === false) { $groupmode = $features; $this->_features = new object(); $this->_features->groups = $groupmode; } else { if (is_array($features)) { $this->_features = (object) $features; } else { if (empty($features)) { $this->_features = new object(); } else { $this->_features = $features; } } } if (!isset($this->_features->groups)) { $this->_features->groups = true; } if (!isset($this->_features->groupings)) { $this->_features->groupings = false; } if (!isset($this->_features->groupmembersonly)) { $this->_features->groupmembersonly = false; } if (!isset($this->_features->outcomes)) { $this->_features->outcomes = true; } if (!isset($this->_features->gradecat)) { $this->_features->gradecat = true; } if (!isset($this->_features->idnumber)) { $this->_features->idnumber = true; } $outcomesused = false; if (!empty($CFG->enableoutcomes) and $this->_features->outcomes) { if ($outcomes = grade_outcome::fetch_all_available($COURSE->id)) { $outcomesused = true; $mform->addElement('header', 'modoutcomes', get_string('outcomes', 'grades')); foreach ($outcomes as $outcome) { $mform->addElement('advcheckbox', 'outcome_' . $outcome->id, $outcome->get_name()); } } } $mform->addElement('header', 'modstandardelshdr', get_string('modstandardels', 'form')); 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'), $options, NOGROUPS); $mform->setHelpButton('groupmode', array('groupmode', get_string('groupmode'))); } if (!empty($CFG->enablegroupings)) { if ($this->_features->groupings or $this->_features->groupmembersonly) { //groupings selector - used for normal grouping mode or also when restricting access with groupmembersonly $options = array(); $options[0] = get_string('none'); if ($groupings = get_records('groupings', 'courseid', $COURSE->id)) { foreach ($groupings as $grouping) { $options[$grouping->id] = format_string($grouping->name); } } $mform->addElement('select', 'groupingid', get_string('grouping', 'group'), $options); $mform->setHelpButton('groupingid', array('grouping', get_string('grouping', 'group'))); $mform->setAdvanced('groupingid'); } if ($this->_features->groupmembersonly) { $mform->addElement('checkbox', 'groupmembersonly', get_string('groupmembersonly', 'group')); $mform->setHelpButton('groupmembersonly', array('groupmembersonly', get_string('groupmembersonly', 'group'))); $mform->setAdvanced('groupmembersonly'); } } $mform->addElement('modvisible', 'visible', get_string('visible')); if ($this->_features->idnumber) { $mform->addElement('text', 'cmidnumber', get_string('idnumbermod')); $mform->setHelpButton('cmidnumber', array('cmidnumber', get_string('idnumbermod')), true); } if ($this->_features->gradecat) { $categories = grade_get_categories_menu($COURSE->id, $outcomesused); $mform->addElement('select', 'gradecat', get_string('gradecategory', 'grades'), $categories); } $this->standard_hidden_coursemodule_elements(); }
function RWSUQGrades($r_qiz) { $r_gi = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => $r_qiz->modulename, 'iteminstance' => $r_qiz->instance, 'itemnumber' => 0, 'courseid' => $r_qiz->course)); if ($r_gi && $r_gi->idnumber != $r_qiz->cmidnumber) { $r_gi->idnumber = $r_qiz->cmidnumber; $r_gi->update(); } $r_its = grade_item::fetch_all(array('itemtype' => 'mod', 'itemmodule' => $r_qiz->modulename, 'iteminstance' => $r_qiz->instance, 'courseid' => $r_qiz->course)); if ($r_its && isset($r_qiz->gradecat)) { if ($r_qiz->gradecat == -1) { $r_gcat = new grade_category(); $r_gcat->courseid = $r_qiz->course; $r_gcat->fullname = $r_qiz->name; $r_gcat->insert(); if ($r_gi) { $r_par = $r_gi->get_parent_category(); $r_gcat->set_parent($r_par->id); } $r_qiz->gradecat = $r_gcat->id; } foreach ($r_its as $r_iti => $r_un) { $r_its[$r_iti]->set_parent($r_qiz->gradecat); if ($r_iti == $r_gi->id) { $r_gi = $r_its[$r_iti]; } } } if ($r_ocs = grade_outcome::fetch_all_available($r_qiz->course)) { $r_gis = array(); $r_mit = 999; if ($r_its) { foreach ($r_its as $r_it) { if ($r_it->itemnumber > $r_mit) { $r_mit = $r_it->itemnumber; } } } foreach ($r_ocs as $r_oc) { $r_eln = 'outcome_' . $r_oc->id; if (property_exists($r_qiz, $r_eln) and $r_qiz->{$r_eln}) { if ($r_its) { foreach ($r_its as $r_it) { if ($r_it->outcomeid == $r_oc->id) { continue 2; } } } $r_mit++; $r_oi = new grade_item(); $r_oi->courseid = $r_qiz->course; $r_oi->itemtype = 'mod'; $r_oi->itemmodule = $r_qiz->modulename; $r_oi->iteminstance = $r_qiz->instance; $r_oi->itemnumber = $r_mit; $r_oi->itemname = $r_oc->fullname; $r_oi->outcomeid = $r_oc->id; $r_oi->gradetype = GRADE_TYPE_SCALE; $r_oi->scaleid = $r_oc->scaleid; $r_oi->insert(); if ($r_gi) { $r_oi->set_parent($r_gi->categoryid); $r_oi->move_after_sortorder($r_gi->sortorder); } else { if (isset($r_qiz->gradecat)) { $r_oi->set_parent($r_qiz->gradecat); } } } } } }
$grade_item->move_after_sortorder($item->sortorder); } } else { // set parent if needed if (isset($data->parentcategory)) { $grade_item->set_parent($data->parentcategory, 'gradebook'); } } } else { $grade_item->update(); } // update hiding flag if ($hiddenuntil) { $grade_item->set_hidden($hiddenuntil, false); } else { $grade_item->set_hidden($hidden, false); } $grade_item->set_locktime($locktime); // locktime first - it might be removed when unlocking $grade_item->set_locked($locked, false, true); redirect($returnurl); } $PAGE->navbar->add($heading); print_grade_page_head($courseid, 'settings', null, $heading, false, false, false); if (!grade_outcome::fetch_all_available($COURSE->id)) { echo $OUTPUT->confirm(get_string('nooutcomes', 'grades'), $CFG->wwwroot . '/grade/edit/outcome/course.php?id=' . $courseid, $returnurl); echo $OUTPUT->footer(); die; } $mform->display(); echo $OUTPUT->footer();
/** * Adds all the standard elements to a form to edit the settings for an activity module. * * @param mixed array or object describing supported features - groups, groupings, groupmembersonly */ function standard_coursemodule_elements($features = null) { global $COURSE, $CFG; $mform =& $this->_form; // deal with legacy $supportgroups param if ($features === true or $features === false) { $groupmode = $features; $features = new object(); $features->groups = $groupmode; } else { if (is_array($features)) { $features = (object) $features; } else { if (empty($features)) { $features = new object(); } } } if (!isset($features->groups)) { $features->groups = true; } if (!isset($features->groupings)) { $features->groupings = false; } if (!isset($features->groupmembersonly)) { $features->groupmembersonly = false; } if (!empty($CFG->enableoutcomes)) { if ($outcomes = grade_outcome::fetch_all_available($COURSE->id)) { $mform->addElement('header', 'modoutcomes', get_string('outcomes', 'grades')); foreach ($outcomes as $outcome) { $mform->addElement('advcheckbox', 'outcome_' . $outcome->id, $outcome->get_name()); } } } $mform->addElement('header', 'modstandardelshdr', get_string('modstandardels', 'form')); // if no other elements will be shown, this header should be removed $showHeader = false; if ($features->groups) { $mform->addElement('modgroupmode', 'groupmode', get_string('groupmode')); $showHeader = true; } if (!empty($CFG->enablegroupings)) { if ($features->groupings or $features->groupmembersonly) { //groupings selector - used for normal grouping mode or also when restricting access with groupmembersonly $options = array(); $options[0] = get_string('none'); if ($groupings = get_records('groupings', 'courseid', $COURSE->id)) { foreach ($groupings as $grouping) { $options[$grouping->id] = format_string($grouping->name); } } $mform->addElement('select', 'groupingid', get_string('grouping', 'group'), $options); $mform->setAdvanced('groupingid'); $showHeader = true; } if ($features->groupmembersonly) { $mform->addElement('checkbox', 'groupmembersonly', get_string('groupmembersonly', 'group')); $mform->setAdvanced('groupmembersonly'); $showHeader = true; } } if (!$showHeader) { $mform->removeElement('modstandardelshdr'); } // kowy - this parameter is too dificult to leave setting to a teacher //$mform->addElement('modvisible', 'visible', get_string('visible')); //$mform->addElement('text', 'cmidnumber', get_string('idnumber')); $this->standard_hidden_coursemodule_elements(); }
if ($grade_item) { $parent = $grade_item->get_parent_category(); $grade_category->set_parent($parent->id); } $fromform->gradecat = $grade_category->id; } foreach ($items as $itemid => $unused) { $items[$itemid]->set_parent($fromform->gradecat); if ($itemid == $grade_item->id) { // use updated grade_item $grade_item = $items[$itemid]; } } } // add outcomes if requested if ($outcomes = grade_outcome::fetch_all_available($course->id)) { $grade_items = array(); // Outcome grade_item.itemnumber start at 1000, there is nothing above outcomes $max_itemnumber = 999; if ($items) { foreach ($items as $item) { if ($item->itemnumber > $max_itemnumber) { $max_itemnumber = $item->itemnumber; } } } foreach ($outcomes as $outcome) { $elname = 'outcome_' . $outcome->id; if (property_exists($fromform, $elname) and $fromform->{$elname}) { // so we have a request for new outcome grade item? if ($items) {
/** * 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; $outcomesused = false; if ($this->_features->outcomes) { if ($outcomes = grade_outcome::fetch_all_available($COURSE->id)) { $outcomesused = true; $mform->addElement('header', 'modoutcomes', get_string('outcomes', 'grades')); foreach ($outcomes as $outcome) { $mform->addElement('advcheckbox', 'outcome_' . $outcome->id, $outcome->get_name()); } } } $mform->addElement('header', 'modstandardelshdr', get_string('modstandardels', 'form')); 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'), $options, NOGROUPS); $mform->setHelpButton('groupmode', array('groupmode', get_string('groupmode'))); } if (!empty($CFG->enablegroupings)) { if ($this->_features->groupings or $this->_features->groupmembersonly) { //groupings selector - used for normal grouping mode or also when restricting access with groupmembersonly $options = array(); $options[0] = get_string('none'); if ($groupings = $DB->get_records('groupings', array('courseid' => $COURSE->id))) { foreach ($groupings as $grouping) { $options[$grouping->id] = format_string($grouping->name); } } $mform->addElement('select', 'groupingid', get_string('grouping', 'group'), $options); $mform->setHelpButton('groupingid', array('grouping', get_string('grouping', 'group'))); $mform->setAdvanced('groupingid'); } if ($this->_features->groupmembersonly) { $mform->addElement('checkbox', 'groupmembersonly', get_string('groupmembersonly', 'group')); $mform->setHelpButton('groupmembersonly', array('groupmembersonly', get_string('groupmembersonly', 'group'))); $mform->setAdvanced('groupmembersonly'); } } $mform->addElement('modvisible', 'visible', get_string('visible')); if ($this->_features->idnumber) { $mform->addElement('text', 'cmidnumber', get_string('idnumbermod')); $mform->setHelpButton('cmidnumber', array('cmidnumber', get_string('idnumbermod')), true); } if ($this->_features->gradecat) { $categories = grade_get_categories_menu($COURSE->id, $outcomesused); $mform->addElement('select', 'gradecat', get_string('gradecategory', 'grades'), $categories); } if (!empty($CFG->enableavailability)) { // Conditional availability $mform->addElement('header', '', get_string('availabilityconditions', 'condition')); $mform->addElement('date_selector', 'availablefrom', get_string('availablefrom', 'condition'), array('optional' => true)); $mform->setHelpButton('availablefrom', array('conditiondates', get_string('help_conditiondates', 'condition'), 'condition')); $mform->addElement('date_selector', 'availableuntil', get_string('availableuntil', 'condition'), array('optional' => true)); $mform->setHelpButton('availableuntil', array('conditiondates', get_string('help_conditiondates', 'condition'), 'condition')); // Conditions based on grades $gradeoptions = array(); $items = grade_item::fetch_all(array('courseid' => $COURSE->id)); $items = $items ? $items : array(); foreach ($items as $id => $item) { // Do not include grades for current item if (!empty($this->_cm) && $this->_cm->instance == $item->iteminstance && $this->_cm->modname == $item->itemmodule && $item->itemtype == 'mod') { continue; } $gradeoptions[$id] = $item->get_name(); } asort($gradeoptions); $gradeoptions = array(0 => get_string('none', 'condition')) + $gradeoptions; $grouparray = array(); $grouparray[] =& $mform->createElement('select', 'conditiongradeitemid', '', $gradeoptions); $grouparray[] =& $mform->createElement('static', '', '', ' ' . get_string('grade_atleast', 'condition') . ' '); $grouparray[] =& $mform->createElement('text', 'conditiongrademin', '', array('size' => 3)); $grouparray[] =& $mform->createElement('static', '', '', '% ' . get_string('grade_upto', 'condition') . ' '); $grouparray[] =& $mform->createElement('text', 'conditiongrademax', '', array('size' => 3)); $grouparray[] =& $mform->createElement('static', '', '', '%'); $mform->setType('conditiongrademin', PARAM_FLOAT); $mform->setType('conditiongrademax', PARAM_FLOAT); $group = $mform->createElement('group', 'conditiongradegroup', get_string('gradecondition', 'condition'), $grouparray); // Get version with condition info and store it so we don't ask // twice if (!empty($this->_cm)) { $ci = new condition_info($this->_cm, CONDITION_MISSING_EXTRATABLE); $this->_cm = $ci->get_full_course_module(); $count = count($this->_cm->conditionsgrade) + 1; } else { $count = 1; } $this->repeat_elements(array($group), $count, array(), 'conditiongraderepeats', 'conditiongradeadds', 2, get_string('addgrades', 'condition'), true); $mform->setHelpButton('conditiongradegroup[0]', array('gradecondition', get_string('help_gradecondition', 'condition'), 'condition')); // Conditions based on completion $completion = new completion_info($COURSE); if ($completion->is_enabled()) { $completionoptions = array(); $modinfo = get_fast_modinfo($COURSE); foreach ($modinfo->cms as $id => $cm) { // Add each course-module if it: // (a) has completion turned on // (b) is not the same as current course-module if ($cm->completion && (empty($this->_cm) || $this->_cm->id != $id)) { $completionoptions[$id] = $cm->name; } } asort($completionoptions); $completionoptions = array(0 => get_string('none', 'condition')) + $completionoptions; $completionvalues = array(COMPLETION_COMPLETE => get_string('completion_complete', 'condition'), COMPLETION_INCOMPLETE => get_string('completion_incomplete', 'condition'), COMPLETION_COMPLETE_PASS => get_string('completion_pass', 'condition'), COMPLETION_COMPLETE_FAIL => get_string('completion_fail', 'condition')); $grouparray = array(); $grouparray[] =& $mform->createElement('select', 'conditionsourcecmid', '', $completionoptions); $grouparray[] =& $mform->createElement('select', 'conditionrequiredcompletion', '', $completionvalues); $group = $mform->createElement('group', 'conditioncompletiongroup', get_string('completioncondition', 'condition'), $grouparray); $count = empty($this->_cm) ? 1 : count($this->_cm->conditionscompletion) + 1; $this->repeat_elements(array($group), $count, array(), 'conditioncompletionrepeats', 'conditioncompletionadds', 2, get_string('addcompletions', 'condition'), true); $mform->setHelpButton('conditioncompletiongroup[0]', array('completioncondition', get_string('help_completioncondition', 'condition'), 'condition')); } // Do we display availability info to students? $mform->addElement('select', 'showavailability', get_string('showavailability', 'condition'), array(CONDITION_STUDENTVIEW_SHOW => get_string('showavailability_show', 'condition'), CONDITION_STUDENTVIEW_HIDE => get_string('showavailability_hide', 'condition'))); $mform->setDefault('showavailability', CONDITION_STUDENTVIEW_SHOW); $mform->setHelpButton('showavailability', array('showavailability', get_string('help_showavailability', 'condition'), 'condition')); } // Conditional activities: completion tracking section if (!isset($completion)) { $completion = new completion_info($COURSE); } if ($completion->is_enabled()) { $mform->addElement('header', '', 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->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->setHelpButton('completion', array('completion', get_string('help_completion', 'completion'), 'completion')); $mform->setDefault('completion', $this->_features->defaultcompletion ? COMPLETION_TRACKING_MANUAL : COMPLETION_TRACKING_NONE); // 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_text', 'completion')); $mform->setHelpButton('completionview', array('completionview', get_string('help_completionview', 'completion'), '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_text', 'completion')); $mform->setHelpButton('completionusegrade', array('completionusegrade', get_string('help_completionusegrade', 'completion'), 'completion')); $mform->disabledIf('completionusegrade', 'completion', 'ne', COMPLETION_TRACKING_AUTOMATIC); $gotcompletionoptions = true; } // 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->setHelpButton('completionexpected', array('completionexpected', get_string('help_completionexpected', 'completion'), 'completion')); $mform->disabledIf('completionexpected', 'completion', 'eq', COMPLETION_TRACKING_NONE); } $this->standard_hidden_coursemodule_elements(); }
/** * Copies the outcomes (and associates to course if necessary) from * a source emarking activity to a destination one * * @param unknown $emarkingsrc * @param unknown $emarkingdst * @return boolean */ function emarking_copy_course_outcomes($emarkingsrc, $emarkingdst) { global $DB, $CFG; require_once $CFG->libdir . "/gradelib.php"; require_once $CFG->libdir . "/grade/grade_outcome.php"; if (!($coursesrc = $DB->get_record('course', array('id' => $emarkingsrc->course)))) { return false; } if (!($coursedst = $DB->get_record('course', array('id' => $emarkingdst->course)))) { return false; } $params = array($coursesrc->id, $emarkingsrc->id); $sql = "SELECT outcomeid, itemnumber\n FROM {grade_items}\n WHERE courseid=? AND outcomeid IS NOT NULL\n AND itemmodule = 'emarking' AND iteminstance = ?\n AND itemtype = 'mod'"; $tocopy = $DB->get_records_sql($sql, $params); $outcomesready = array(); foreach ($tocopy as $outcomeused) { $outcomesready[] = $outcomeused->outcomeid; } $params = array($coursedst->id, $emarkingdst->id); $sql = "SELECT outcomeid, itemnumber\n FROM {grade_items}\n WHERE courseid=? AND outcomeid IS NOT NULL\n AND itemmodule = 'emarking' AND iteminstance = ?\n AND itemtype = 'mod'"; $realused = $DB->get_records_sql($sql, $params); $maxitemnumber = 999; foreach ($realused as $outcomeused) { if (array_search($outcomeused->outcomeid, $outcomesready)) { array_remove_by_value($outcomesready, $outcomeused->outcomeid); } if ($outcomeused->itemnumber > $maxitemnumber) { $maxitemnumber = $outcomeused->itemnumber; } } $outcomesdst = grade_outcome::fetch_all_available($emarkingdst->course); $outcomesavailable = array(); foreach ($outcomesdst as $outcomedst) { $outcomesavailable[] = $outcomedst->id; } if ($maxitemnumber < 1000) { $maxitemnumber = 1000; } foreach ($outcomesready as $outcometocopy) { $outcome = grade_outcome::fetch(array('id' => $outcometocopy)); if (!array_search($outcometocopy, $outcomesavailable)) { $outcome->use_in($emarkingdst->course); } $outcomeitem = new grade_item(); $outcomeitem->courseid = $emarkingdst->course; $outcomeitem->itemtype = 'mod'; $outcomeitem->itemmodule = 'emarking'; $outcomeitem->iteminstance = $emarkingdst->id; $outcomeitem->itemnumber = $maxitemnumber; $outcomeitem->itemname = $outcome->fullname; $outcomeitem->outcomeid = $outcome->id; $outcomeitem->gradetype = GRADE_TYPE_SCALE; $outcomeitem->scaleid = $outcome->scaleid; $outcomeitem->insert(); $maxitemnumber++; } return true; }
function definition() { global $COURSE, $CFG; $mform =& $this->_form; /// visible elements $mform->addElement('header', 'general', get_string('gradeoutcomeitem', 'grades')); $mform->addElement('text', 'itemname', get_string('itemname', 'grades')); $mform->addRule('itemname', get_string('required'), 'required', null, 'client'); $mform->addElement('text', 'iteminfo', get_string('iteminfo', 'grades')); $mform->setHelpButton('iteminfo', array(false, get_string('iteminfo', 'grades'), false, true, false, get_string('iteminfohelp', 'grades'))); $mform->addElement('text', 'idnumber', get_string('idnumber')); $mform->setHelpButton('idnumber', array(false, get_string('idnumber'), false, true, false, get_string('idnumberhelp', 'grades'))); // allow setting of outcomes on module items too $options = array(); if ($outcomes = grade_outcome::fetch_all_available($COURSE->id)) { foreach ($outcomes as $outcome) { $options[$outcome->id] = $outcome->get_name(); } } $mform->addElement('select', 'outcomeid', get_string('outcome', 'grades'), $options); $mform->setHelpButton('outcomeid', array(false, get_string('outcomeid', 'grades'), false, true, false, get_string('outcomeidhelp', 'grades'))); $mform->addRule('outcomeid', get_string('required'), 'required'); $options = array(0 => get_string('none')); if ($coursemods = get_course_mods($COURSE->id)) { foreach ($coursemods as $coursemod) { $mod = get_coursemodule_from_id($coursemod->modname, $coursemod->id); $options[$coursemod->id] = format_string($mod->name); } } $mform->addElement('select', 'cmid', get_string('linkedactivity', 'grades'), $options); $mform->setHelpButton('cmid', array(false, get_string('linkedactivity', 'grades'), false, true, false, get_string('linkedactivityhelp', 'grades'))); $mform->setDefault('cmid', 0); //$mform->addElement('text', 'calculation', get_string('calculation', 'grades')); /*$mform->addElement('text', 'gradepass', get_string('gradepass', 'grades')); $mform->setHelpButton('gradepass', array(false, get_string('gradepass', 'grades'), false, true, false, get_string('gradepasshelp', 'grades')));*/ $mform->addElement('text', 'aggregationcoef', get_string('aggregationcoef', 'grades')); $mform->setHelpButton('aggregationcoef', array(false, get_string('aggregationcoef', 'grades'), false, true, false, get_string('aggregationcoefhelp', 'grades'))); /// hiding /// advcheckbox is not compatible with disabledIf !! $mform->addElement('checkbox', 'hidden', get_string('hidden', 'grades')); $mform->setHelpButton('hidden', array('hidden', get_string('hidden', 'grades'), 'grade')); $mform->addElement('date_time_selector', 'hiddenuntil', get_string('hiddenuntil', 'grades'), array('optional' => true)); $mform->setHelpButton('hiddenuntil', array('hiddenuntil', get_string('hiddenuntil', 'grades'), 'grade')); $mform->disabledIf('hidden', 'hiddenuntil[off]', 'notchecked'); //locking $mform->addElement('advcheckbox', 'locked', get_string('locked', 'grades')); $mform->setHelpButton('locked', array('locked', get_string('locked', 'grades'), 'grade')); $mform->addElement('date_time_selector', 'locktime', get_string('locktime', 'grades'), array('optional' => true)); $mform->setHelpButton('locktime', array('locktime', get_string('locktime', 'grades'), 'grade')); /// hidden params $mform->addElement('hidden', 'id', 0); $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'courseid', $COURSE->id); $mform->setType('courseid', PARAM_INT); /// add return tracking info $gpr = $this->_customdata['gpr']; $gpr->add_mform_elements($mform); //------------------------------------------------------------------------------- // buttons $this->add_action_buttons(); }