Skip to content

Commit

Permalink
MDL-12122 Changed userid to PARAM_INT, and changed 'all' to 0
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasconnault committed Jan 17, 2008
1 parent 047901c commit 3983345
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
28 changes: 12 additions & 16 deletions grade/lib.php
Expand Up @@ -131,18 +131,6 @@ function init() {
}
return true;
}

/**
* Returns the number of graded users in the course. Needs to be called after init(), otherwise returns null.
* @return int Number of users in course
*/
function users_count() {
if (method_exists($this->users_rs, 'RecordCount')) {
return $this->users_rs->RecordCount();
} else {
return null;
}
}

/**
* Returns information about the next user
Expand Down Expand Up @@ -256,8 +244,12 @@ function _pop() {
* @param bool $return If true, will return the HTML, otherwise, will print directly
* @return null
*/
function print_graded_users_selector($course, $actionpage, $userid='all', $return=false) {
global $CFG;
function print_graded_users_selector($course, $actionpage, $userid=null, $return=false) {
global $CFG, $USER;

if (is_null($userid)) {
$userid = $USER->id;
}

$context = get_context_instance(CONTEXT_COURSE, $course->id);

Expand All @@ -266,8 +258,8 @@ function print_graded_users_selector($course, $actionpage, $userid='all', $retur
$gui = new graded_users_iterator($course);
$gui->init();

if ($userid != 'all') {
$menu['all'] = get_string('allusers', 'grades') . ' (' . $gui->users_count() . ')';
if ($userid !== 0) {
$menu[0] = get_string('allusers', 'grades');
}

while ($userdata = $gui->next_user()) {
Expand All @@ -276,6 +268,10 @@ function print_graded_users_selector($course, $actionpage, $userid='all', $retur
}

$gui->close();

if ($userid !== 0) {
$menu[0] .= " (" . (count($menu) - 1) . ")";
}

return popup_form($CFG->wwwroot.'/grade/' . $actionpage . '&userid=', $menu, 'choosegradeduser', $userid, 'choose', '', '',
$return, 'self', get_string('selectalloroneuser', 'grades'));
Expand Down
6 changes: 3 additions & 3 deletions grade/report/user/index.php
Expand Up @@ -28,7 +28,7 @@
require_once $CFG->dirroot.'/grade/report/user/lib.php';

$courseid = required_param('id');
$userid = optional_param('userid', $USER->id, PARAM_ALPHANUM);
$userid = optional_param('userid', $USER->id, PARAM_INT);

/// basic access checks
if (!$course = get_record('course', 'id', $courseid)) {
Expand All @@ -37,7 +37,7 @@
require_login($course);


if ($userid != 'all' && !$user = get_complete_user_data('id', $userid)) {
if ($userid !== 0 && !$user = get_complete_user_data('id', $userid)) {
error("Incorrect userid");
}

Expand Down Expand Up @@ -93,7 +93,7 @@
print_graded_users_selector($course, 'report/user/index.php?id=' . $course->id, $userid);
echo '</div>';

if ($userid == 'all') {
if ($userid === 0) {
$gui = new graded_users_iterator($course);
$gui->init();
while ($userdata = $gui->next_user()) {
Expand Down

0 comments on commit 3983345

Please sign in to comment.