From 8247c84fd8653c0370463ee69997cf61276cb71a Mon Sep 17 00:00:00 2001 From: Matt Davidson Date: Wed, 26 Feb 2025 13:54:55 -0500 Subject: [PATCH 1/4] Allow bulk download of archives Additionally: Only show buttons when items are available and selected --- classes/processor.php | 67 +++++++++++++------------ lang/en/tool_coursearchiver.php | 4 +- templates/archive_view.mustache | 87 ++++++++++++++++++++++----------- 3 files changed, 99 insertions(+), 59 deletions(-) diff --git a/classes/processor.php b/classes/processor.php index f391662..b230ef5 100644 --- a/classes/processor.php +++ b/classes/processor.php @@ -1435,16 +1435,16 @@ public static function select_deselect_javascript() { require(["jquery"], function($) { $(".coursearchiver_selectall #id_toggle").click(function() { var text = $(this).val().length > 0 ? $(this).val() : $(this).text().trim(); - if("'.get_string('selectall', 'tool_coursearchiver').'" === text) { - $("input:checkbox").prop("checked", true); + if ("'.get_string('selectall', 'tool_coursearchiver').'" === text) { + $(".coursearchiveselection").prop("checked", true); $(".coursearchiver_selectall #id_toggle").val("'.get_string('deselectall', 'tool_coursearchiver').'"); $(".coursearchiver_selectall #id_toggle").text("'.get_string('deselectall', 'tool_coursearchiver').'"); - } - else if("'.get_string('deselectall', 'tool_coursearchiver').'" === text) { - $("input:checkbox").prop("checked", false); + } else if ("'.get_string('deselectall', 'tool_coursearchiver').'" === text) { + $(".coursearchiveselection").prop("checked", false); $(".coursearchiver_selectall #id_toggle").val("'.get_string('selectall', 'tool_coursearchiver').'"); $(".coursearchiver_selectall #id_toggle").text("'.get_string('selectall', 'tool_coursearchiver').'"); } + let visible = $(".coursearchiveselection:checked").length ? $(".coursearchivermultibuttons").show() : $(".coursearchivermultibuttons").hide(); }); }); '); @@ -1607,16 +1607,6 @@ public static function get_archivelist($search, $recover = false) { '', $config->coursearchiverpath), "/\\"); - // Form start. - $rowcolor = "#FFF"; - $data = ["formstart" => true, - "isadmin" => $isadmin, - "recover" => $recover, - "searchterm" => $search, - "rowcolor" => $rowcolor, - "limiter" => $config->archivelimit, - ]; - $courses = $OUTPUT->render_from_template('tool_coursearchiver/archive_view', $data); // Get either archives that are not marked for deletion or those that have been. $select = !$recover ? 'timetodelete = 0' : 'timetodelete > 0'; @@ -1634,6 +1624,20 @@ public static function get_archivelist($search, $recover = false) { '*', 0, $config->archivelimit); + + // Form start. + $rowcolor = "#FFF"; + $data = [ + "formstart" => true, + "results" => ($archives), + "isadmin" => $isadmin, + "recover" => $recover, + "searchterm" => $search, + "rowcolor" => $rowcolor, + "limiter" => $config->archivelimit, + ]; + $courses = $OUTPUT->render_from_template('tool_coursearchiver/archive_view', $data); + if ($archives) { foreach ($archives as $archive) { $pathinfo = pathinfo($archive->filename); @@ -1656,30 +1660,33 @@ public static function get_archivelist($search, $recover = false) { $rowcolor = $rowcolor == "#FFF" ? "#EEE" : "#FFF"; // Form content. - $data = ["formcontent" => true, - "isadmin" => $isadmin, - "recover" => $recover, - "rowcolor" => $rowcolor, - "file" => $file, - "path" => $path, - "downloadurl" => $downloadurl, - "restoreurl" => $restoreurl, - ]; + $data = [ + "formcontent" => true, + "results" => ($archives), + "isadmin" => $isadmin, + "recover" => $recover, + "rowcolor" => $rowcolor, + "file" => $file, + "path" => $path, + "downloadurl" => $downloadurl, + "restoreurl" => $restoreurl, + ]; $courses .= $OUTPUT->render_from_template('tool_coursearchiver/archive_view', $data); } } else { $rowcolor = $rowcolor == "#FFF" ? "#EEE" : "#FFF"; // Form content. - $data = ["nocontent" => true, - "isadmin" => $isadmin, - "recover" => $recover, - "rowcolor" => $rowcolor, - ]; + $data = [ + "nocontent" => true, + "isadmin" => $isadmin, + "recover" => $recover, + "rowcolor" => $rowcolor, + ]; $courses .= $OUTPUT->render_from_template('tool_coursearchiver/archive_view', $data); } // Form end. - $data = ["formend" => true, "recover" => $recover, "isadmin" => $isadmin]; + $data = ["formend" => true, "recover" => $recover, "isadmin" => $isadmin, "results" => ($archives)]; $courses .= $OUTPUT->render_from_template('tool_coursearchiver/archive_view', $data); return $courses; diff --git a/lang/en/tool_coursearchiver.php b/lang/en/tool_coursearchiver.php index 3c4e0fe..cf3ed14 100644 --- a/lang/en/tool_coursearchiver.php +++ b/lang/en/tool_coursearchiver.php @@ -61,7 +61,8 @@ $string['cli_question_hide'] = 'Hide these {$a} courses?'; $string['cli_question_hideemail'] = 'Send these {$a} users a "Course to be hidden" email?'; $string['confirm'] = 'Continue'; -$string['confirmdelete'] = 'Are you sure you want to delete?'; +$string['confirmdelete'] = 'Are you sure you want to delete these archived files?'; +$string['confirmdownload'] = 'Are you sure you want to download these archived files?'; $string['confirmmessage'] = 'Are you sure you want to {$a}'; $string['confirmmessagearchive'] = 'archive and remove these {$a} courses?'; $string['confirmmessagearchiveemail'] = 'send an email notification of pending course archival to these {$a} course owners?'; @@ -118,6 +119,7 @@ '; $string['deletewarningsubject'] = 'Notice: Courses will be deleted soon.'; $string['deselectall'] = 'Deselect All'; +$string['downloadselected'] = 'Download Selected'; $string['email'] = 'Send Email'; $string['emailselector'] = 'Users selected to receive emails.'; $string['empty'] = 'empty'; diff --git a/templates/archive_view.mustache b/templates/archive_view.mustache index 4784703..3a17a1c 100644 --- a/templates/archive_view.mustache +++ b/templates/archive_view.mustache @@ -76,11 +76,13 @@ {{/limiter}} {{#isadmin}} -
- -
+ {{#results}} +
+ +
+ {{/results}}
{{/isadmin}} @@ -103,7 +105,28 @@
{{#isadmin}} - + {{/isadmin}} @@ -113,7 +136,7 @@ {{path}} - + {{# str }} download, moodle {{/ str }} {{#isadmin}} @@ -136,25 +159,33 @@ {{#formend}}
- {{#isadmin}} - {{#recover}} - - {{/recover}} - {{^recover}} - - {{/recover}} - -
-
- -
- {{/isadmin}} + {{#results}} + {{#isadmin}} + {{#recover}} + + {{/recover}} + {{^recover}} + + + {{/recover}} + + +
+ +
+ {{/isadmin}} + {{/results}} {{/formend}} \ No newline at end of file From 1a618eb378acf1b0d13c15e8a45dc2cf31877d60 Mon Sep 17 00:00:00 2001 From: Matt Davidson Date: Wed, 26 Feb 2025 13:55:38 -0500 Subject: [PATCH 2/4] requires version bump for strings --- version.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.php b/version.php index b917e23..30e8e64 100644 --- a/version.php +++ b/version.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die(); $plugin = new stdClass(); -$plugin->version = 2025060200; // The current plugin version (Date: YYYYMMDDXX). +$plugin->version = 2025060201; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2014111000; // Requires this Moodle version. $plugin->component = 'tool_coursearchiver'; // Full name of the plugin (used for diagnostics). $plugin->release = '4.5.0 (Build: 2016090200)'; From 973c5ab7eb08988b0fbe975cc248a186056e53ff Mon Sep 17 00:00:00 2001 From: Matt Davidson Date: Wed, 26 Feb 2025 14:47:40 -0500 Subject: [PATCH 3/4] fix checkbox names and lengths --- classes/processor.php | 11 ++++++++--- templates/archive_view.mustache | 16 ++++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/classes/processor.php b/classes/processor.php index b230ef5..0fc58e6 100644 --- a/classes/processor.php +++ b/classes/processor.php @@ -1436,15 +1436,20 @@ public static function select_deselect_javascript() { $(".coursearchiver_selectall #id_toggle").click(function() { var text = $(this).val().length > 0 ? $(this).val() : $(this).text().trim(); if ("'.get_string('selectall', 'tool_coursearchiver').'" === text) { - $(".coursearchiveselection").prop("checked", true); + $("input[type=checkbox]", "#region-main").prop("checked", true); $(".coursearchiver_selectall #id_toggle").val("'.get_string('deselectall', 'tool_coursearchiver').'"); $(".coursearchiver_selectall #id_toggle").text("'.get_string('deselectall', 'tool_coursearchiver').'"); } else if ("'.get_string('deselectall', 'tool_coursearchiver').'" === text) { - $(".coursearchiveselection").prop("checked", false); + $("input[type=checkbox]", "#region-main").prop("checked", false); $(".coursearchiver_selectall #id_toggle").val("'.get_string('selectall', 'tool_coursearchiver').'"); $(".coursearchiver_selectall #id_toggle").text("'.get_string('selectall', 'tool_coursearchiver').'"); } - let visible = $(".coursearchiveselection:checked").length ? $(".coursearchivermultibuttons").show() : $(".coursearchivermultibuttons").hide(); + + if ($("input[type=checkbox]:checked", "#region-main").length) { + $(".camultibuttons").show(); + } else { + $(".camultibuttons").hide(); + } }); }); '); diff --git a/templates/archive_view.mustache b/templates/archive_view.mustache index 3a17a1c..1ef2b3e 100644 --- a/templates/archive_view.mustache +++ b/templates/archive_view.mustache @@ -105,13 +105,17 @@ {{#isadmin}} - {{/recover}} {{^recover}} From 3af275149c696f93c15539a0da6cb9723768ae78 Mon Sep 17 00:00:00 2001 From: Matt Davidson Date: Tue, 1 Jul 2025 13:44:01 -0400 Subject: [PATCH 4/4] Update processor.php --- classes/processor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/processor.php b/classes/processor.php index c4db36b..95242c9 100644 --- a/classes/processor.php +++ b/classes/processor.php @@ -1655,7 +1655,7 @@ public static function get_archivelist($search, $recover = false) { 0, $config->archivelimit ); - + // Form start. $rowcolor = "#FFF"; $data = [