function test_has_activities() { global $DB; $this->resetAfterTest(true); // Create a course with mixed auto completion data. $course = $this->getDataGenerator()->create_course(); $course2 = $this->getDataGenerator()->create_course(); $completionauto = array('completion' => COMPLETION_TRACKING_AUTOMATIC); $completionnone = array('completion' => COMPLETION_TRACKING_NONE); $c1forum = $this->getDataGenerator()->create_module('forum', array('course' => $course->id), $completionauto); $c2forum = $this->getDataGenerator()->create_module('forum', array('course' => $course2->id), $completionnone); $c1 = new completion_info($course); $c2 = new completion_info($course2); $this->assertTrue($c1->has_activities()); $this->assertFalse($c2->has_activities()); }
/** * This function extends the navigation with the report items * * @param navigation_node $navigation The navigation node to extend * @param stdClass $course The course to object for the report * @param stdClass $context The context of the course */ function report_progress_extend_navigation_course($navigation, $course, $context) { global $CFG, $OUTPUT; require_once $CFG->libdir . '/completionlib.php'; $showonnavigation = has_capability('report/progress:view', $context); $group = groups_get_course_group($course, true); // Supposed to verify group if ($group === 0 && $course->groupmode == SEPARATEGROUPS) { $showonnavigation = $showonnavigation && has_capability('moodle/site:accessallgroups', $context); } $completion = new completion_info($course); $showonnavigation = $showonnavigation && $completion->is_enabled() && $completion->has_activities(); if ($showonnavigation) { $url = new moodle_url('/report/progress/index.php', array('course' => $course->id)); $navigation->add(get_string('pluginname', 'report_progress'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', '')); } }
public function test_has_activities() { global $CFG; $this->resetAfterTest(); // Enable completion before creating modules, otherwise the completion data is not written in DB. $CFG->enablecompletion = true; // Create a course with mixed auto completion data. $course = $this->getDataGenerator()->create_course(array('enablecompletion' => true)); $course2 = $this->getDataGenerator()->create_course(array('enablecompletion' => true)); $completionauto = array('completion' => COMPLETION_TRACKING_AUTOMATIC); $completionnone = array('completion' => COMPLETION_TRACKING_NONE); $c1forum = $this->getDataGenerator()->create_module('forum', array('course' => $course->id), $completionauto); $c2forum = $this->getDataGenerator()->create_module('forum', array('course' => $course2->id), $completionnone); $c1 = new completion_info($course); $c2 = new completion_info($course2); $this->assertTrue($c1->has_activities()); $this->assertFalse($c2->has_activities()); }