/** * Constructor for this renderable. * * @param int $userid The user we will open the grading app too. * @param int $groupid If groups are enabled this is the current course group. * @param assign $assignment The assignment class */ public function __construct($userid, $groupid, $assignment) { $this->userid = $userid; $this->groupid = $groupid; $this->assignment = $assignment; $this->participants = $assignment->list_participants_with_filter_status_and_group($groupid); if (!$this->userid && count($this->participants)) { $this->userid = reset($this->participants)->id; } }
/** * Retrieves the list of students to be graded for the assignment. * * @param int $assignid the assign instance id * @param int $groupid the current group id * @param string $filter search string to filter the results. * @param int $skip Number of records to skip * @param int $limit Maximum number of records to return * @return array of warnings and status result * @since Moodle 3.1 * @throws moodle_exception */ public static function list_participants($assignid, $groupid, $filter, $skip, $limit) { global $DB, $CFG; require_once $CFG->dirroot . "/mod/assign/locallib.php"; require_once $CFG->dirroot . "/user/lib.php"; $params = self::validate_parameters(self::list_participants_parameters(), array('assignid' => $assignid, 'groupid' => $groupid, 'filter' => $filter, 'skip' => $skip, 'limit' => $limit)); $warnings = array(); // Request and permission validation. $assign = $DB->get_record('assign', array('id' => $params['assignid']), 'id', MUST_EXIST); list($course, $cm) = get_course_and_cm_from_instance($assign, 'assign'); $context = context_module::instance($cm->id); self::validate_context($context); require_capability('mod/assign:view', $context); $assign = new assign($context, null, null); $assign->require_view_grades(); $participants = $assign->list_participants_with_filter_status_and_group($params['groupid']); $result = array(); $index = 0; foreach ($participants as $record) { // Preserve the fullname set by the assignment. $fullname = $record->fullname; $searchable = $fullname; $match = false; if (empty($filter)) { $match = true; } else { $filter = core_text::strtolower($filter); $value = core_text::strtolower($searchable); if (is_string($value) && core_text::strpos($value, $filter) !== false) { $match = true; } } if ($match) { $index++; if ($index <= $params['skip']) { continue; } if ($params['limit'] > 0 && $index - $params['skip'] > $params['limit']) { break; } // Now we do the expensive lookup of user details because we completed the filtering. if (!$assign->is_blind_marking() && !$params['onlyids']) { $userdetails = user_get_user_details($record, $course); } else { $userdetails = array('id' => $record->id); } $userdetails['fullname'] = $fullname; $userdetails['submitted'] = $record->submitted; $userdetails['requiregrading'] = $record->requiregrading; if (!empty($record->groupid)) { $userdetails['groupid'] = $record->groupid; } if (!empty($record->groupname)) { $userdetails['groupname'] = $record->groupname; } $result[] = $userdetails; } } return $result; }