Merge branch 'MDL-40631-master' of git://github.com/damyon/moodle

This commit is contained in:
Dan Poltawski 2013-09-10 14:33:41 +08:00
commit 92d92606ba
2 changed files with 69 additions and 8 deletions

View File

@ -2723,11 +2723,13 @@ class assign {
if ($teamsubmission) {
$showsubmit = $showedit &&
$teamsubmission &&
($teamsubmission->status == ASSIGN_SUBMISSION_STATUS_DRAFT);
($teamsubmission->status != ASSIGN_SUBMISSION_STATUS_SUBMITTED) &&
!$this->submission_empty($teamsubmission);
} else {
$showsubmit = $showedit &&
$submission &&
($submission->status == ASSIGN_SUBMISSION_STATUS_DRAFT);
($submission->status != ASSIGN_SUBMISSION_STATUS_SUBMITTED) &&
!$this->submission_empty($submission);
}
if (!$this->get_instance()->submissiondrafts) {
$showsubmit = false;
@ -3548,10 +3550,16 @@ class assign {
}
$showsubmit = ($submission || $teamsubmission) && $showlinks;
if ($teamsubmission && ($teamsubmission->status != ASSIGN_SUBMISSION_STATUS_DRAFT)) {
if ($teamsubmission && ($teamsubmission->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED)) {
$showsubmit = false;
}
if ($submission && ($submission->status != ASSIGN_SUBMISSION_STATUS_DRAFT)) {
if ($teamsubmission && $this->submission_empty($teamsubmission)) {
$showsubmit = false;
}
if ($submission && ($submission->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED)) {
$showsubmit = false;
}
if ($submission && $this->submission_empty($submission)) {
$showsubmit = false;
}
if (!$this->get_instance()->submissiondrafts) {
@ -5094,6 +5102,25 @@ class assign {
return true;
}
/**
* Determine if the current submission is empty or not.
*
* @param submission $submission the students submission record to check.
* @return bool
*/
public function submission_empty($submission) {
$allempty = true;
foreach ($this->submissionplugins as $plugin) {
if ($plugin->is_enabled() && $plugin->is_visible()) {
if (!$allempty || !$plugin->is_empty($submission)) {
$allempty = false;
}
}
}
return $allempty;
}
/**
* Save assignment submission.
*
@ -5142,7 +5169,6 @@ class assign {
return true;
}
$allempty = true;
$pluginerror = false;
foreach ($this->submissionplugins as $plugin) {
if ($plugin->is_enabled() && $plugin->is_visible()) {
@ -5150,11 +5176,9 @@ class assign {
$notices[] = $plugin->get_error();
$pluginerror = true;
}
if (!$allempty || !$plugin->is_empty($submission)) {
$allempty = false;
}
}
}
$allempty = $this->submission_empty($submission);
if ($pluginerror || $allempty) {
if ($allempty) {
$notices[] = get_string('submissionempty', 'mod_assign');

View File

@ -292,6 +292,43 @@ class mod_assign_locallib_testcase extends mod_assign_base_testcase {
$this->assertEquals($now, $instance->duedate);
}
public function test_cannot_submit_empty() {
global $PAGE;
$this->setUser($this->editingteachers[0]);
$assign = $this->create_instance(array('submissiondrafts'=>1));
$PAGE->set_url(new moodle_url('/mod/assign/view.php', array('id' => $assign->get_course_module()->id)));
// Test you cannot see the submit button for an offline assignment regardless.
$this->setUser($this->students[0]);
$output = $assign->view_student_summary($this->students[0], true);
$this->assertNotContains(get_string('submitassignment', 'assign'), $output, 'Can submit empty offline assignment');
// Test you cannot see the submit button for an online text assignment with no submission.
$this->setUser($this->editingteachers[0]);
$instance = $assign->get_instance();
$instance->instance = $instance->id;
$instance->assignsubmission_onlinetext_enabled = 1;
$assign->update_instance($instance);
$this->setUser($this->students[0]);
$output = $assign->view_student_summary($this->students[0], true);
$this->assertNotContains(get_string('submitassignment', 'assign'), $output, 'Cannot submit empty onlinetext assignment');
// Simulate a submission.
$submission = $assign->get_user_submission($this->students[0]->id, true);
$data = new stdClass();
$data->onlinetext_editor = array('itemid'=>file_get_unused_draft_itemid(),
'text'=>'Submission text',
'format'=>FORMAT_MOODLE);
$plugin = $assign->get_submission_plugin_by_type('onlinetext');
$plugin->save($submission, $data);
// Test you can see the submit button for an online text assignment with a submission.
$output = $assign->view_student_summary($this->students[0], true);
$this->assertContains(get_string('submitassignment', 'assign'), $output, 'Can submit non empty onlinetext assignment');
}
public function test_list_participants() {
$this->create_extra_users();
$this->setUser($this->editingteachers[0]);