MDL-38128 mod_assign: Fixing count teams and submissions with status
We should restrict the groups to the activity active group. Also improving performance caching get_submission_group() results.
This commit is contained in:
+82
-15
@@ -135,6 +135,9 @@ class assign {
|
||||
/** @var array cached list of participants for this assignment. The cache key will be group, showactive and the context id */
|
||||
private $participants = array();
|
||||
|
||||
/** @var array cached list of user groups when team submissions are enabled. The cache key will be the user. */
|
||||
private $usersubmissiongroups = array();
|
||||
|
||||
/**
|
||||
* Constructor for the base assign class.
|
||||
*
|
||||
@@ -1335,6 +1338,11 @@ class assign {
|
||||
* @return array List of user records
|
||||
*/
|
||||
public function list_participants($currentgroup, $idsonly) {
|
||||
|
||||
if (empty($currentgroup)) {
|
||||
$currentgroup = 0;
|
||||
}
|
||||
|
||||
$key = $this->context->id . '-' . $currentgroup . '-' . $this->show_only_active_users();
|
||||
if (!isset($this->participants[$key])) {
|
||||
$users = get_enrolled_users($this->context, 'mod/assign:submit', $currentgroup, 'u.*', null, null, null,
|
||||
@@ -1360,21 +1368,51 @@ class assign {
|
||||
/**
|
||||
* Load a count of valid teams for this assignment.
|
||||
*
|
||||
* @param int $activitygroup Activity active group
|
||||
* @return int number of valid teams
|
||||
*/
|
||||
public function count_teams() {
|
||||
public function count_teams($activitygroup = 0) {
|
||||
|
||||
$groups = groups_get_all_groups($this->get_course()->id,
|
||||
0,
|
||||
$this->get_instance()->teamsubmissiongroupingid,
|
||||
'g.id');
|
||||
$count = count($groups);
|
||||
$count = 0;
|
||||
|
||||
// See if there are any users in the default group.
|
||||
$defaultusers = $this->get_submission_group_members(0, true);
|
||||
if (count($defaultusers) > 0) {
|
||||
$count += 1;
|
||||
$participants = $this->list_participants($activitygroup, true);
|
||||
|
||||
// If a team submission grouping id is provided all good as all returned groups
|
||||
// are the submission teams, but if no team submission grouping was specified
|
||||
// $groups will contain all participants groups.
|
||||
if ($this->get_instance()->teamsubmissiongroupingid) {
|
||||
|
||||
// We restrict the users to the selected group ones.
|
||||
$groups = groups_get_all_groups($this->get_course()->id,
|
||||
array_keys($participants),
|
||||
$this->get_instance()->teamsubmissiongroupingid,
|
||||
'DISTINCT g.id, g.name');
|
||||
|
||||
$count = count($groups);
|
||||
|
||||
// When a specific group is selected we don't count the default group users.
|
||||
if ($activitygroup == 0) {
|
||||
|
||||
// See if there are any users in the default group.
|
||||
$defaultusers = $this->get_submission_group_members(0, true);
|
||||
if (count($defaultusers) > 0) {
|
||||
$count += 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// It is faster to loop around participants if no grouping was specified.
|
||||
$groups = array();
|
||||
foreach ($participants as $participant) {
|
||||
if ($group = $this->get_submission_group($participant->id)) {
|
||||
$groups[$group->id] = true;
|
||||
} else {
|
||||
$groups[0] = true;
|
||||
}
|
||||
}
|
||||
|
||||
$count = count($groups);
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
@@ -1523,6 +1561,20 @@ class assign {
|
||||
$params['submissionstatus'] = $status;
|
||||
|
||||
if ($this->get_instance()->teamsubmission) {
|
||||
|
||||
$groupsstr = '';
|
||||
if ($currentgroup != 0) {
|
||||
// If there is an active group we should only display the current group users groups.
|
||||
$participants = $this->list_participants($currentgroup, true);
|
||||
$groups = groups_get_all_groups($this->get_course()->id,
|
||||
array_keys($participants),
|
||||
$this->get_instance()->teamsubmissiongroupingid,
|
||||
'DISTINCT g.id, g.name');
|
||||
list($groupssql, $groupsparams) = $DB->get_in_or_equal(array_keys($groups), SQL_PARAMS_NAMED);
|
||||
$groupsstr = 's.groupid ' . $groupssql . ' AND';
|
||||
$params = $params + $groupsparams;
|
||||
}
|
||||
|
||||
$maxattemptsql = 'SELECT mxs.groupid, MAX(mxs.attemptnumber) AS maxattempt
|
||||
FROM {assign_submission} mxs
|
||||
WHERE mxs.assignment = :assignid2 GROUP BY mxs.groupid';
|
||||
@@ -1534,7 +1586,8 @@ class assign {
|
||||
s.attemptnumber = smx.maxattempt AND
|
||||
s.assignment = :assignid AND
|
||||
s.timemodified IS NOT NULL AND
|
||||
s.userid = :groupuserid AND
|
||||
s.userid = :groupuserid AND '
|
||||
. $groupsstr . '
|
||||
s.status = :submissionstatus';
|
||||
$params['groupuserid'] = 0;
|
||||
} else {
|
||||
@@ -1964,6 +2017,7 @@ class assign {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $members;
|
||||
}
|
||||
|
||||
@@ -2166,12 +2220,23 @@ class assign {
|
||||
* @return mixed The group or false
|
||||
*/
|
||||
public function get_submission_group($userid) {
|
||||
|
||||
if (isset($this->usersubmissiongroups[$userid])) {
|
||||
return $this->usersubmissiongroups[$userid];
|
||||
}
|
||||
|
||||
$grouping = $this->get_instance()->teamsubmissiongroupingid;
|
||||
$groups = groups_get_all_groups($this->get_course()->id, $userid, $grouping);
|
||||
if (count($groups) != 1) {
|
||||
return false;
|
||||
$return = false;
|
||||
} else {
|
||||
$return = array_pop($groups);
|
||||
}
|
||||
return array_pop($groups);
|
||||
|
||||
// Cache the user submission group.
|
||||
$this->usersubmissiongroups[$userid] = $return;
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
@@ -4048,8 +4113,10 @@ class assign {
|
||||
$currenturl = new moodle_url('/mod/assign/view.php', array('id' => $this->get_course_module()->id));
|
||||
$o .= groups_print_activity_menu($this->get_course_module(), $currenturl->out(), true);
|
||||
|
||||
$activitygroup = groups_get_activity_group($this->get_course_module());
|
||||
|
||||
if ($instance->teamsubmission) {
|
||||
$summary = new assign_grading_summary($this->count_teams(),
|
||||
$summary = new assign_grading_summary($this->count_teams($activitygroup),
|
||||
$instance->submissiondrafts,
|
||||
$this->count_submissions_with_status($draft),
|
||||
$this->is_any_submission_plugin_enabled(),
|
||||
@@ -4062,7 +4129,7 @@ class assign {
|
||||
$o .= $this->get_renderer()->render($summary);
|
||||
} else {
|
||||
// The active group has already been updated in groups_print_activity_menu().
|
||||
$countparticipants = $this->count_participants(groups_get_activity_group($this->get_course_module()));
|
||||
$countparticipants = $this->count_participants($activitygroup);
|
||||
$summary = new assign_grading_summary($countparticipants,
|
||||
$instance->submissiondrafts,
|
||||
$this->count_submissions_with_status($draft),
|
||||
|
||||
Reference in New Issue
Block a user