public function test_constructor() { $generator = $this->getDataGenerator(); $course = $generator->create_course(); $page = $generator->get_plugin_generator('mod_page')->create_instance(array('course' => $course)); $modinfo = get_fast_modinfo($course); // No ID. try { $test = new condition_info((object) array()); $this->fail(); } catch (coding_exception $e) { // Do nothing. $this->assertDebuggingCalled(); } // Get actual cm_info for comparison. $realcm = $modinfo->get_cm($page->cmid); // No other data. $test = new condition_info((object) array('id' => $page->cmid)); $this->assertDebuggingCalled(); $this->assertEquals($realcm, $test->get_full_course_module()); $this->assertDebuggingCalled(); // Course id. $test = new condition_info((object) array('id' => $page->cmid, 'course' => $course->id)); $this->assertDebuggingCalled(); $this->assertEquals($realcm, $test->get_full_course_module()); $this->assertDebuggingCalled(); // Full cm. $test = new condition_info($realcm); $this->assertDebuggingCalled(); $this->assertEquals($realcm, $test->get_full_course_module()); $this->assertDebuggingCalled(); }
/** * 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(); }
/** * Tests grade_report_user::inject_rowspans() * * inject_rowspans() returns the count of the number of elements, sets maxdepth on the * report object and sets the rowspan property on any element that has children. */ public function test_inject_rowspans() { global $CFG, $USER, $DB; parent::setUp(); $this->resetAfterTest(true); $CFG->enableavailability = 1; $CFG->enablecompletion = 1; // Create a course. $course = $this->getDataGenerator()->create_course(); $coursecategory = grade_category::fetch_course_category($course->id); $coursecontext = context_course::instance($course->id); // Create and enrol test users. $student = $this->getDataGenerator()->create_user(array('username' => 'Student Sam')); $role = $DB->get_record('role', array('shortname' => 'student'), '*', MUST_EXIST); $this->getDataGenerator()->enrol_user($student->id, $course->id, $role->id); $teacher = $this->getDataGenerator()->create_user(array('username' => 'Teacher T')); $role = $DB->get_record('role', array('shortname' => 'editingteacher'), '*', MUST_EXIST); $this->getDataGenerator()->enrol_user($teacher->id, $course->id, $role->id); // An array so we can test with both users in a loop. $users = array($student, $teacher); // Make the student the current user. $this->setUser($student); // Test an empty course. $report = $this->create_report($course, $student, $coursecontext); // a lead column that spans all children + course grade item = 2 $this->assertEquals(2, $report->inject_rowspans($report->gtree->top_element)); $this->assertEquals(2, $report->gtree->top_element['rowspan']); $this->assertEquals(2, $report->maxdepth); // Only elements with children should have rowspan set. if (array_key_exists('rowspan', $report->gtree->top_element['children'][1])) { $this->fail('Elements without children should not have rowspan set'); } // Add 2 activities. $data1 = $this->getDataGenerator()->create_module('data', array('assessed' => 1, 'scale' => 100, 'course' => $course->id)); $forum1 = $this->getDataGenerator()->create_module('forum', array('assessed' => 1, 'scale' => 100, 'course' => $course->id)); $forum1cm = get_coursemodule_from_id('forum', $forum1->cmid); // Switch the stdClass instance for a grade item instance so grade_item::set_parent() is available. $forum1 = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => 'forum', 'iteminstance' => $forum1->id, 'courseid' => $course->id)); $report = $this->create_report($course, $student, $coursecontext); // Lead column + course + (2 x activity) = 4 $this->assertEquals(4, $report->inject_rowspans($report->gtree->top_element)); $this->assertEquals(4, $report->gtree->top_element['rowspan']); // Lead column + 1 level (course + 2 activities) = 2 $this->assertEquals(2, $report->maxdepth); // Only elements with children should have rowspan set. if (array_key_exists('rowspan', $report->gtree->top_element['children'][1])) { $this->fail('Elements without children should not have rowspan set'); } // Hide the forum activity. set_coursemodule_visible($forum1cm->id, 0); foreach ($users as $user) { $this->setUser($user); $message = 'Testing with ' . $user->username; accesslib_clear_all_caches_for_unit_testing(); $report = $this->create_report($course, $user, $coursecontext); // Lead column + course + (2 x activity) = 4 (element count isn't affected by hiding) $this->assertEquals(4, $report->inject_rowspans($report->gtree->top_element), $message); $this->assertEquals(4, $report->gtree->top_element['rowspan'], $message); // Lead column -> 1 level containing the course + 2 activities = 2 $this->assertEquals(2, $report->maxdepth, $message); } // Unhide the forum activity. set_coursemodule_visible($forum1cm->id, 1); // Create a category and put the forum in it. $params = new stdClass(); $params->courseid = $course->id; $params->fullname = 'unittestcategory'; $params->parent = $coursecategory->id; $gradecategory = new grade_category($params, false); $gradecategory->insert(); $forum1->set_parent($gradecategory->id); $report = $this->create_report($course, $student, $coursecontext); // Lead column + course + (category + category grade item) + (2 x activity) = 6 $this->assertEquals(6, $report->inject_rowspans($report->gtree->top_element)); $this->assertEquals(6, $report->gtree->top_element['rowspan']); // Lead column -> the category -> the forum activity = 3 $this->assertEquals(3, $report->maxdepth); // Check rowspan on the category. The category itself + category grade item + forum = 3 $this->assertEquals(3, $report->gtree->top_element['children'][4]['rowspan']); // check the forum doesn't have rowspan set if (array_key_exists('rowspan', $report->gtree->top_element['children'][4]['children'][3])) { $this->fail('The forum has no children so should not have rowspan set'); } // Conditional activity tests. $DB->insert_record('course_modules_availability', (object) array('coursemoduleid' => $forum1cm->id, 'gradeitemid' => 37, 'grademin' => 5.5)); $cm = (object) array('id' => $forum1cm->id); $test = new condition_info($cm, CONDITION_MISSING_EVERYTHING); $fullcm = $test->get_full_course_module(); foreach ($users as $user) { $this->setUser($user); $message = 'Testing with ' . $user->username; accesslib_clear_all_caches_for_unit_testing(); $report = $this->create_report($course, $user, $coursecontext); // Lead column + course + (category + category grade item) + (2 x activity) = 6 $this->assertEquals(6, $report->inject_rowspans($report->gtree->top_element), $message); $this->assertEquals(6, $report->gtree->top_element['rowspan'], $message); // Lead column -> the category -> the forum activity = 3 $this->assertEquals(3, $report->maxdepth, $message); } }
function test_add_and_remove() { global $DB; // Make course and module $courseid = $this->make_course(); $cmid = $this->make_course_module($courseid, array('showavailability' => 0, 'availablefrom' => 0, 'availableuntil' => 0)); $this->make_section($courseid, array($cmid)); // Check it has no conditions $test1 = new condition_info((object) array('id' => $cmid), CONDITION_MISSING_EVERYTHING); $cm = $test1->get_full_course_module(); $this->assertEqual(array(), $cm->conditionscompletion); $this->assertEqual(array(), $cm->conditionsgrade); // Add conditions of each type $test1->add_completion_condition(13, 3); $this->assertEqual(array(13 => 3), $cm->conditionscompletion); $test1->add_grade_condition(666, 0.4, null, true); $this->assertEqual(array(666 => (object) array('min' => 0.4, 'max' => null, 'name' => '!missing')), $cm->conditionsgrade); // Check they were really added in db $test2 = new condition_info((object) array('id' => $cmid), CONDITION_MISSING_EVERYTHING); $cm = $test2->get_full_course_module(); $this->assertEqual(array(13 => 3), $cm->conditionscompletion); $this->assertEqual(array(666 => (object) array('min' => 0.4, 'max' => null, 'name' => '!missing')), $cm->conditionsgrade); // Wipe conditions $test2->wipe_conditions(); $this->assertEqual(array(), $cm->conditionscompletion); $this->assertEqual(array(), $cm->conditionsgrade); // Check they were really wiped $test3 = new condition_info((object) array('id' => $cmid), CONDITION_MISSING_EVERYTHING); $cm = $test3->get_full_course_module(); $this->assertEqual(array(), $cm->conditionscompletion); $this->assertEqual(array(), $cm->conditionsgrade); }
/** * 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(); }