* @param bool $selfitemisempty True if we have not selected a user.
*/
public function init($selfitemisempty = false) {
- $roleids = explode(',', get_config('moodle', 'gradebookroles'));
-
- $this->items = array();
- foreach ($roleids as $roleid) {
- // Keeping the first user appearance.
- $this->items = $this->items + get_role_users(
- $roleid, $this->context, false, '',
- 'u.lastname, u.firstname', null, $this->groupid);
- }
- $this->totalitemcount = count_role_users($roleids, $this->context);
+ $this->items = $this->load_users();
+ $this->totalitemcount = count($this->items);
if ($selfitemisempty) {
return;
new moodle_url('/grade/report/singleview/index.php', array(
'perpage' => $this->perpage,
'id' => $this->courseid,
- 'groupid' => $this->groupid,
+ 'group' => $this->groupid,
'itemid' => $this->itemid,
'item' => 'grade'
))
public function supports_next_prev() {
return true;
}
+
+ /**
+ * Load a valid list of users for this gradebook as the screen "items".
+ * @return array $users A list of enroled users.
+ */
+ protected function load_users() {
+ global $CFG;
+
+ // Create a graded_users_iterator because it will properly check the groups etc.
+ $defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol);
+ $showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol);
+ $showonlyactiveenrol = $showonlyactiveenrol || !has_capability('moodle/course:viewsuspendedusers', $this->context);
+
+ require_once($CFG->dirroot.'/grade/lib.php');
+ $gui = new \graded_users_iterator($this->course, null, $this->groupid);
+ $gui->require_active_enrolment($showonlyactiveenrol);
+ $gui->init();
+
+ // Flatten the users.
+ $users = array();
+ while ($user = $gui->next_user()) {
+ $users[$user->user->id] = $user->user;
+ }
+ return $users;
+ }
}
global $DB;
if (!$selfitemisempty) {
- $this->item = $DB->get_record('user', array('id' => $this->itemid));
+ $validusers = $this->load_users();
+ if (!isset($validusers[$this->itemid])) {
+ print_error('invaliduserid');
+ }
+ $this->item = $validusers[$this->itemid];
}
$params = array('courseid' => $this->courseid);
new moodle_url('/grade/report/singleview/index.php', array(
'perpage' => $this->perpage,
'id' => $this->courseid,
- 'groupid' => $this->groupid,
+ 'group' => $this->groupid,
'itemid' => $this->itemid,
'item' => 'user'
))
// this must be done before constructing of the grade tree.
grade_regrade_final_grades($courseid);
-$report = new gradereport_singleview(
- $courseid, $gpr, $context,
- $itemtype, $itemid, $groupid
-);
+$report = new gradereport_singleview($courseid, $gpr, $context, $itemtype, $itemid);
$reportname = $report->screen->heading();
$relreport = new gradereport_singleview(
$courseid, $gpr, $context,
- $report->screen->item_type(), $optionitemid, $groupid
+ $report->screen->item_type(), $optionitemid
);
$reloptions = $relreport->screen->options();
$reloptionssorting = array_keys($relreport->screen->options());
* @param context_course $context
* @param string $itemtype Should be user, select or grade
* @param int $itemid The id of the user or grade item
- * @param int $groupid (optional) The current groupid.
+ * @param string $unused Used to be group id but that was removed and this is now unused.
*/
- public function __construct($courseid, $gpr, $context, $itemtype, $itemid, $groupid=null) {
+ public function __construct($courseid, $gpr, $context, $itemtype, $itemid, $unused = null) {
parent::__construct($courseid, $gpr, $context);
- $screenclass = "\\gradereport_singleview\\local\\screen\\${itemtype}";
-
- $this->screen = new $screenclass($courseid, $itemid, $groupid);
-
- // Load custom or predifined js.
- $this->screen->js();
-
$base = '/grade/report/singleview/index.php';
$idparams = array('id' => $courseid);
$this->baseurl = new moodle_url($base, $idparams);
$this->pbarurl = new moodle_url($base, $idparams + array(
- 'item' => $itemtype,
- 'itemid' => $itemid
- ));
+ 'item' => $itemtype,
+ 'itemid' => $itemid
+ ));
+ // The setup_group method is used to validate group mode and permissions and define the currentgroup value.
$this->setup_groups();
+
+ $screenclass = "\\gradereport_singleview\\local\\screen\\${itemtype}";
+
+ $this->screen = new $screenclass($courseid, $itemid, $this->currentgroup);
+
+ // Load custom or predifined js.
+ $this->screen->js();
}
/**
This files describes API changes in /grade/report/*,
information provided here is intended especially for developers.
+=== 2.8.1 ===
+* gradereport_singleview::__construct doesn't need groupid parameter anymore, so it was renamed to $unused.
+
=== 2.6.5, 2.7.2 ===
* The callback function grade_report_*_profilereport now takes one more parameter $viewasuser. This parameter