Permalink
Browse files

MDL-31284: Backported team assignment fixes from stable branch

  • Loading branch information...
1 parent 12a1a0d commit cd01491c11ec90c7da1967b568b131e0475768a1 Damyon Wiese committed Sep 3, 2012
Showing with 61 additions and 6 deletions.
  1. +52 −4 mod/assign/gradingtable.php
  2. +8 −1 mod/assign/locallib.php
  3. +1 −1 mod/assign/renderer.php
@@ -52,6 +52,11 @@ class assign_grading_table extends table_sql implements renderable {
private $quickgrading = false;
/** @var boolean $hasgrantextension - Only do the capability check once for the entire table */
private $hasgrantextension = false;
+ /** @var array $groupsubmissions - A static cache of group submissions */
+ private $groupsubmissions = array();
+ /** @var array $submissiongroups - A static cache of submission groups */
+ private $submissiongroups = array();
+
/**
* overridden constructor keeps a reference to the assignment class that is displaying this table
@@ -274,21 +279,56 @@ function display_grade($grade, $editable, $userid, $modified) {
* @return string The team name
*/
function col_team(stdClass $row) {
- $group = $this->assignment->get_submission_group($row->id);
+ $submission = false;
+ $group = false;
+ $this->get_group_and_submission($row->id, $group, $submission);
if ($group) {
return $group->name;
}
return get_string('defaultteam', 'assign');
}
/**
- * Get the team info for this user
+ * Use a static cache to try and reduce DB calls.
+ *
+ * @param int $userid The user id for this submission
+ * @param int $groupid The groupid (returned)
+ * @param mixed $submission The stdClass submission or false (returned)
+ */
+ function get_group_and_submission($userid, &$group, &$submission) {
+ $group = false;
+ if (isset($this->submissiongroups[$userid])) {
+ $group = $this->submissiongroups[$userid];
+ } else {
+ $group = $this->assignment->get_submission_group($userid, false);
+ $this->submissiongroups[$userid] = $group;
+ }
+
+ $groupid = 0;
+ if ($group) {
+ $groupid = $group->id;
+ }
+
+ if (isset($this->groupsubmissions[$groupid])) {
+ $submission = $this->groupsubmissions[$groupid];
+ } else {
+ $submission = $this->assignment->get_group_submission($userid, $groupid, false);
+ $this->groupsubmissions[$groupid] = $submission;
+ }
+ }
+
+
+ /**
+ * Get the team status for this user
*
* @param stdClass $row
* @return string The team name
*/
function col_teamstatus(stdClass $row) {
- $submission = $this->assignment->get_group_submission($row->id, 0, false);
+ $submission = false;
+ $group = false;
+ $this->get_group_and_submission($row->id, $group, $submission);
+
$status = '';
if ($submission) {
$status = $submission->status;
@@ -648,7 +688,15 @@ function other_cols($colname, $row){
$plugin = $this->assignment->get_submission_plugin_by_type(substr($colname, strlen('assignsubmission_')));
if ($plugin->is_visible() && $plugin->is_enabled()) {
- if ($row->submissionid) {
+ if ($this->assignment->get_instance()->teamsubmission) {
+ $group = false;
+ $submission = false;
+ $this->get_group_and_submission($row->id, $group, $submission);
+ if ($submission) {
+ return $this->format_plugin_summary_with_link($plugin, $submission, 'grading', array());
+ }
+ } else if ($row->submissionid) {
+
$submission = new stdClass();
$submission->id = $row->submissionid;
$submission->timecreated = $row->firstsubmission;
View
@@ -2702,7 +2702,14 @@ private function submissions_open($userid = 0) {
if (!is_enrolled($this->get_course_context(), $userid)) {
return false;
}
- if ($submission = $this->get_user_submission($userid, false)) {
+ $submission = false;
+ if ($this->get_instance()->teamsubmission) {
+ $submission = $this->get_group_submission($USER->id, 0, false);
+ } else {
+ $submission = $this->get_user_submission($USER->id, false);
+ }
+ if ($submission) {
+
if ($this->get_instance()->submissiondrafts && $submission->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
// drafts are tracked and the student has submitted the assignment
return false;
View
@@ -573,7 +573,7 @@ public function render_assign_submission_status(assign_submission_status $status
// Links.
if ($status->view == assign_submission_status::STUDENT_VIEW) {
if ($status->canedit) {
- if (!$status->submission) {
+ if (!$submission) {
$urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission');
$o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
get_string('addsubmission', 'assign'), 'get');

0 comments on commit cd01491

Please sign in to comment.