Get current graded student id from advance grading plugin for new type assignments

Get current graded student id from advance grading plugin for new type assignments

by John Dimopoulos -
Number of replies: 6

Hello everyone,


I am cuurently developing a new plugin for advanced grading and I came across the following obstacle:

I want the id of the current student being graded so that I can use it in my plugin in the student evaluation form.

The problem appears only in the new type assignment (Moodle 2.3). The previous assignment types pass this information through the URL and I simply use optional_param function.

Can anyone tell me how can I get this? Preferably through a Global variable like $PAGE?

Thank you in advance smile.

Average of ratings: -
In reply to John Dimopoulos

Re: Get current graded student id from advance grading plugin for new type assignments

by Andrew Normore -

Are you looking for the $USER->id perhaps?

(Make sure you global $USER; first)

In reply to Andrew Normore

Απάντηση: Re: Get current graded student id from advance grading plugin for new type assignments

by John Dimopoulos -

Thank you Andrew, but this gets the evaluator's id (the one who is currently assessing), not the student's (the one who is being graded).

In reply to John Dimopoulos

Απάντηση: Get current graded student id from advance grading plugin for new type assignments

by John Dimopoulos -

Problem solved!


First of all you must obtain the participants list that is used during evaluation. To do that you must use the assign class declared previously.

Use this:

global $CFG;
global $PAGE;
require_once($CFG->dirroot . '/mod/assign/locallib.php');
$context = context_module::instance($PAGE->cm->module);
$assignment = new assign($context, $PAGE->cm, $PAGE->cm->course);
$useridlist = array_keys($assignment->list_participants(0, true));
sort($useridlist);

Then you must obtain the row number (array key of $useridlist). Here we state the problem:
Before the advance grading plugin renderer is called in locallib.php of assign module, all the $_POST variables are deleted by using $_POST = array(), and so you can't check if the user has pressed either 'next' or 'previous' buttons thus you can't define if the next student evaluated is of index key -1 or +1. You can't use optional_param() function or any other similar, and of course you can't use $_POST to get your variables!

Solution: You use the $_REQUEST array object with the appropriate key e.g. 'saveandshownext' and you check whether the 'next' button was pressed or any other! Using the same object you can obtain the previous rownum and with these you can get the appropriate student id from the user id list above.

$rownum = $_REQUEST['rownum'];

In reply to John Dimopoulos

Re: Απάντηση: Get current graded student id from advance grading plugin for new type assignments

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Directly manipulating $_POST like this is not a good solution to anything.

I suggest you re-think your design.

In reply to Tim Hunt

Απάντηση: Re: Απάντηση: Get current graded student id from advance grading plugin for new type assignments

by John Dimopoulos -

I didn't manipulate the $_POST object. The object is reset by the new assign module, before the renderer of my advance grading plugin gets called.

All I did was to reclaim the same variables through $_REQUEST.

Is this inappropriate? An if so, why?

And if I may, why the new assign module resets all $_POST variables?

The comment "the placement of this is important so can pass the list of userids above", is first of all in wrong syntax, and second doesn't really explains what is the ulterior motive of this command.

In reply to John Dimopoulos

Re: Απάντηση: Re: Απάντηση: Get current graded student id from advance grading plugin for new type assignments

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Oh, so it is the new assign module that is behaving badly. How did that get through code-review? I will file a bug. (MDL-35427)