/** * Export the data. * * @param renderer_base $output * @return stdClass */ public function export_for_template(renderer_base $output) { global $CFG, $DB, $PAGE; $context = context_course::instance($this->courseid); $data = new stdClass(); $data->userid = $this->userid; $data->competencyid = $this->competencyid; $data->courseid = $this->courseid; $data->baseurl = $this->baseurl; $data->groupselector = ''; if (has_any_capability(array('moodle/competency:usercompetencyview', 'moodle/competency:coursecompetencymanage'), $context)) { $course = $DB->get_record('course', array('id' => $this->courseid)); $currentgroup = groups_get_course_group($course, true); if ($currentgroup !== false) { $select = groups_allgroups_course_menu($course, $PAGE->url, true, $currentgroup); $data->groupselector = $select; } // Fetch showactive. $defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol); $showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol); $showonlyactiveenrol = $showonlyactiveenrol || !has_capability('moodle/course:viewsuspendedusers', $context); $users = get_enrolled_users($context, 'moodle/competency:coursecompetencygradable', $currentgroup, 'u.*', null, 0, 0, $showonlyactiveenrol); $data->users = array(); foreach ($users as $user) { $exporter = new user_summary_exporter($user); $user = $exporter->export($output); if ($user->id == $this->userid) { $user->selected = true; } $data->users[] = $user; } $data->hasusers = true; } else { $data->users = array(); $data->hasusers = false; } $coursecompetencies = \core_competency\api::list_course_competencies($this->courseid); $data->competencies = array(); $contextcache = array(); foreach ($coursecompetencies as $coursecompetency) { $frameworkid = $coursecompetency['competency']->get_competencyframeworkid(); if (!isset($contextcache[$frameworkid])) { $contextcache[$frameworkid] = $coursecompetency['competency']->get_context(); } $context = $contextcache[$frameworkid]; $coursecompetencycontext = $context; $exporter = new competency_exporter($coursecompetency['competency'], array('context' => $coursecompetencycontext)); $competency = $exporter->export($output); if ($competency->id == $this->competencyid) { $competency->selected = true; } $data->competencies[] = $competency; } $data->hascompetencies = count($data->competencies); return $data; }
$minloginternalreader = $DB->get_field_sql('SELECT min(timecreated) FROM {' . $logtable . '} WHERE courseid = ?', array($course->id)); // If new log store has oldest data then don't use old log table. if (empty($minlog) || $minloginternalreader <= $minlog) { $uselegacyreader = false; $minlog = $minloginternalreader; } // If timefrom is greater then first record in sql_internal_reader then get record from sql_internal_reader only. if (!empty($timefrom) && $minloginternalreader < $timefrom) { $uselegacyreader = false; } } // Print first controls. report_participation_print_filter_form($course, $timefrom, $minlog, $action, $roleid, $instanceid); $baseurl = new moodle_url('/report/participation/index.php', array('id' => $course->id, 'roleid' => $roleid, 'instanceid' => $instanceid, 'timefrom' => $timefrom, 'action' => $action, 'perpage' => $perpage, 'group' => $currentgroup)); $select = groups_allgroups_course_menu($course, $baseurl, true, $currentgroup); // User cannot see any group. if (empty($select)) { echo $OUTPUT->heading(get_string("notingroup")); echo $OUTPUT->footer(); exit; } else { echo $select; } // Fetch current active group. $groupmode = groups_get_course_groupmode($course); $currentgroup = $SESSION->activegroup[$course->id][$groupmode][$course->defaultgroupingid]; if (!empty($instanceid) && !empty($roleid)) { // Trigger a report viewed event. $event = \report_participation\event\report_viewed::create(array('context' => $context, 'other' => array('instanceid' => $instanceid, 'groupid' => $currentgroup, 'roleid' => $roleid, 'timefrom' => $timefrom, 'action' => $action))); $event->trigger();
/** * Tests for groups_allgroups_course_menu() . */ public function test_groups_allgroups_course_menu() { global $SESSION; $this->resetAfterTest(); // Generate data. $course = $this->getDataGenerator()->create_course(); $record = new stdClass(); $record->courseid = $course->id; $group1 = $this->getDataGenerator()->create_group($record); $group2 = $this->getDataGenerator()->create_group($record); $user = $this->getDataGenerator()->create_user(); $this->getDataGenerator()->enrol_user($user->id, $course->id); $this->setUser($user); $html = groups_allgroups_course_menu($course, 'someurl.php'); // Since user is not a part of this group and doesn't have accessallgroups permission, // the html should be empty. $this->assertEmpty($html); groups_add_member($group1->id, $user); // Now user can access one of the group. We can't assert an exact match here because of random ids generated by yui. So do // partial match to see if all groups are listed or not. $html = groups_allgroups_course_menu($course, 'someurl.php'); $this->assertContains(format_string($group1->name), $html); $this->assertNotContains(format_string($group2->name), $html); $this->setAdminUser(); // Now user can access everything. $html = groups_allgroups_course_menu($course, 'someurl.php'); $this->assertContains(format_string($group1->name), $html); $this->assertContains(format_string($group2->name), $html); // Make sure separate groups mode, doesn't change anything. $course->groupmode = SEPARATEGROUPS; update_course($course); $html = groups_allgroups_course_menu($course, 'someurl.php'); $this->assertContains(format_string($group1->name), $html); $this->assertContains(format_string($group2->name), $html); // Make sure Visible groups mode, doesn't change anything. $course->groupmode = VISIBLEGROUPS; update_course($course); $html = groups_allgroups_course_menu($course, 'someurl.php'); $this->assertContains(format_string($group1->name), $html); $this->assertContains(format_string($group2->name), $html); // Let us test activegroup changes now. $this->setUser($user); $SESSION->activegroup[$course->id][VISIBLEGROUPS][$course->defaultgroupingid] = 5; groups_allgroups_course_menu($course, 'someurl.php', false); // Do not update session. $this->assertSame(5, $SESSION->activegroup[$course->id][VISIBLEGROUPS][$course->defaultgroupingid]); groups_allgroups_course_menu($course, 'someurl.php', true, $group1->id); // Update session. $this->assertSame($group1->id, $SESSION->activegroup[$course->id][VISIBLEGROUPS][$course->defaultgroupingid]); // Try to update session with an invalid groupid. It should not accept the invalid id. groups_allgroups_course_menu($course, 'someurl.php', true, 256); $this->assertEquals($group1->id, $SESSION->activegroup[$course->id][VISIBLEGROUPS][$course->defaultgroupingid]); }