From 5c02b884f590d9793a108a720d4e60aede901021 Mon Sep 17 00:00:00 2001 From: Matt Davidson Date: Tue, 16 Jan 2024 11:41:14 -0500 Subject: [PATCH] review commit 1 --- classes/actions.php | 2 +- classes/event/course_modules_duplicated.php | 23 +++++++++++++++---- .../course_modules_duplicated_failed.php | 8 ++++--- classes/massactionutils.php | 2 +- lang/en/block_massaction.php | 6 +++++ 5 files changed, 31 insertions(+), 10 deletions(-) diff --git a/classes/actions.php b/classes/actions.php index fb24add..e737e3b 100644 --- a/classes/actions.php +++ b/classes/actions.php @@ -507,7 +507,7 @@ public static function show_description(array $modules, bool $showdescription): \course_modinfo::purge_course_module_cache($cm->course, $cm->id); } } else { - throw new moodle_exception('Could not find course module with id ' . $cm->id); + throw new moodle_exception('invalidmoduleid', 'block_massaction', $cm->id); } } } diff --git a/classes/event/course_modules_duplicated.php b/classes/event/course_modules_duplicated.php index c8ac260..2ae0a54 100644 --- a/classes/event/course_modules_duplicated.php +++ b/classes/event/course_modules_duplicated.php @@ -55,15 +55,28 @@ public function get_description(): string { $cms = []; $failed = []; foreach ($this->other['cms'] as $srccm => $dstcm) { - $cms[] = 'cmid from \'' . $srccm . '\' to \'' . $dstcm . '\''; + $cms[] = get_string('event:duplicated_description', + 'block_massaction', + ['src' => $srccm, + 'dst' => $dstcm, + ]); } + foreach ($this->other['failed'] as $cmid) { $failed[] = 'cmid \'' . $cmid . '\''; } - return 'Course modules duplicate has been completed. ' - . 'Summary: ' . count($cms) . ' Completed, ' . count($failed) . ' Failed.' - . ($cms ? ' Completed ' . implode(", ", $cms) . '.' : '') - . ($failed ? ' Failed ' . implode(", ", $failed) . '.' : ''); + + return get_string('event:duplicated_summary', + 'block_massaction', + ['countcomplete' => count($cms), + 'countfailed' => count($failed), + ]) . + ($cms ? get_string('event:duplicated_completed_list', + 'block_massaction', + ['list' => implode(', ', $cms)]) : '') . + ($failed ? get_string('event:duplicated_failed_list', + 'block_massaction', + ['list' => implode(', ', $failed)]) : ''); } /** diff --git a/classes/event/course_modules_duplicated_failed.php b/classes/event/course_modules_duplicated_failed.php index a874071..4b8a30c 100644 --- a/classes/event/course_modules_duplicated_failed.php +++ b/classes/event/course_modules_duplicated_failed.php @@ -52,9 +52,11 @@ public static function get_name(): string { * @return string */ public function get_description(): string { - return 'Course modules duplicate failed. ' - . 'cmid: ' . $this->other['cmid'] - . 'error:' . $this->other['error']; + return get_string('event:duplicated_failed_description', + 'block_massaction', + ['cmid' => $this->other['cmid'], + 'error' => $this->other['error'], + ]); } /** diff --git a/classes/massactionutils.php b/classes/massactionutils.php index e1cb0ed..a5816fa 100644 --- a/classes/massactionutils.php +++ b/classes/massactionutils.php @@ -160,7 +160,7 @@ public static function duplicate_cm_to_course(object $course, object $cm): int { } } if (empty($newcmid)) { - throw new \moodle_exception('Could not duplicate course module from id ' . $cm->id); + throw new \moodle_exception('duplicatefailed', 'block_massaction', $cm->id); } return $newcmid; } diff --git a/lang/en/block_massaction.php b/lang/en/block_massaction.php index 4abb3ba..578dd35 100644 --- a/lang/en/block_massaction.php +++ b/lang/en/block_massaction.php @@ -72,11 +72,17 @@ $string['confirmsectionselect'] = 'Choose section'; $string['deletecheck'] = 'Confirm mass deletion'; $string['deletecheckconfirm'] = 'Are you sure you want to delete the following module(s)?'; +$string['duplicatefailed'] = 'Could not duplicate course module from id {$a}'; $string['duplicatemaxactivities'] = 'Maximum amount of course modules to duplicate'; $string['duplicatemaxactivities_description'] = 'Maximum amount of course modules which can be duplicated at the same time without running the process as background task. If set to "0" all duplication operations will be run as background task.'; $string['enablebulkediting'] = 'Enable bulk editing'; $string['event:course_modules_duplicated'] = 'Course modules duplicated'; $string['event:course_modules_duplicated_failed'] = 'Course modules failed to duplicate'; +$string['event:duplicated_description'] = 'cmid from \'{$a->src}\' to \'{$a->dst}\''; +$string['event:duplicated_summary'] = 'Course module duplication has been completed. Summary: {$a->countcomplete} Completed, {$a->countfailed} Failed.'; +$string['event:duplicated_completed_list'] = 'Completed {$a->list}.'; +$string['event:duplicated_failed_list'] = 'Failed {$a->list}.'; +$string['event:duplicated_failed_description'] = 'Course module duplication failed. cmid: {$a->cmid} error: {$a->error}'; $string['invalidaction'] = 'Unknown action: {$a}'; $string['invalidmoduleid'] = 'Invalid module ID: {$a}'; $string['invalidcoursemodule'] = 'Invalid course module';