From d846cb244dae6c46cf82dc54dd29f08bce95c27d Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Wed, 22 Mar 2017 09:34:01 +0800 Subject: [PATCH] MDL-58337 mod_assign: Do not show submitted assignments in dashboard Part of MDL-55611 epic. --- mod/assign/lib.php | 8 +++++++ mod/assign/tests/lib_test.php | 40 +++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/mod/assign/lib.php b/mod/assign/lib.php index c789465e031..79023204124 100644 --- a/mod/assign/lib.php +++ b/mod/assign/lib.php @@ -1756,6 +1756,14 @@ function mod_assign_core_calendar_provide_event_action(\core_calendar\event $eve $itemcount = $assign->count_submissions_need_grading(); $actionable = $assign->can_grade() && (time() >= $assign->get_instance()->allowsubmissionsfromdate); } else { + $usersubmission = $assign->get_user_submission($USER->id, false); + if ($usersubmission && $usersubmission->status === ASSIGN_SUBMISSION_STATUS_SUBMITTED) { + // The user has already submitted. + // We do not want to change the text to edit the submission, we want to remove the event from the Dashboard entirely. + return null; + } + + // The user has not yet submitted anything. Show the addsubmission link. $name = get_string('addsubmission', 'assign'); $url = new \moodle_url('/mod/assign/view.php', [ 'id' => $cm->id, diff --git a/mod/assign/tests/lib_test.php b/mod/assign/tests/lib_test.php index 0724da33586..2a568af4907 100644 --- a/mod/assign/tests/lib_test.php +++ b/mod/assign/tests/lib_test.php @@ -548,6 +548,46 @@ class mod_assign_lib_testcase extends mod_assign_base_testcase { $this->assertFalse($actionevent->is_actionable()); } + public function test_assign_core_calendar_provide_event_action_duedate_as_student_submitted() { + $this->setAdminUser(); + + // Create an assignment. + $assign = $this->create_instance(array('assignsubmission_onlinetext_enabled' => 1)); + + // Create a calendar event. + $event = $this->create_action_event($assign->get_instance()->id, ASSIGN_EVENT_TYPE_DUE); + + // Create an action factory. + $factory = new \core_calendar\action_factory(); + + // Set the user to a student. + $this->setUser($this->students[0]); + + // Submit the assignment. + $submission = $assign->get_user_submission($this->students[0]->id, true); + $submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED; + $assign->testable_update_submission($submission, $this->students[0]->id, true, false); + $data = (object) [ + 'userid' => $this->students[0]->id, + 'onlinetext_editor' => [ + 'itemid' => file_get_unused_draft_itemid(), + 'text' => 'Submission text', + 'format' => FORMAT_MOODLE, + ], + ]; + $plugin = $assign->get_submission_plugin_by_type('onlinetext'); + $plugin->save($submission, $data); + + // Create an action factory. + $factory = new \core_calendar\action_factory(); + + // Decorate action event. + $actionevent = mod_assign_core_calendar_provide_event_action($event, $factory); + + // Confirm there was no event to action. + $this->assertNull($actionevent); + } + /** * Creates an action event. *