Permalink
Browse files

Merge branch 'MDL-36263-23' of git://github.com/damyon/moodle into MO…

…ODLE_23_STABLE
  • Loading branch information...
2 parents f1cf05c + 40c1230 commit 3c805e592c1567a77cbcca7abe449736db6a5f1a Sam Hemelryk committed Dec 10, 2012
View
@@ -1056,22 +1056,32 @@ public function count_participants($currentgroup) {
/**
* Load a count of users submissions in the current module that require grading
* This means the submission modification time is more recent than the
- * grading modification time.
+ * grading modification time and the status is SUBMITTED.
*
* @return int number of matching submissions
*/
public function count_submissions_need_grading() {
global $DB;
- $params = array($this->get_course_module()->instance);
+ $currentgroup = groups_get_activity_group($this->get_course_module(), true);
+ list($esql, $params) = get_enrolled_sql($this->get_context(), 'mod/assign:submit', $currentgroup, false);
+
+ $params['assignid'] = $this->get_instance()->id;
+ $params['submitted'] = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
- return $DB->count_records_sql("SELECT COUNT('x')
- FROM {assign_submission} s
- LEFT JOIN {assign_grades} g ON s.assignment = g.assignment AND s.userid = g.userid
- WHERE s.assignment = ?
- AND s.timemodified IS NOT NULL
- AND (s.timemodified > g.timemodified OR g.timemodified IS NULL)",
- $params);
+ $sql = 'SELECT COUNT(s.userid)
+ FROM {assign_submission} s
+ LEFT JOIN {assign_grades} g ON
+ s.assignment = g.assignment AND
+ s.userid = g.userid
+ JOIN(' . $esql . ') AS e ON e.id = s.userid
+ WHERE
+ s.assignment = :assignid AND
+ s.timemodified IS NOT NULL AND
+ s.status = :submitted AND
+ (s.timemodified > g.timemodified OR g.timemodified IS NULL)';
+
+ return $DB->count_records_sql($sql, $params);
}
/**
@@ -1082,10 +1092,26 @@ public function count_submissions_need_grading() {
*/
public function count_submissions_with_status($status) {
global $DB;
- return $DB->count_records_sql("SELECT COUNT('x')
- FROM {assign_submission}
- WHERE assignment = ? AND
- status = ?", array($this->get_course_module()->instance, $status));
+
+ $currentgroup = groups_get_activity_group($this->get_course_module(), true);
+ list($esql, $params) = get_enrolled_sql($this->get_context(), 'mod/assign:submit', $currentgroup, false);
+
+ $params['assignid'] = $this->get_instance()->id;
+ $params['submissionstatus'] = $status;
+
+ $sql = 'SELECT COUNT(s.userid)
+ FROM {assign_submission} s
+ LEFT JOIN {assign_grades} g ON
+ s.assignment = g.assignment AND
+ s.userid = g.userid
+ JOIN(' . $esql . ') AS e ON e.id = s.userid
+ WHERE
+ s.assignment = :assignid AND
+ s.timemodified IS NOT NULL AND
+ s.status = :submissionstatus AND
+ (s.timemodified > g.timemodified OR g.timemodified IS NULL)';
+
+ return $DB->count_records_sql($sql, $params);
}
/**
@@ -1138,22 +1164,32 @@ private function get_userid_for_row($num, $last){
* @return array The submission objects indexed by id
*/
private function get_all_submissions( $sort="", $dir="DESC") {
- global $CFG, $DB;
+ global $DB;
+
+ $currentgroup = groups_get_activity_group($this->get_course_module(), true);
+ list($esql, $params) = get_enrolled_sql($this->get_context(), 'mod/assign:submit', $currentgroup, false);
+
+ $params['assignid'] = $this->get_instance()->id;
+
+ $sql = 'SELECT s.*, u.lastname, u.firstname, u.username
+ FROM {assign_submission} s
+ JOIN {user} u ON s.userid = u.id
+ JOIN(' . $esql . ') AS e ON e.id = s.userid
+ WHERE
+ s.assignment = :assignid AND
+ s.timemodified IS NOT NULL';
if ($sort == "lastname" or $sort == "firstname") {
$sort = "u.$sort $dir";
} else if (empty($sort)) {
- $sort = "a.timemodified DESC";
+ $sort = "s.timemodified DESC";
} else {
- $sort = "a.$sort $dir";
+ $sort = "s.$sort $dir";
}
- return $DB->get_records_sql("SELECT a.*
- FROM {assign_submission} a, {user} u
- WHERE u.id = a.userid
- AND a.assignment = ?
- ORDER BY $sort", array($this->get_instance()->id));
+ $sql .= ' ORDER BY ' . $sort;
+ return $DB->get_records_sql($sql, $params);
}
/**
@@ -1542,9 +1578,7 @@ private function download_submissions() {
if ((groups_is_member($groupid,$userid) or !$groupmode or !$groupid)) {
// get the plugins to add their own files to the zip
- $user = $DB->get_record("user", array("id"=>$userid),'id,username,firstname,lastname', MUST_EXIST);
-
- $prefix = clean_filename(fullname($user) . "_" .$userid . "_");
+ $prefix = clean_filename(fullname($submission) . "_" .$userid . "_");
foreach ($this->submissionplugins as $plugin) {
if ($plugin->is_enabled() && $plugin->is_visible()) {
@@ -1609,12 +1643,7 @@ private function get_user_submission($userid, $create) {
$submission->userid = $userid;
$submission->timecreated = time();
$submission->timemodified = $submission->timecreated;
-
- if ($this->get_instance()->submissiondrafts) {
- $submission->status = ASSIGN_SUBMISSION_STATUS_DRAFT;
- } else {
- $submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
- }
+ $submission->status = ASSIGN_SUBMISSION_STATUS_DRAFT;
$sid = $DB->insert_record('assign_submission', $submission);
$submission->id = $sid;
return $submission;
@@ -2102,6 +2131,9 @@ public function view_student_summary($user, $showlinks) {
$showedit = has_capability('mod/assign:submit', $this->context) &&
$this->submissions_open() && ($this->is_any_submission_plugin_enabled()) && $showlinks;
$showsubmit = $submission && ($submission->status == ASSIGN_SUBMISSION_STATUS_DRAFT) && $showlinks;
+ if (!$this->get_instance()->submissiondrafts) {
+ $showsubmit = false;
+ }
$gradelocked = ($grade && $grade->locked) || $this->grading_disabled($user->id);
$o .= $this->output->render(new assign_submission_status($this->get_instance()->allowsubmissionsfromdate,
@@ -2852,13 +2884,18 @@ private function process_save_submission(&$mform, &$notices) {
}
if ($data = $mform->get_data()) {
$submission = $this->get_user_submission($USER->id, true); //create the submission if needed & its id
+ if ($this->get_instance()->submissiondrafts) {
+ $submission->status = ASSIGN_SUBMISSION_STATUS_DRAFT;
+ } else {
+ $submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
+ }
+
$grade = $this->get_user_grade($USER->id, false); // get the grade to check if it is locked
if ($grade && $grade->locked) {
print_error('submissionslocked', 'assign');
return true;
}
-
$allempty = true;
$pluginerror = false;
foreach ($this->submissionplugins as $plugin) {
View
@@ -452,7 +452,11 @@ public function render_assign_submission_status(assign_submission_status $status
$t->data[] = $row;
foreach ($status->submissionplugins as $plugin) {
- if ($plugin->is_enabled() && $plugin->is_visible() && !$plugin->is_empty($status->submission)) {
+ $pluginshowsummary = !$plugin->is_empty($status->submission) || !$plugin->allow_submissions();
+ if ($plugin->is_enabled() &&
+ $plugin->is_visible() &&
+ $pluginshowsummary) {
+
$row = new html_table_row();
$cell1 = new html_table_cell($plugin->get_name());
$pluginsubmission = new assign_submission_plugin_submission($plugin, $status->submission, assign_submission_plugin_submission::SUMMARY, $status->coursemoduleid, $status->returnaction, $status->returnparams);
@@ -78,12 +78,13 @@ public function view_summary(stdClass $submission, & $showviewlink) {
}
/**
- * Always return false because at a minimum there is the comments control
+ * Always return true because the submission comments are not part of the submission form.
+ *
* @param stdClass $submission
* @return bool
*/
public function is_empty(stdClass $submission) {
- return false;
+ return true;
}
/**
@@ -376,7 +376,9 @@ public function delete_instance() {
* @return bool
*/
public function is_empty(stdClass $submission) {
- return $this->view($submission) == '';
+ $onlinetextsubmission = $this->get_onlinetext_submission($submission->id);
+
+ return empty($onlinetextsubmission->onlinetext);
}
/**

0 comments on commit 3c805e5

Please sign in to comment.