From 937dd204d1cc99776e5d7c88aa3df4c90943889f Mon Sep 17 00:00:00 2001 From: Sara Arjona Date: Tue, 22 Jul 2025 11:22:59 +0200 Subject: [PATCH] MDL-85842 workshop: Apply last changes in the overview page - Change 'Deadline' column name to 'Phase deadline'. - Submissions and Assessments columns should always be text only (remove the links). - Add Actions column with a 'View' link to Workshop tab (current phase selected). --- .../classes/courseformat/overview.php | 62 ++++++++------- public/mod/workshop/lang/en/workshop.php | 2 +- .../tests/behat/overview_report.feature | 72 +++++++----------- .../tests/courseformat/overview_test.php | 75 +++++++++++++++++-- 4 files changed, 131 insertions(+), 80 deletions(-) diff --git a/public/mod/workshop/classes/courseformat/overview.php b/public/mod/workshop/classes/courseformat/overview.php index 6e3c30be4aa..6f7a674af90 100644 --- a/public/mod/workshop/classes/courseformat/overview.php +++ b/public/mod/workshop/classes/courseformat/overview.php @@ -91,6 +91,42 @@ class overview extends \core_courseformat\activityoverviewbase { ]; } + #[\Override] + public function get_actions_overview(): ?overviewitem { + + if ( + !has_capability('mod/workshop:viewallsubmissions', $this->cm->context) + && !has_capability('mod/workshop:viewallassessments', $this->cm->context) + ) { + // Students do not have any actions. + return null; + } + + $anchor = null; + if ($this->workshop->phase == workshop::PHASE_SUBMISSION) { + $anchor = 'workshop-viewlet-allsubmissions'; + } else if ($this->workshop->phase == workshop::PHASE_ASSESSMENT) { + $anchor = 'workshop-viewlet-gradereport'; + } + + $content = new action_link( + url: new url( + '/mod/workshop/view.php', + ['id' => $this->cm->id], + $anchor, + ), + text: get_string('view', 'core'), + attributes: ['class' => button::BODY_OUTLINE->classes()], + ); + + return new overviewitem( + name: get_string('actions', 'core'), + value: get_string('view', 'core'), + content: $content, + textalign: text_align::CENTER, + ); + } + /** * Get the current phase overview item. * @@ -163,19 +199,6 @@ class overview extends \core_courseformat\activityoverviewbase { ['count' => $submissions, 'total' => $total] ); - // If the current phase is submission, we can add a direct link. - if ($this->workshop->phase == workshop::PHASE_SUBMISSION) { - $content = new action_link( - url: new url( - '/mod/workshop/view.php', - ['id' => $this->cm->id], - 'workshop-viewlet-allsubmissions', - ), - text: $content, - attributes: ['class' => button::BODY_OUTLINE->classes()], - ); - } - return new overviewitem( name: get_string('submissions', 'workshop'), value: $submissions, @@ -214,19 +237,6 @@ class overview extends \core_courseformat\activityoverviewbase { ['count' => $assessments, 'total' => $total] ); - // If the current phase is assessment, we can add a direct link. - if ($this->workshop->phase == workshop::PHASE_ASSESSMENT) { - $content = new action_link( - url: new url( - '/mod/workshop/view.php', - ['id' => $this->cm->id], - 'workshop-viewlet-gradereport', - ), - text: $content, - attributes: ['class' => button::BODY_OUTLINE->classes()], - ); - } - return new overviewitem( name: get_string('assessments', 'workshop'), value: $assessments, diff --git a/public/mod/workshop/lang/en/workshop.php b/public/mod/workshop/lang/en/workshop.php index b8ffbe90f78..4338d45a9d2 100644 --- a/public/mod/workshop/lang/en/workshop.php +++ b/public/mod/workshop/lang/en/workshop.php @@ -108,7 +108,7 @@ $string['daysleft'] = '{$a} days left'; $string['daystoday'] = 'today'; $string['daystomorrow'] = 'tomorrow'; $string['daysyesterday'] = 'yesterday'; -$string['deadline'] = 'Deadline'; +$string['deadline'] = 'Phase deadline'; $string['deadlinesignored'] = 'Time restrictions do not apply to you'; $string['deletesubmission'] = 'Delete submission'; $string['editassessmentform'] = 'Edit assessment form'; diff --git a/public/mod/workshop/tests/behat/overview_report.feature b/public/mod/workshop/tests/behat/overview_report.feature index d1a107f7d3e..3d5feb79b8e 100644 --- a/public/mod/workshop/tests/behat/overview_report.feature +++ b/public/mod/workshop/tests/behat/overview_report.feature @@ -56,7 +56,7 @@ In order to summarize the workshops | Overridden | 1 | | Final grade | 10 | And I press "Save changes" - And I click on "Activity 2 (assessment)" "core_grades > grade_actions" in the "Student 1" "table_row" + And I click on "Activity 1 (assessment)" "core_grades > grade_actions" in the "Student 1" "table_row" And I choose "Edit grade" in the open action menu And I set the following fields to these values: | Overridden | 1 | @@ -66,24 +66,11 @@ In order to summarize the workshops And I am on the "Activity 1" "workshop activity" page And I change phase in workshop "Activity 1" to "Submission phase" When I am on the "Course 1" "course > activities > workshop" page logged in as "student1" - # Check columns. - Then I should see "Name" in the "workshop_overview_collapsible" "region" - And I should see "Phase" in the "workshop_overview_collapsible" "region" - And I should see "Deadline" in the "workshop_overview_collapsible" "region" - And I should see "Assessment grade" in the "workshop_overview_collapsible" "region" - And I should see "Submission grade" in the "workshop_overview_collapsible" "region" - # Check phase. - And I should see "Submission phase" in the "Activity 1" "table_row" - And I should see "Setup phase" in the "Activity 2" "table_row" - # Cheack Deadline. - And I should see "1 January 2040" in the "Activity 1" "table_row" - And I should see "-" in the "Activity 2" "table_row" - # Check Grades. - And I should see "10.00" in the "Activity 1" "table_row" - And I should see "-" in the "Activity 1" "table_row" - And I should see "-" in the "Activity 2" "table_row" - # The worksup assessment grade is normalized to 5.00. - And I should see "5.00" in the "Activity 2" "table_row" + Then the following should exist in the "Table listing all Workshop activities" table: + | Name | Phase | Phase deadline | Submission grade | Assessment grade | + | Activity 1 | Submission phase | 1 January 2040 | 10.00 | 5.00 | + | Activity 2 | Setup phase | - | - | - | + And I should not see "Actions" in the "workshop_overview_collapsible" "region" Scenario: Teachers can see relevant columns in the workshop overview Given I log in as "teacher1" @@ -134,33 +121,24 @@ In order to summarize the workshops And I press "Re-calculate grades" # Now, the test itself. When I am on the "Course 1" "course > activities > workshop" page logged in as "teacher1" - # Check columns. - Then I should see "Name" in the "workshop_overview_collapsible" "region" - And I should see "Phase" in the "workshop_overview_collapsible" "region" - And I should see "Deadline" in the "workshop_overview_collapsible" "region" - And I should see "Submissions" in the "workshop_overview_collapsible" "region" - And I should see "Assessments" in the "workshop_overview_collapsible" "region" - # Check phase. - And I should see "Grading evaluation phase" in the "Activity 1" "table_row" - And I should see "Submission phase" in the "Activity 2" "table_row" - # Cheack Deadline. - And I should see "-" in the "Activity 1" "table_row" - And I should see "Tomorrow" in the "Activity 2" "table_row" - # Check Submissions. - And I should see "1 of 8" in the "Activity 1" "table_row" - And I should see "0 of 8" in the "Activity 2" "table_row" - # Check Assessments. - And I should see "3 of 3" in the "Activity 1" "table_row" - And I should see "-" in the "Activity 2" "table_row" + Then the following should exist in the "Table listing all Workshop activities" table: + | Name | Phase | Phase deadline | Submissions | Assessments | Actions | + | Activity 1 | Grading evaluation phase | - | 1 of 8 | 3 of 3 | View | + | Activity 2 | Submission phase | Tomorrow | 0 of 8 | - | View | + # Check the View link. + And I click on "View" "link" in the "Activity 1" "table_row" + And I should see "Workshop grades report" + And I am on the "Course 1" "course > activities > workshop" page + And I click on "View" "link" in the "Activity 2" "table_row" + And I should see "Workshop submissions report" - @javascript Scenario: The workshop index redirect to the activities overview - When I log in as "admin" - And I am on "Course 1" course homepage with editing mode on - And I add the "Activities" block - And I click on "Workshops" "link" in the "Activities" "block" - Then I should see "An overview of all activities in the course" - And I should see "Name" in the "workshop_overview_collapsible" "region" - And I should see "Phase" in the "workshop_overview_collapsible" "region" - And I should see "Submissions" in the "workshop_overview_collapsible" "region" - And I should see "Assessments" in the "workshop_overview_collapsible" "region" + Given the following "activity" exists: + | activity | workshop | + | course | Acceptance test site | + | name | Home workshop | + And I log in as "admin" + When I visit "/mod/workshop/index.php?id=1" + Then the following should exist in the "Table listing all Workshop activities" table: + | Name | Phase | Submissions | Assessments | Actions | + | Home workshop | Setup phase | - | - | View | diff --git a/public/mod/workshop/tests/courseformat/overview_test.php b/public/mod/workshop/tests/courseformat/overview_test.php index a6f74a4ea28..48ab4a82161 100644 --- a/public/mod/workshop/tests/courseformat/overview_test.php +++ b/public/mod/workshop/tests/courseformat/overview_test.php @@ -16,6 +16,11 @@ namespace mod_workshop\courseformat; +defined('MOODLE_INTERNAL') || die(); + +global $CFG; +require_once($CFG->dirroot . '/mod/workshop/locallib.php'); + use core_courseformat\local\overview\overviewfactory; /** @@ -28,12 +33,6 @@ use core_courseformat\local\overview\overviewfactory; * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ final class overview_test extends \advanced_testcase { - #[\Override] - public static function setUpBeforeClass(): void { - global $CFG; - require_once($CFG->dirroot . '/mod/workshop/locallib.php'); - parent::setUpBeforeClass(); - } /** * Test get_grade_item_names method. @@ -633,4 +632,68 @@ final class overview_test extends \advanced_testcase { ], ]; } + + /** + * Test get_actions_overview. + * + * @covers ::get_actions_overview + * @dataProvider provider_test_get_actions_overview + * + * @param string $role + * @param array|null $expected + */ + public function test_get_actions_overview( + string $role, + ?array $expected + ): void { + $this->resetAfterTest(); + $this->setAdminUser(); + + $course = $this->getDataGenerator()->create_course(); + $currentuser = $this->getDataGenerator()->create_and_enrol($course, $role); + $activity = $this->getDataGenerator()->create_module('workshop', ['course' => $course->id]); + + $this->setUser($currentuser); + + $cm = get_fast_modinfo($course)->get_cm($activity->cmid); + $item = overviewfactory::create($cm)->get_actions_overview(); + + if ($expected === null) { + $this->assertNull($item); + return; + } + + $this->assertEquals( + $expected, + ['name' => $item->get_name(), 'value' => $item->get_value()] + ); + } + + /** + * Data provider for test_get_actions_overview. + * + * @return array + */ + public static function provider_test_get_actions_overview(): array { + return [ + 'Student' => [ + 'role' => 'student', + 'expected' => null, + ], + 'Editing teacher' => [ + 'role' => 'editingteacher', + 'expected' => [ + 'name' => get_string('actions'), + 'value' => get_string('view'), + ], + ], + 'Teacher' => [ + 'role' => 'teacher', + 'expected' => [ + 'name' => get_string('actions'), + 'value' => get_string('view'), + ], + ], + ]; + } }