diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 8e1ae73..b7d489b 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -30,8 +30,8 @@ jobs:
strategy:
fail-fast: false
matrix:
- php: ['8.2', '8.3']
- moodle-branch: ['main', 'MOODLE_500_STABLE']
+ php: ['8.3', '8.4']
+ moodle-branch: ['main', 'MOODLE_501_STABLE', 'MOODLE_500_STABLE']
database: [pgsql, mariadb]
steps:
@@ -66,10 +66,6 @@ jobs:
if: ${{ always() }}
run: moodle-plugin-ci phplint
- - name: PHP Copy/Paste Detector
- if: ${{ always() }}
- run: moodle-plugin-ci phpcpd
-
- name: PHP Mess Detector
continue-on-error: true # This step will show errors but will not fail
if: ${{ always() }}
diff --git a/action.php b/action.php
index 75befde..24a3b4a 100644
--- a/action.php
+++ b/action.php
@@ -88,8 +88,12 @@
$duplicatetask->set_userid($USER->id);
$duplicatetask->set_custom_data(['modules' => $modulerecords]);
manager::queue_adhoc_task($duplicatetask);
- redirect($returnurl, get_string('backgroundtaskinformation', 'block_massaction'), null,
- notification::NOTIFY_SUCCESS);
+ redirect(
+ $returnurl,
+ get_string('backgroundtaskinformation', 'block_massaction'),
+ null,
+ notification::NOTIFY_SUCCESS
+ );
} else {
block_massaction\actions::duplicate($modulerecords);
}
@@ -139,8 +143,12 @@
$duplicatetask->set_userid($USER->id);
$duplicatetask->set_custom_data(['modules' => $modulerecords, 'sectionid' => $data->duplicateToTarget]);
manager::queue_adhoc_task($duplicatetask);
- redirect($returnurl, get_string('backgroundtaskinformation', 'block_massaction'), null,
- notification::NOTIFY_SUCCESS);
+ redirect(
+ $returnurl,
+ get_string('backgroundtaskinformation', 'block_massaction'),
+ null,
+ notification::NOTIFY_SUCCESS
+ );
} else {
block_massaction\actions::duplicate($modulerecords, $data->duplicateToTarget);
}
@@ -178,7 +186,6 @@
actions::print_course_select_form($courseselectform);
break;
} else if ($data = $sectionselectform->get_data()) {
-
// We validate the section number and default to 'same section than source course' if it is not a proper section
// number.
$targetsectionnum = property_exists($data, 'targetsectionnum') && is_numeric($data->targetsectionnum)
@@ -190,15 +197,22 @@
$duplicatetask->set_custom_data(['modules' => $modulerecords, 'sectionnum' => $targetsectionnum,
'courseid' => $targetcourseid]);
manager::queue_adhoc_task($duplicatetask);
- redirect($returnurl, get_string('backgroundtaskinformation', 'block_massaction'), null,
- notification::NOTIFY_SUCCESS);
+ redirect(
+ $returnurl,
+ get_string('backgroundtaskinformation', 'block_massaction'),
+ null,
+ notification::NOTIFY_SUCCESS
+ );
} else {
block_massaction\actions::duplicate_to_course($modulerecords, $targetcourseid, $targetsectionnum);
}
- redirect($returnurl, get_string('actionexecuted', 'block_massaction'), null,
- notification::NOTIFY_SUCCESS);
-
+ redirect(
+ $returnurl,
+ get_string('actionexecuted', 'block_massaction'),
+ null,
+ notification::NOTIFY_SUCCESS
+ );
} else {
$redirect = false;
actions::print_section_select_form($sectionselectform);
@@ -213,6 +227,10 @@
// Redirect back to the previous page.
// If an error has occurred, the action handler functions already should have thrown an exception to the user, so if we get to
// this point in the code, the demanded action should have been successful.
- redirect($returnurl, get_string('actionexecuted', 'block_massaction'), null,
- notification::NOTIFY_SUCCESS);
+ redirect(
+ $returnurl,
+ get_string('actionexecuted', 'block_massaction'),
+ null,
+ notification::NOTIFY_SUCCESS
+ );
}
diff --git a/block_massaction.php b/block_massaction.php
index 80b3bd1..c657b60 100644
--- a/block_massaction.php
+++ b/block_massaction.php
@@ -14,25 +14,17 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Primary block class.
- *
- * @package block_massaction
- * @copyright 2013 University of Minnesota
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
use block_massaction\hook\filter_sections_different_course;
use block_massaction\hook\filter_sections_same_course;
/**
* Configures and displays the block.
*
+ * @package block_massaction
* @copyright 2013 University of Minnesota
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_massaction extends block_base {
-
/**
* Initialize the plugin. This method is being called by the parent constructor by default.
*/
@@ -140,8 +132,10 @@ public function get_content(): stdClass {
$context = context_course::instance($COURSE->id);
// Actions to be rendered later on.
$actionicons = [];
- if (has_capability('moodle/course:activityvisibility', $context)
- && has_capability('block/massaction:activityshowhide', $blockcontext)) {
+ if (
+ has_capability('moodle/course:activityvisibility', $context)
+ && has_capability('block/massaction:activityshowhide', $blockcontext)
+ ) {
// As we want to use this symbol for the *operation*, not the state, we switch the icons hide/show.
$actionicons['show'] = 't/hide';
$actionicons['hide'] = 't/show';
@@ -149,21 +143,27 @@ public function get_content(): stdClass {
$actionicons['makeavailable'] = 't/block';
}
}
- if (has_capability('moodle/backup:backuptargetimport', $context)
- && has_capability('moodle/restore:restoretargetimport', $context)
- && has_capability('block/massaction:duplicate', $blockcontext)) {
+ if (
+ has_capability('moodle/backup:backuptargetimport', $context)
+ && has_capability('moodle/restore:restoretargetimport', $context)
+ && has_capability('block/massaction:duplicate', $blockcontext)
+ ) {
$actionicons['duplicate'] = 't/copy';
}
- if (has_capability('moodle/backup:backuptargetimport', $context)
- && has_capability('block/massaction:duplicatetocourse', $blockcontext)) {
+ if (
+ has_capability('moodle/backup:backuptargetimport', $context)
+ && has_capability('block/massaction:duplicatetocourse', $blockcontext)
+ ) {
$actionicons['duplicatetocourse'] = 't/copy';
}
if (has_capability('moodle/course:manageactivities', $context)) {
if (has_capability('block/massaction:delete', $blockcontext)) {
$actionicons['delete'] = 't/delete';
}
- if (course_get_format($COURSE->id)->uses_indentation()
- && has_capability('block/massaction:indent', $blockcontext)) {
+ if (
+ course_get_format($COURSE->id)->uses_indentation()
+ && has_capability('block/massaction:indent', $blockcontext)
+ ) {
// From Moodle 4.0 on the course format has to declare if it supports indentation or not.
$actionicons['moveright'] = 't/right';
$actionicons['moveleft'] = 't/left';
@@ -183,19 +183,26 @@ public function get_content(): stdClass {
'actiontext' => get_string('action_' . $action, 'block_massaction')];
}
- $this->content->text = $OUTPUT->render_from_template('block_massaction/block_massaction',
- ['actions' => $actions,
- 'formaction' => $CFG->wwwroot . '/blocks/massaction/action.php',
- 'instanceid' => $this->instance->id, 'requesturi' => $_SERVER['REQUEST_URI'],
- 'helpicon' => $OUTPUT->help_icon('usage', 'block_massaction'),
- 'show_moveto_select' => (has_capability('moodle/course:manageactivities', $context) &&
- has_capability('block/massaction:movetosection', $context)),
- 'show_duplicateto_select' => (has_capability('moodle/backup:backuptargetimport', $context) &&
- has_capability('moodle/restore:restoretargetimport', $context) &&
- has_capability('block/massaction:movetosection', $context)),
- 'sectionselecthelpicon' => $OUTPUT->help_icon('sectionselect', 'block_massaction'),
+ $this->content->text = $OUTPUT->render_from_template(
+ 'block_massaction/block_massaction',
+ [
+ 'actions' => $actions,
+ 'formaction' => $CFG->wwwroot . '/blocks/massaction/action.php',
+ 'instanceid' => $this->instance->id, 'requesturi' => $_SERVER['REQUEST_URI'],
+ 'helpicon' => $OUTPUT->help_icon('usage', 'block_massaction'),
+ 'show_moveto_select' => (
+ has_capability('moodle/course:manageactivities', $context) &&
+ has_capability('block/massaction:movetosection', $context)
+ ),
+ 'show_duplicateto_select' => (
+ has_capability('moodle/backup:backuptargetimport', $context) &&
+ has_capability('moodle/restore:restoretargetimport', $context) &&
+ has_capability('block/massaction:movetosection', $context)
+ ),
+ 'sectionselecthelpicon' => $OUTPUT->help_icon('sectionselect', 'block_massaction'),
'availabletargetsections' => implode(',', $sectionsavailable),
- ]);
+ ]
+ );
}
return $this->content;
}
diff --git a/classes/actions.php b/classes/actions.php
index 98ec1fe..a2525ee 100644
--- a/classes/actions.php
+++ b/classes/actions.php
@@ -14,15 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * actions class: Utility class providing methods for actions performed by the massaction block.
- *
- * @package block_massaction
- * @copyright 2021 ISB Bayern
- * @author Philipp Memmel
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
namespace block_massaction;
use base_plan_exception;
@@ -43,8 +34,9 @@
use restore_controller_exception;
/**
- * Block actions class.
+ * actions class: Utility class providing methods for actions performed by the massaction block.
*
+ * @package block_massaction
* @copyright 2021 ISB Bayern
* @author Philipp Memmel
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
@@ -142,15 +134,18 @@ public static function duplicate(array $modules, $sectionnumber = false): void {
global $CFG, $DB;
require_once($CFG->dirroot . '/course/lib.php');
require_once($CFG->dirroot . '/lib/modinfolib.php');
- if (empty($modules) || !reset($modules)
- || !property_exists(reset($modules), 'course')) {
+ if (
+ empty($modules)
+ || !reset($modules)
+ || !property_exists(reset($modules), 'course')
+ ) {
return;
}
$courseid = reset($modules)->course;
if (!$DB->record_exists('course', ['id' => $courseid])) {
debugging('Could not find the course (id ' . $courseid
- . '), has probably been deleted before we can duplicate, exiting cleanly.');
+ . '), has probably been deleted before we can duplicate, exiting cleanly.');
return;
}
@@ -240,31 +235,42 @@ public static function duplicate_to_course(array $modules, int $targetcourseid,
global $CFG, $DB;
require_once($CFG->dirroot . '/course/lib.php');
require_once($CFG->dirroot . '/lib/modinfolib.php');
- if (empty($modules) || !reset($modules)
- || !property_exists(reset($modules), 'course')) {
+ if (
+ empty($modules)
+ || !reset($modules)
+ || !property_exists(reset($modules), 'course')
+ ) {
return;
}
$sourcecourseid = reset($modules)->course;
if (!$DB->record_exists('course', ['id' => $sourcecourseid])) {
debugging('Could not find the source course (id ' . $sourcecourseid
- . '), has probably been deleted before we can duplicate to this course, exiting cleanly.');
+ . '), has probably been deleted before we can duplicate to this course, exiting cleanly.');
return;
}
if (!$DB->record_exists('course', ['id' => $targetcourseid])) {
debugging('Could not find the target course (id ' . $targetcourseid
- . '), has probably been deleted before we can duplicate to this course, exiting cleanly.');
+ . '), has probably been deleted before we can duplicate to this course, exiting cleanly.');
return;
}
$sourcecoursecontext = context_course::instance($sourcecourseid);
$targetcoursecontext = context_course::instance($targetcourseid);
if (!has_capability('moodle/backup:backuptargetimport', $sourcecoursecontext)) {
- throw new required_capability_exception($sourcecoursecontext,
- 'moodle/backup:backuptargetimport', 'nocaptobackup', 'block_massaction');
+ throw new required_capability_exception(
+ $sourcecoursecontext,
+ 'moodle/backup:backuptargetimport',
+ 'nocaptobackup',
+ 'block_massaction'
+ );
}
if (!has_capability('moodle/restore:restoretargetimport', $targetcoursecontext)) {
- throw new required_capability_exception($targetcoursecontext,
- 'moodle/restore:restoretargetimport', 'nocaptorestore', 'block_massaction');
+ throw new required_capability_exception(
+ $targetcoursecontext,
+ 'moodle/restore:restoretargetimport',
+ 'nocaptorestore',
+ 'block_massaction'
+ );
}
$sourcemodinfo = get_fast_modinfo($sourcecourseid);
@@ -272,8 +278,10 @@ public static function duplicate_to_course(array $modules, int $targetcourseid,
$targetformat = course_get_format($targetmodinfo->get_course());
$lastsectionnum = $targetformat->get_last_section_number();
- $filtersectionshook = new filter_sections_different_course($targetcourseid,
- array_keys($targetmodinfo->get_section_info_all()));
+ $filtersectionshook = new filter_sections_different_course(
+ $targetcourseid,
+ array_keys($targetmodinfo->get_section_info_all())
+ );
\core\di::get(\core\hook\manager::class)->dispatch($filtersectionshook);
$filteredsections = $filtersectionshook->get_sectionnums();
@@ -308,7 +316,7 @@ public static function duplicate_to_course(array $modules, int $targetcourseid,
// Update course format setting to prevent new orphaned sections.
if (isset($targetformatopt['numsections'])) {
- update_course((object)['id' => $targetcourseid, 'numsections' => $targetformatopt['numsections'] + 1]);
+ update_course((object) ['id' => $targetcourseid, 'numsections' => $targetformatopt['numsections'] + 1]);
}
// Make sure new sectionnum is set accurately.
@@ -318,7 +326,7 @@ public static function duplicate_to_course(array $modules, int $targetcourseid,
if ($sectionnum == -1) {
// In case no target section is specified we make sure that enough sections in the target course exist before
// duplicating, so each course module will be restored to the section number it has in the source course.
- $srcmaxsectionnum = max(array_map(function($mod) use ($sourcemodinfo) {
+ $srcmaxsectionnum = max(array_map(function ($mod) use ($sourcemodinfo) {
return $sourcemodinfo->get_cm($mod->id)->sectionnum;
}, $modules));
@@ -333,7 +341,7 @@ public static function duplicate_to_course(array $modules, int $targetcourseid,
// Update course format setting to prevent orphaned sections.
$targetformatopt = $targetformat->get_format_options();
if (isset($targetformatopt['numsections']) && $targetformatopt['numsections'] < $srcmaxsectionnum) {
- update_course((object)['id' => $targetcourseid, 'numsections' => $srcmaxsectionnum]);
+ update_course((object) ['id' => $targetcourseid, 'numsections' => $srcmaxsectionnum]);
}
}
@@ -357,17 +365,21 @@ public static function duplicate_to_course(array $modules, int $targetcourseid,
}
try {
- $duplicatedmod = massactionutils::duplicate_cm_to_course($targetmodinfo->get_course(),
- $sourcemodinfo->get_cm($cmid));
+ $duplicatedmod = massactionutils::duplicate_cm_to_course(
+ $targetmodinfo->get_course(),
+ $sourcemodinfo->get_cm($cmid)
+ );
} catch (\Exception $e) {
$errors[$cmid] = 'cmid:' . $cmid . '(' . $e->getMessage() . ')';
- $event = \block_massaction\event\course_modules_duplicated_failed::create([
- 'context' => \context_course::instance($sourcecourseid),
- 'other' => [
- 'cmid' => $cmid,
- 'error' => $errors[$cmid],
- ],
- ]);
+ $event = \block_massaction\event\course_modules_duplicated_failed::create(
+ [
+ 'context' => \context_course::instance($sourcecourseid),
+ 'other' => [
+ 'cmid' => $cmid,
+ 'error' => $errors[$cmid],
+ ],
+ ]
+ );
$event->trigger();
continue;
}
@@ -439,8 +451,12 @@ public static function print_section_select_form(section_select_form $sectionsel
* @throws require_login_exception
* @throws required_capability_exception
*/
- public static function print_deletion_confirmation(array $modules, string $massactionrequest,
- int $instanceid, string $returnurl): void {
+ public static function print_deletion_confirmation(
+ array $modules,
+ string $massactionrequest,
+ int $instanceid,
+ string $returnurl
+ ): void {
global $DB, $PAGE, $OUTPUT, $CFG;
$modulelist = [];
@@ -478,16 +494,24 @@ public static function print_deletion_confirmation(array $modules, string $massa
echo $OUTPUT->header();
// Render the content.
- $content = $OUTPUT->render_from_template('block_massaction/deletionconfirm',
- ['modules' => $modulelist]);
+ $content = $OUTPUT->render_from_template(
+ 'block_massaction/deletionconfirm',
+ ['modules' => $modulelist]
+ );
echo $OUTPUT->box_start('noticebox');
$formcontinue =
- new \single_button(new \moodle_url("{$CFG->wwwroot}/blocks/massaction/action.php", $optionsonconfirm),
- get_string('delete'), 'post');
+ new \single_button(
+ new \moodle_url("{$CFG->wwwroot}/blocks/massaction/action.php", $optionsonconfirm),
+ get_string('delete'),
+ 'post'
+ );
$formcancel =
- new \single_button(new \moodle_url("{$CFG->wwwroot}/course/view.php?id={$course->id}", $optionsoncancel),
- get_string('cancel'), 'get');
+ new \single_button(
+ new \moodle_url("{$CFG->wwwroot}/course/view.php?id={$course->id}", $optionsoncancel),
+ get_string('cancel'),
+ 'get'
+ );
echo $OUTPUT->confirm($content, $formcontinue, $formcancel);
echo $OUTPUT->box_end();
echo $OUTPUT->footer();
@@ -591,7 +615,8 @@ public static function send_content_changed_notifications(array $modules): void
// being sent. As all modules we handle with block_massaction already exist we can safely set 'update' to 1 which
// means that the message will read 'course module updated' instead of 'new course module added'.
$adhoctask->set_custom_data(
- ['update' => 1, 'cmid' => $cm->id, 'courseid' => $course->id, 'userfrom' => $USER->id]);
+ ['update' => 1, 'cmid' => $cm->id, 'courseid' => $course->id, 'userfrom' => $USER->id]
+ );
$adhoctask->set_component('course');
manager::queue_adhoc_task($adhoctask, true);
}
@@ -616,8 +641,8 @@ public static function perform_moveto(array $modules, int $target): void {
if (!empty($modules)) {
$courseid = reset($modules)->course;
$filtersectionshook = new filter_sections_same_course(
- $courseid,
- array_keys(get_fast_modinfo($courseid)->get_section_info_all())
+ $courseid,
+ array_keys(get_fast_modinfo($courseid)->get_section_info_all())
);
\core\di::get(\core\hook\manager::class)->dispatch($filtersectionshook);
}
@@ -666,11 +691,20 @@ private static function sort_course_order(array $modules): array {
}
// We filter all modules: After that only the modules which should be duplicated are being left.
- $idsincourseorder = array_filter($idsincourseorder, function($cmid) use ($modules) {
- return in_array($cmid, array_map(function($cm) {
- return $cm->id;
- }, $modules));
- });
+ $idsincourseorder = array_filter(
+ $idsincourseorder,
+ function ($cmid) use ($modules) {
+ return in_array(
+ $cmid,
+ array_map(
+ function ($cm) {
+ return $cm->id;
+ },
+ $modules
+ )
+ );
+ }
+ );
return $idsincourseorder;
}
diff --git a/classes/event/course_modules_duplicated.php b/classes/event/course_modules_duplicated.php
index 2ae0a54..43ae8e7 100644
--- a/classes/event/course_modules_duplicated.php
+++ b/classes/event/course_modules_duplicated.php
@@ -28,7 +28,6 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_modules_duplicated extends base {
-
/**
* Initialise required event data properties.
*/
@@ -55,28 +54,43 @@ public function get_description(): string {
$cms = [];
$failed = [];
foreach ($this->other['cms'] as $srccm => $dstcm) {
- $cms[] = get_string('event:duplicated_description',
- 'block_massaction',
- ['src' => $srccm,
- 'dst' => $dstcm,
- ]);
+ $cms[] = get_string(
+ 'event:duplicated_description',
+ 'block_massaction',
+ ['src' => $srccm,
+ 'dst' => $dstcm,
+ ]
+ );
}
foreach ($this->other['failed'] as $cmid) {
$failed[] = 'cmid \'' . $cmid . '\'';
}
- 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)]) : '');
+ 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 4b8a30c..4590559 100644
--- a/classes/event/course_modules_duplicated_failed.php
+++ b/classes/event/course_modules_duplicated_failed.php
@@ -28,7 +28,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_modules_duplicated_failed extends base {
-
/**
* Initialise required event data properties.
*/
@@ -52,11 +51,13 @@ public static function get_name(): string {
* @return string
*/
public function get_description(): string {
- return get_string('event:duplicated_failed_description',
- 'block_massaction',
- ['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/form/course_select_form.php b/classes/form/course_select_form.php
index 5beccd9..f87ab1a 100644
--- a/classes/form/course_select_form.php
+++ b/classes/form/course_select_form.php
@@ -43,7 +43,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_select_form extends moodleform {
-
/**
* Form definition.
*/
@@ -64,9 +63,16 @@ public function definition() {
$mform->addElement('header', 'choosetargetcourse', get_string('choosetargetcourse', 'block_massaction'));
$limittoenrolled = !empty(get_config('block_massaction', 'limittoenrolled'));
- $mform->addElement('course', 'targetcourseid', get_string('choosecoursetoduplicateto', 'block_massaction'),
- ['limittoenrolled' => $limittoenrolled, 'exclude' => $sourcecourseid,
- 'requiredcapabilities' => ['moodle/restore:restoretargetimport']]);
+ $mform->addElement(
+ 'course',
+ 'targetcourseid',
+ get_string('choosecoursetoduplicateto', 'block_massaction'),
+ [
+ 'limittoenrolled' => $limittoenrolled,
+ 'exclude' => $sourcecourseid,
+ 'requiredcapabilities' => ['moodle/restore:restoretargetimport'],
+ ]
+ );
$this->add_action_buttons(true, get_string('confirmcourseselect', 'block_massaction'));
}
diff --git a/classes/form/section_select_form.php b/classes/form/section_select_form.php
index 7364120..de35bd1 100644
--- a/classes/form/section_select_form.php
+++ b/classes/form/section_select_form.php
@@ -46,7 +46,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class section_select_form extends moodleform {
-
/**
* Form definition.
*/
@@ -67,13 +66,21 @@ public function definition() {
$mform->addElement('header', 'choosetargetsection', get_string('choosetargetsection', 'block_massaction'));
if (empty($targetcourseid)) {
- redirect($this->_customdata['return_url'], get_string('notargetcourseidspecified', 'block_massaction'),
- null, notification::NOTIFY_ERROR);
+ redirect(
+ $this->_customdata['return_url'],
+ get_string('notargetcourseidspecified', 'block_massaction'),
+ null,
+ notification::NOTIFY_ERROR
+ );
}
if (empty($sourcecourseid)) {
- redirect($this->_customdata['return_url'], get_string('sourcecourseidlost', 'block_massaction'),
- null, notification::NOTIFY_ERROR);
+ redirect(
+ $this->_customdata['return_url'],
+ get_string('sourcecourseidlost', 'block_massaction'),
+ null,
+ notification::NOTIFY_ERROR
+ );
}
$sourcecoursemodinfo = get_fast_modinfo($sourcecourseid);
@@ -89,7 +96,7 @@ public function definition() {
}
// We create an array with the sections. If a section does not have a name, we name it 'Section $sectionnumber'.
- $targetsections = array_map(function($section) {
+ $targetsections = array_map(function ($section) {
$name = $section->name;
if (empty($section->name)) {
$name = get_string('section') . ' ' . $section->section;
@@ -112,7 +119,7 @@ public function definition() {
$massactionrequest = $this->_customdata['request'];
$data = \block_massaction\massactionutils::extract_modules_from_json($massactionrequest);
$modules = $data->modulerecords;
- $srcmaxsectionnum = max(array_map(function($mod) use ($sourcecoursemodinfo) {
+ $srcmaxsectionnum = max(array_map(function ($mod) use ($sourcecoursemodinfo) {
return $sourcecoursemodinfo->get_cm($mod->id)->sectionnum;
}, $modules));
@@ -120,8 +127,14 @@ public function definition() {
// If user can add sections in target course or don't need to be able to.
if (($canaddsection || $srcmaxsectionnum <= $targetsectionnum) && $filtersectionshook->is_originsectionkept()) {
// We add the default value: Restore each course module to the section number it has in the source course.
- $radioarray[] = $mform->createElement('radio', 'targetsectionnum', '',
- get_string('keepsectionnum', 'block_massaction'), -1, ['class' => 'mt-2']);
+ $radioarray[] = $mform->createElement(
+ 'radio',
+ 'targetsectionnum',
+ '',
+ get_string('keepsectionnum', 'block_massaction'),
+ -1,
+ ['class' => 'mt-2']
+ );
}
// Now add the sections of the target course.
@@ -130,20 +143,35 @@ public function definition() {
if (!in_array($sectionnum, $filteredsections)) {
$attributes['disabled'] = 'disabled';
}
- $radioarray[] = $mform->createElement('radio', 'targetsectionnum',
- '', $sectionname, $sectionnum, $attributes);
+ $radioarray[] = $mform->createElement(
+ 'radio',
+ 'targetsectionnum',
+ '',
+ $sectionname,
+ $sectionnum,
+ $attributes
+ );
}
if ($canaddsection) {
- if (($targetsectionnum + 1) <= $targetformat->get_max_sections()) {
- // New section option.
- $radioarray[] = $mform->createElement('radio', 'targetsectionnum', '',
- get_string('newsection', 'block_massaction'), $targetsectionnum + 1, ['class' => 'mt-2']);
- }
+ // New section option.
+ $radioarray[] = $mform->createElement(
+ 'radio',
+ 'targetsectionnum',
+ '',
+ get_string('newsection', 'block_massaction'),
+ $targetsectionnum + 1,
+ ['class' => 'mt-2']
+ );
}
- $mform->addGroup($radioarray, 'sections', get_string('choosesectiontoduplicateto', 'block_massaction'),
- '
', false);
+ $mform->addGroup(
+ $radioarray,
+ 'sections',
+ get_string('choosesectiontoduplicateto', 'block_massaction'),
+ '
',
+ false
+ );
$mform->setDefault('targetsectionnum', -1);
$this->add_action_buttons(true, get_string('confirmsectionselect', 'block_massaction'));
diff --git a/classes/hook/filter_sections_different_course.php b/classes/hook/filter_sections_different_course.php
index 614c7d8..bbb45c0 100644
--- a/classes/hook/filter_sections_different_course.php
+++ b/classes/hook/filter_sections_different_course.php
@@ -16,8 +16,6 @@
namespace block_massaction\hook;
-defined('MOODLE_INTERNAL') || die();
-
#[\core\attribute\label('Hook dispatched when block_massaction is duplicating activities into another course. '
. 'The hook provides ways to customize which sections the user can duplicate activities to.')]
#[\core\attribute\tags('block_massaction')]
@@ -30,7 +28,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class filter_sections_different_course {
-
use filter_sections_handler;
/** @var bool Determines if the user will be able to keep the original section of a course module when performing some operations. */
diff --git a/classes/hook/filter_sections_handler.php b/classes/hook/filter_sections_handler.php
index a86adff..671623c 100644
--- a/classes/hook/filter_sections_handler.php
+++ b/classes/hook/filter_sections_handler.php
@@ -16,8 +16,6 @@
namespace block_massaction\hook;
-use coding_exception;
-
/**
* Trait for providing the common methods for the filter sections hooks.
*
@@ -27,7 +25,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
trait filter_sections_handler {
-
/** @var array Array of section numbers which originally are available for block_massaction. */
private readonly array $originalsectionnums;
@@ -38,10 +35,10 @@ trait filter_sections_handler {
* @param array $sectionnums the section numbers which are available (so the available sections the hook listeners may filter)
*/
public function __construct(
- /** @var int the course id which is target for section select. */
- private readonly int $courseid,
- /** @var array $sectionnums the section numbers which are available (so the available sections the hook listeners may filter) */
- private array $sectionnums
+ /** @var int the course id which is target for section select. */
+ private readonly int $courseid,
+ /** @var array $sectionnums the section numbers which are available (so the available sections the hook listeners may filter) */
+ private array $sectionnums
) {
$this->originalsectionnums = $this->sectionnums;
}
diff --git a/classes/hook/filter_sections_same_course.php b/classes/hook/filter_sections_same_course.php
index aa50245..fdab3fa 100644
--- a/classes/hook/filter_sections_same_course.php
+++ b/classes/hook/filter_sections_same_course.php
@@ -16,8 +16,6 @@
namespace block_massaction\hook;
-defined('MOODLE_INTERNAL') || die();
-
#[\core\attribute\label('Hook dispatched when block_massaction is duplicating or moving activities inside a course. '
. 'The hook provides ways to customize which sections the user can duplicate/move activities to.')]
#[\core\attribute\tags('block_massaction')]
@@ -30,8 +28,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class filter_sections_same_course {
-
// We use the trait here, because inheritance is not recommended for hooks.
use filter_sections_handler;
-
}
diff --git a/classes/massactionutils.php b/classes/massactionutils.php
index 07ca39d..baef940 100644
--- a/classes/massactionutils.php
+++ b/classes/massactionutils.php
@@ -14,15 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * massactionutils class: Utility class providing methods for generating data used by the massaction block.
- *
- * @package block_massaction
- * @copyright 2021 ISB Bayern
- * @author Philipp Memmel
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
namespace block_massaction;
use backup;
@@ -38,14 +29,14 @@
use stdClass;
/**
- * Mass action utility functions class.
+ * Utility class providing methods for generating data used by the massaction block.
*
+ * @package block_massaction
* @copyright 2021 ISB Bayern
* @author Philipp Memmel
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class massactionutils {
-
/**
* Method to extract the modules from the request JSON which is sent by the block_massaction JS module to the backend.
*
@@ -65,9 +56,11 @@ public static function extract_modules_from_json(string $massactionrequest): std
throw new moodle_exception('jsonerror', 'block_massaction');
}
- $modulerecords = $DB->get_records_select('course_modules',
+ $modulerecords = $DB->get_records_select(
+ 'course_modules',
'id IN (' . implode(',', array_fill(0, count($data->moduleIds), '?')) . ')',
- $data->moduleIds);
+ $data->moduleIds
+ );
foreach ($data->moduleIds as $modid) {
if (!isset($modulerecords[$modid])) {
@@ -114,8 +107,14 @@ public static function duplicate_cm_to_course(object $course, object $cm): int {
// Backup the activity.
- $bc = new backup_controller(backup::TYPE_1ACTIVITY, $cm->id, backup::FORMAT_MOODLE,
- backup::INTERACTIVE_NO, backup::MODE_IMPORT, $USER->id);
+ $bc = new backup_controller(
+ backup::TYPE_1ACTIVITY,
+ $cm->id,
+ backup::FORMAT_MOODLE,
+ backup::INTERACTIVE_NO,
+ backup::MODE_IMPORT,
+ $USER->id
+ );
$backupid = $bc->get_backupid();
$backupbasepath = $bc->get_plan()->get_basepath();
@@ -125,8 +124,14 @@ public static function duplicate_cm_to_course(object $course, object $cm): int {
$bc->destroy();
// Restore the backup immediately.
- $rc = new restore_controller($backupid, $course->id,
- backup::INTERACTIVE_NO, backup::MODE_IMPORT, $USER->id, backup::TARGET_CURRENT_ADDING);
+ $rc = new restore_controller(
+ $backupid,
+ $course->id,
+ backup::INTERACTIVE_NO,
+ backup::MODE_IMPORT,
+ $USER->id,
+ backup::TARGET_CURRENT_ADDING
+ );
// Make sure that the restore_general_groups setting is always enabled when duplicating an activity.
$plan = $rc->get_plan();
diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php
index f73acb1..88dec0d 100644
--- a/classes/privacy/provider.php
+++ b/classes/privacy/provider.php
@@ -14,26 +14,17 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Privacy Subsystem implementation for block_massaction.
- *
- * @package block_massaction
- * @copyright 2021 ISB Bayern
- * @author Philipp Memmel
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
namespace block_massaction\privacy;
/**
* Privacy Subsystem for blocks_massaction implementing null_provider.
*
+ * @package block_massaction
* @copyright 2021 ISB Bayern
* @author Philipp Memmel
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
-
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
diff --git a/classes/task/duplicate_task.php b/classes/task/duplicate_task.php
index 5c83ced..90bfcba 100644
--- a/classes/task/duplicate_task.php
+++ b/classes/task/duplicate_task.php
@@ -14,15 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * duplicate_task class: Adhoc task to process duplicating course modules from the block_massaction plugin.
- *
- * @package block_massaction
- * @copyright 2022 ISB Bayern
- * @author Philipp Memmel
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
namespace block_massaction\task;
use block_massaction\actions;
@@ -32,14 +23,14 @@
use restore_controller_exception;
/**
- * Duplicate task class.
+ * duplicate_task class: Adhoc task to process duplicating course modules from the block_massaction plugin.
*
+ * @package block_massaction
* @copyright 2022 ISB Bayern
* @author Philipp Memmel
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class duplicate_task extends adhoc_task {
-
/**
* Executes the duplication of multiple course modules.
*
diff --git a/db/upgrade.php b/db/upgrade.php
index 0298aa4..5f425b4 100644
--- a/db/upgrade.php
+++ b/db/upgrade.php
@@ -70,9 +70,10 @@ function block_massaction_add_supported_format(string $addformat): void {
$supportedformats = [];
foreach ($plugins as $format => $name) {
- if (isset($name) &&
- (in_array($format, $selectedformats) ||
- $format === $addformat)) {
+ if (
+ isset($name)
+ && (in_array($format, $selectedformats) || $format === $addformat)
+ ) {
$supportedformats[$format] = 1;
}
}
@@ -103,9 +104,11 @@ function block_massaction_remove_supported_format(string $removeformat): void {
$supportedformats = [];
foreach ($plugins as $format => $name) {
- if (isset($name) &&
- in_array($format, $selectedformats) &&
- $format !== $removeformat) {
+ if (
+ isset($name)
+ && in_array($format, $selectedformats)
+ && $format !== $removeformat
+ ) {
$supportedformats[$format] = 1;
}
}
diff --git a/settings.php b/settings.php
index ab96bde..9d23e63 100644
--- a/settings.php
+++ b/settings.php
@@ -26,17 +26,23 @@
defined('MOODLE_INTERNAL') || die;
if ($hassiteconfig) {
-
- $ADMIN->add('blocksettings', new admin_category('block_massaction_settings',
- new lang_string('pluginname', 'block_massaction')));
+ $ADMIN->add(
+ 'blocksettings',
+ new admin_category(
+ 'block_massaction_settings',
+ new lang_string('pluginname', 'block_massaction')
+ )
+ );
if ($ADMIN->fulltree) {
- $settings->add(new admin_setting_configtext(
- 'block_massaction/duplicatemaxactivities',
- new lang_string('duplicatemaxactivities', 'block_massaction'),
- new lang_string('duplicatemaxactivities_description', 'block_massaction'),
- 5
- ));
+ $settings->add(
+ new admin_setting_configtext(
+ 'block_massaction/duplicatemaxactivities',
+ new lang_string('duplicatemaxactivities', 'block_massaction'),
+ new lang_string('duplicatemaxactivities_description', 'block_massaction'),
+ 5
+ )
+ );
$pluginmanager = \core_plugin_manager::instance();
$plugins = [];
@@ -47,26 +53,30 @@
$plugins[$pluginname] = new lang_string('pluginname', 'format_' . $pluginname);
}
// Sort alphabetically. Custom sort function needed, because lang_string is an object.
- uasort($plugins, function($a, $b) {
+ uasort($plugins, function ($a, $b) {
return strcmp($a->out(), $b->out());
});
// These are the formats supported by the maintainer.
$supportedformatsbydefault = ['weeks' => 1, 'topics' => 1, 'topcoll' => 1, 'onetopic' => 1, 'grid' => 1, 'tiles' => 1];
- $settings->add(new admin_setting_configmulticheckbox(
- 'block_massaction/applicablecourseformats',
- new lang_string('applicablecourseformats', 'block_massaction'),
- new lang_string('applicablecourseformats_description', 'block_massaction'),
- $supportedformatsbydefault,
- $plugins)
+ $settings->add(
+ new admin_setting_configmulticheckbox(
+ 'block_massaction/applicablecourseformats',
+ new lang_string('applicablecourseformats', 'block_massaction'),
+ new lang_string('applicablecourseformats_description', 'block_massaction'),
+ $supportedformatsbydefault,
+ $plugins
+ )
);
- $settings->add(new admin_setting_configcheckbox(
- 'block_massaction/limittoenrolled',
- new lang_string('limittoenrolled', 'block_massaction'),
- new lang_string('limittoenrolled_description', 'block_massaction'),
- 1)
+ $settings->add(
+ new admin_setting_configcheckbox(
+ 'block_massaction/limittoenrolled',
+ new lang_string('limittoenrolled', 'block_massaction'),
+ new lang_string('limittoenrolled_description', 'block_massaction'),
+ 1
+ )
);
}
}
diff --git a/tests/behat/behat_massaction.php b/tests/behat/behat_massaction.php
index a634c3a..c08be10 100644
--- a/tests/behat/behat_massaction.php
+++ b/tests/behat/behat_massaction.php
@@ -14,15 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Behat massaction skippable steps definitions.
- *
- * @package block_massaction
- * @copyright 2021 ISB Bayern
- * @author Philipp Memmel
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
require_once(__DIR__ . '/../../../../lib/behat/behat_base.php');
/**
@@ -34,7 +25,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_massaction extends behat_base {
-
/**
* Checks that a given course format is installed.
*
@@ -45,7 +35,7 @@ class behat_massaction extends behat_base {
public function i_installed_course_format($formatname) {
$formatplugins = core_plugin_manager::instance()->get_plugins_of_type('format');
if (!isset($formatplugins[$formatname])) {
- throw new \Moodle\BehatExtension\Exception\SkippedException;
+ throw new \Moodle\BehatExtension\Exception\SkippedException();
}
}
}
diff --git a/tests/massaction_test.php b/tests/massaction_test.php
index b6764e8..3816aaf 100644
--- a/tests/massaction_test.php
+++ b/tests/massaction_test.php
@@ -22,7 +22,6 @@
use block_massaction;
use block_massaction\hook\filter_sections_different_course;
use coding_exception;
-use core\di;
use core\event\course_module_updated;
use core\task\manager;
use dml_exception;
@@ -100,7 +99,7 @@ public function test_extract_modules_from_json(): void {
$modulerecords = $this->get_test_course_modules();
$selectedmodules = array_splice($modulerecords, 1, 3);
- $func = function(object $modulerecords): int {
+ $func = function (object $modulerecords): int {
return $modulerecords->id;
};
$selectedmodules = array_map($func, $selectedmodules);
@@ -161,7 +160,7 @@ public function test_mass_show_hide_description(): void {
$selectedmoduleids[] = get_fast_modinfo($this->course->id)->get_sections()[2][1];
$selectedmoduleids[] = get_fast_modinfo($this->course->id)->get_sections()[3][2];
- $selectedmodules = array_filter($this->get_test_course_modules(), function($module) use ($selectedmoduleids) {
+ $selectedmodules = array_filter($this->get_test_course_modules(), function ($module) use ($selectedmoduleids) {
return in_array($module->id, $selectedmoduleids);
});
@@ -176,7 +175,7 @@ public function test_mass_show_hide_description(): void {
}
block_massaction\actions::show_description($selectedmodules, true);
// Reload modules from database.
- $selectedmodules = array_filter($this->get_test_course_modules(), function($module) use ($selectedmoduleids) {
+ $selectedmodules = array_filter($this->get_test_course_modules(), function ($module) use ($selectedmoduleids) {
return in_array($module->id, $selectedmoduleids);
});
// All selected modules should now show the description in the course page.
@@ -190,7 +189,7 @@ public function test_mass_show_hide_description(): void {
}
block_massaction\actions::show_description($selectedmodules, false);
// Reload modules from database.
- $selectedmodules = array_filter($this->get_test_course_modules(), function($module) use ($selectedmoduleids) {
+ $selectedmodules = array_filter($this->get_test_course_modules(), function ($module) use ($selectedmoduleids) {
return in_array($module->id, $selectedmoduleids);
});
// All selected modules should now not show the description in the course page.
@@ -229,7 +228,7 @@ public function test_mass_move_modules_to_new_section(): void {
$moduleidstomove[] = get_fast_modinfo($this->course->id)->get_sections()[3][2];
$module = $this->get_test_course_modules();
- $modulestomove = array_filter($module, function($module) use ($moduleidstomove) {
+ $modulestomove = array_filter($module, function ($module) use ($moduleidstomove) {
return in_array($module->id, $moduleidstomove);
});
@@ -264,7 +263,7 @@ public function test_mass_hide_unhide_modules(): void {
$selectedmoduleids[] = get_fast_modinfo($this->course->id)->get_sections()[2][1];
$selectedmoduleids[] = get_fast_modinfo($this->course->id)->get_sections()[3][2];
- $selectedmodules = array_filter($this->get_test_course_modules(), function($module) use ($selectedmoduleids) {
+ $selectedmodules = array_filter($this->get_test_course_modules(), function ($module) use ($selectedmoduleids) {
return in_array($module->id, $selectedmoduleids);
});
@@ -274,7 +273,7 @@ public function test_mass_hide_unhide_modules(): void {
}
block_massaction\actions::set_visibility($selectedmodules, false);
// Reload modules from database.
- $selectedmodules = array_filter($this->get_test_course_modules(), function($module) use ($selectedmoduleids) {
+ $selectedmodules = array_filter($this->get_test_course_modules(), function ($module) use ($selectedmoduleids) {
return in_array($module->id, $selectedmoduleids);
});
// All selected modules should now be hidden.
@@ -285,7 +284,7 @@ public function test_mass_hide_unhide_modules(): void {
// Check, if hide them again will change nothing.
block_massaction\actions::set_visibility($selectedmodules, false);
// Reload modules from database.
- $selectedmodules = array_filter($this->get_test_course_modules(), function($module) use ($selectedmoduleids) {
+ $selectedmodules = array_filter($this->get_test_course_modules(), function ($module) use ($selectedmoduleids) {
return in_array($module->id, $selectedmoduleids);
});
// All selected modules should now be hidden.
@@ -296,7 +295,7 @@ public function test_mass_hide_unhide_modules(): void {
// All modules are hidden now, make them visible again.
block_massaction\actions::set_visibility($selectedmodules, true);
// Reload modules from database.
- $selectedmodules = array_filter($this->get_test_course_modules(), function($module) use ($selectedmoduleids) {
+ $selectedmodules = array_filter($this->get_test_course_modules(), function ($module) use ($selectedmoduleids) {
return in_array($module->id, $selectedmoduleids);
});
// All selected modules should now be visible again.
@@ -307,7 +306,7 @@ public function test_mass_hide_unhide_modules(): void {
// All modules are visible now, check if making them visible again will change nothing.
block_massaction\actions::set_visibility($selectedmodules, true);
// Reload modules from database.
- $selectedmodules = array_filter($this->get_test_course_modules(), function($module) use ($selectedmoduleids) {
+ $selectedmodules = array_filter($this->get_test_course_modules(), function ($module) use ($selectedmoduleids) {
return in_array($module->id, $selectedmoduleids);
});
// All selected modules should now still be visible.
@@ -321,7 +320,7 @@ public function test_mass_hide_unhide_modules(): void {
block_massaction\actions::set_visibility($selectedmodules, true, false);
// Reload modules from database.
- $selectedmodules = array_filter($this->get_test_course_modules(), function($module) use ($selectedmoduleids) {
+ $selectedmodules = array_filter($this->get_test_course_modules(), function ($module) use ($selectedmoduleids) {
return in_array($module->id, $selectedmoduleids);
});
// All selected modules should now still be available, but hidden on course page.
@@ -333,7 +332,7 @@ public function test_mass_hide_unhide_modules(): void {
// Check if we can show them again.
block_massaction\actions::set_visibility($selectedmodules, true);
// Reload modules from database.
- $selectedmodules = array_filter($this->get_test_course_modules(), function($module) use ($selectedmoduleids) {
+ $selectedmodules = array_filter($this->get_test_course_modules(), function ($module) use ($selectedmoduleids) {
return in_array($module->id, $selectedmoduleids);
});
// All selected modules should now be completely visible again.
@@ -345,7 +344,7 @@ public function test_mass_hide_unhide_modules(): void {
// Hide them and then make them only available.
block_massaction\actions::set_visibility($selectedmodules, false);
// Reload modules from database.
- $selectedmodules = array_filter($this->get_test_course_modules(), function($module) use ($selectedmoduleids) {
+ $selectedmodules = array_filter($this->get_test_course_modules(), function ($module) use ($selectedmoduleids) {
return in_array($module->id, $selectedmoduleids);
});
// All selected modules should now be completely hidden.
@@ -355,7 +354,7 @@ public function test_mass_hide_unhide_modules(): void {
// Now make them only available, but not visible on course page.
block_massaction\actions::set_visibility($selectedmodules, true, false);
// Reload modules from database.
- $selectedmodules = array_filter($this->get_test_course_modules(), function($module) use ($selectedmoduleids) {
+ $selectedmodules = array_filter($this->get_test_course_modules(), function ($module) use ($selectedmoduleids) {
return in_array($module->id, $selectedmoduleids);
});
// All selected modules should now be only available, but not visible.
@@ -371,7 +370,7 @@ public function test_mass_hide_unhide_modules(): void {
// Now try to make them 'available, but not visible on course page'.
block_massaction\actions::set_visibility($selectedmodules, true, false);
// Reload modules from database.
- $selectedmodules = array_filter($this->get_test_course_modules(), function($module) use ($selectedmoduleids) {
+ $selectedmodules = array_filter($this->get_test_course_modules(), function ($module) use ($selectedmoduleids) {
return in_array($module->id, $selectedmoduleids);
});
// They still should be visible, also on course page.
@@ -453,7 +452,7 @@ public function test_mass_duplicate_modules(): void {
$selectedmoduleids[] = get_fast_modinfo($this->course->id)->get_sections()[3][0];
$selectedmoduleids[] = get_fast_modinfo($this->course->id)->get_sections()[3][2];
- $selectedmodules = array_filter($this->get_test_course_modules(), function($module) use ($selectedmoduleids) {
+ $selectedmodules = array_filter($this->get_test_course_modules(), function ($module) use ($selectedmoduleids) {
return in_array($module->id, $selectedmoduleids);
});
block_massaction\actions::duplicate($selectedmodules);
@@ -464,20 +463,28 @@ public function test_mass_duplicate_modules(): void {
$this->assertEquals($selectedmoduleids[0], $idsinsectionordered[0]);
$this->assertEquals($selectedmoduleids[1], $idsinsectionordered[1]);
// After the six already existing modules the duplicated modules should appear.
- $this->assertEquals($modinfo->get_cm($idsinsectionordered[6])->name,
- $modinfo->get_cm($selectedmoduleids[0])->name . ' (copy)');
- $this->assertEquals($modinfo->get_cm($idsinsectionordered[7])->name,
- $modinfo->get_cm($selectedmoduleids[1])->name . ' (copy)');
+ $this->assertEquals(
+ $modinfo->get_cm($idsinsectionordered[6])->name,
+ $modinfo->get_cm($selectedmoduleids[0])->name . ' (copy)'
+ );
+ $this->assertEquals(
+ $modinfo->get_cm($idsinsectionordered[7])->name,
+ $modinfo->get_cm($selectedmoduleids[1])->name . ' (copy)'
+ );
// Same for the other modules in the other section.
$idsinsectionordered = $sections[3];
$this->assertEquals($selectedmoduleids[2], $idsinsectionordered[0]);
$this->assertEquals($selectedmoduleids[3], $idsinsectionordered[2]);
// After the six already existing modules the duplicated modules should appear.
- $this->assertEquals($modinfo->get_cm($idsinsectionordered[6])->name,
- $modinfo->get_cm($selectedmoduleids[2])->name . ' (copy)');
- $this->assertEquals($modinfo->get_cm($idsinsectionordered[7])->name,
- $modinfo->get_cm($selectedmoduleids[3])->name . ' (copy)');
+ $this->assertEquals(
+ $modinfo->get_cm($idsinsectionordered[6])->name,
+ $modinfo->get_cm($selectedmoduleids[2])->name . ' (copy)'
+ );
+ $this->assertEquals(
+ $modinfo->get_cm($idsinsectionordered[7])->name,
+ $modinfo->get_cm($selectedmoduleids[3])->name . ' (copy)'
+ );
// Now test 'duplicate to section'. We still have not done anything to section 4, so we just use
// section 4 as target section.
@@ -487,14 +494,22 @@ public function test_mass_duplicate_modules(): void {
$sections = $modinfo->get_sections();
$idsinsectionordered = $sections[4];
// After the six already existing modules the duplicated modules should appear.
- $this->assertEquals($modinfo->get_cm($idsinsectionordered[6])->name,
- $modinfo->get_cm($selectedmoduleids[0])->name . ' (copy)');
- $this->assertEquals($modinfo->get_cm($idsinsectionordered[7])->name,
- $modinfo->get_cm($selectedmoduleids[1])->name . ' (copy)');
- $this->assertEquals($modinfo->get_cm($idsinsectionordered[8])->name,
- $modinfo->get_cm($selectedmoduleids[2])->name . ' (copy)');
- $this->assertEquals($modinfo->get_cm($idsinsectionordered[9])->name,
- $modinfo->get_cm($selectedmoduleids[3])->name . ' (copy)');
+ $this->assertEquals(
+ $modinfo->get_cm($idsinsectionordered[6])->name,
+ $modinfo->get_cm($selectedmoduleids[0])->name . ' (copy)'
+ );
+ $this->assertEquals(
+ $modinfo->get_cm($idsinsectionordered[7])->name,
+ $modinfo->get_cm($selectedmoduleids[1])->name . ' (copy)'
+ );
+ $this->assertEquals(
+ $modinfo->get_cm($idsinsectionordered[8])->name,
+ $modinfo->get_cm($selectedmoduleids[2])->name . ' (copy)'
+ );
+ $this->assertEquals(
+ $modinfo->get_cm($idsinsectionordered[9])->name,
+ $modinfo->get_cm($selectedmoduleids[3])->name . ' (copy)'
+ );
}
/**
@@ -574,8 +589,13 @@ public function test_mass_duplicate_modules_to_course(): void {
$sourcecourseid = $this->course->id;
$sourcecoursemodinfo = get_fast_modinfo($sourcecourseid);
// The teacher in the source course should have the necessary capability to backup modules.
- $this->assertTrue(has_capability('moodle/backup:backuptargetimport', \context_course::instance($this->course->id),
- $this->teacher->id));
+ $this->assertTrue(
+ has_capability(
+ 'moodle/backup:backuptargetimport',
+ \context_course::instance($this->course->id),
+ $this->teacher->id
+ )
+ );
// Create target course with one additional section (section 0 does not count for that), so overall it should have
// 2 sections.
@@ -593,9 +613,12 @@ public function test_mass_duplicate_modules_to_course(): void {
$selectedmoduleids[] = get_fast_modinfo($this->course->id)->get_sections()[3][0];
$selectedmoduleids[] = get_fast_modinfo($this->course->id)->get_sections()[3][2];
- $selectedmodules = array_filter($this->get_test_course_modules(), function($module) use ($selectedmoduleids) {
- return in_array($module->id, $selectedmoduleids);
- });
+ $selectedmodules = array_filter(
+ $this->get_test_course_modules(),
+ function ($module) use ($selectedmoduleids) {
+ return in_array($module->id, $selectedmoduleids);
+ }
+ );
$targetcoursemodinfo = get_fast_modinfo($targetcourseid);
$this->assertCount(2, $targetcoursemodinfo->get_section_info_all());
@@ -615,8 +638,10 @@ public function test_mass_duplicate_modules_to_course(): void {
$duplicatedmoduleids[] = $targetcoursemodinfo->get_sections()[3][1];
// To check if duplication has worked we just compare the names of the modules.
for ($i = 0; $i < count($duplicatedmoduleids); $i++) {
- $this->assertEquals($targetcoursemodinfo->get_cm($duplicatedmoduleids[$i])->name,
- $sourcecoursemodinfo->get_cm($selectedmoduleids[$i])->name);
+ $this->assertEquals(
+ $targetcoursemodinfo->get_cm($duplicatedmoduleids[$i])->name,
+ $sourcecoursemodinfo->get_cm($selectedmoduleids[$i])->name
+ );
}
// Let's duplicate to a specific existing section.
@@ -629,8 +654,10 @@ public function test_mass_duplicate_modules_to_course(): void {
// To check if duplication has worked we just compare the names of the modules.
for ($i = 0; $i < count($selectedmoduleids); $i++) {
// Now all duplicated modules should be in section 2.
- $this->assertEquals($targetcoursemodinfo->get_cm($targetcoursemodinfo->get_sections()[2][$i])->name,
- $sourcecoursemodinfo->get_cm($selectedmoduleids[$i])->name);
+ $this->assertEquals(
+ $targetcoursemodinfo->get_cm($targetcoursemodinfo->get_sections()[2][$i])->name,
+ $sourcecoursemodinfo->get_cm($selectedmoduleids[$i])->name
+ );
}
// Let's duplicate to a sectionnum that does not exist by creating a new section at the end of the target course.
@@ -643,8 +670,10 @@ public function test_mass_duplicate_modules_to_course(): void {
// To check if duplication has worked we just compare the names of the modules.
for ($i = 0; $i < count($selectedmoduleids); $i++) {
// Now all duplicated modules should be in section 4.
- $this->assertEquals($targetcoursemodinfo->get_cm($targetcoursemodinfo->get_sections()[4][$i])->name,
- $sourcecoursemodinfo->get_cm($selectedmoduleids[$i])->name);
+ $this->assertEquals(
+ $targetcoursemodinfo->get_cm($targetcoursemodinfo->get_sections()[4][$i])->name,
+ $sourcecoursemodinfo->get_cm($selectedmoduleids[$i])->name
+ );
}
// Test if some of the activities are broken, but still complete the job.
@@ -667,7 +696,7 @@ public function test_mass_duplicate_modules_to_course(): void {
$sink->close();
$targetcoursemodinfo = get_fast_modinfo($targetcourseid);
$this->assertCount(count($coursemodules) - $numberoferror, $targetcoursemodinfo->get_cms());
- $failedevents = array_filter($events, function($event) {
+ $failedevents = array_filter($events, function ($event) {
return ($event instanceof \block_massaction\event\course_modules_duplicated_failed);
});
$this->assertCount($numberoferror, $failedevents);
@@ -688,8 +717,13 @@ private function setup_target_course_for_duplicating(int $numsections = 5): int
$editingteacherrole = $DB->get_record('role', ['shortname' => 'editingteacher']);
$this->getDataGenerator()->enrol_user($this->teacher->id, $targetcourseid, $editingteacherrole->id);
// The teacher in the target course should have the necessary capability to restore modules.
- $this->assertTrue(has_capability('moodle/restore:restoretargetimport', \context_course::instance($targetcourseid),
- $this->teacher->id));
+ $this->assertTrue(
+ has_capability(
+ 'moodle/restore:restoretargetimport',
+ \context_course::instance($targetcourseid),
+ $this->teacher->id
+ )
+ );
return $targetcourseid;
}
@@ -711,7 +745,7 @@ public function test_mass_adjust_indentation(): void {
$selectedmoduleids[] = get_fast_modinfo($this->course->id)->get_sections()[2][1];
$selectedmoduleids[] = get_fast_modinfo($this->course->id)->get_sections()[3][2];
- $selectedmodules = array_filter($this->get_test_course_modules(), function($module) use ($selectedmoduleids) {
+ $selectedmodules = array_filter($this->get_test_course_modules(), function ($module) use ($selectedmoduleids) {
return in_array($module->id, $selectedmoduleids);
});
@@ -722,7 +756,7 @@ public function test_mass_adjust_indentation(): void {
// Negative tests: Method should only work if parameter 'amount' equals '1' oder '-1'.
// In all other cases method should do nothing.
block_massaction\actions::adjust_indentation($selectedmodules, 0);
- $selectedmodules = array_filter($this->get_test_course_modules(), function($module) use ($selectedmoduleids) {
+ $selectedmodules = array_filter($this->get_test_course_modules(), function ($module) use ($selectedmoduleids) {
return in_array($module->id, $selectedmoduleids);
});
@@ -730,14 +764,14 @@ public function test_mass_adjust_indentation(): void {
$this->assertEquals(0, $module->indent);
}
block_massaction\actions::adjust_indentation($selectedmodules, -2);
- $selectedmodules = array_filter($this->get_test_course_modules(), function($module) use ($selectedmoduleids) {
+ $selectedmodules = array_filter($this->get_test_course_modules(), function ($module) use ($selectedmoduleids) {
return in_array($module->id, $selectedmoduleids);
});
foreach ($selectedmodules as $module) {
$this->assertEquals(0, $module->indent);
}
block_massaction\actions::adjust_indentation($selectedmodules, 2);
- $selectedmodules = array_filter($this->get_test_course_modules(), function($module) use ($selectedmoduleids) {
+ $selectedmodules = array_filter($this->get_test_course_modules(), function ($module) use ($selectedmoduleids) {
return in_array($module->id, $selectedmoduleids);
});
foreach ($selectedmodules as $module) {
@@ -746,7 +780,7 @@ public function test_mass_adjust_indentation(): void {
// Now indent to the right.
block_massaction\actions::adjust_indentation($selectedmodules, 1);
- $selectedmodules = array_filter($this->get_test_course_modules(), function($module) use ($selectedmoduleids) {
+ $selectedmodules = array_filter($this->get_test_course_modules(), function ($module) use ($selectedmoduleids) {
return in_array($module->id, $selectedmoduleids);
});
foreach ($selectedmodules as $module) {
@@ -757,7 +791,7 @@ public function test_mass_adjust_indentation(): void {
for ($i = 0; $i < 15; $i++) {
block_massaction\actions::adjust_indentation($selectedmodules, 1);
}
- $selectedmodules = array_filter($this->get_test_course_modules(), function($module) use ($selectedmoduleids) {
+ $selectedmodules = array_filter($this->get_test_course_modules(), function ($module) use ($selectedmoduleids) {
return in_array($module->id, $selectedmoduleids);
});
foreach ($selectedmodules as $module) {
@@ -765,7 +799,7 @@ public function test_mass_adjust_indentation(): void {
}
// Indenting another time to the right now should do nothing.
block_massaction\actions::adjust_indentation($selectedmodules, 1);
- $selectedmodules = array_filter($this->get_test_course_modules(), function($module) use ($selectedmoduleids) {
+ $selectedmodules = array_filter($this->get_test_course_modules(), function ($module) use ($selectedmoduleids) {
return in_array($module->id, $selectedmoduleids);
});
foreach ($selectedmodules as $module) {
@@ -776,7 +810,7 @@ public function test_mass_adjust_indentation(): void {
for ($i = 0; $i < 16; $i++) {
block_massaction\actions::adjust_indentation($selectedmodules, -1);
}
- $selectedmodules = array_filter($this->get_test_course_modules(), function($module) use ($selectedmoduleids) {
+ $selectedmodules = array_filter($this->get_test_course_modules(), function ($module) use ($selectedmoduleids) {
return in_array($module->id, $selectedmoduleids);
});
foreach ($selectedmodules as $module) {
@@ -784,7 +818,7 @@ public function test_mass_adjust_indentation(): void {
}
// Indenting another time to the left now should do nothing.
block_massaction\actions::adjust_indentation($selectedmodules, -1);
- $selectedmodules = array_filter($this->get_test_course_modules(), function($module) use ($selectedmoduleids) {
+ $selectedmodules = array_filter($this->get_test_course_modules(), function ($module) use ($selectedmoduleids) {
return in_array($module->id, $selectedmoduleids);
});
foreach ($selectedmodules as $module) {
@@ -817,7 +851,7 @@ public function test_mass_send_content_changed_notification(): void {
course_module_updated::create_from_cm(get_coursemodule_from_id(false, $hiddenmoduleid))->trigger();
}
- $selectedmodules = array_filter($this->get_test_course_modules(), function($module) use ($selectedmoduleids) {
+ $selectedmodules = array_filter($this->get_test_course_modules(), function ($module) use ($selectedmoduleids) {
return in_array($module->id, $selectedmoduleids);
});
@@ -853,14 +887,22 @@ private function shuffle_modules(): void {
// Reason: We want to see if the order in the section is preserved which usually is different from the module ids.
// The method to be tested should follow the sections order. To be able to see the correct effect we have to ensure that
// the order of moduleids isn't the same as the order in the section.
- moveto_module(get_fast_modinfo($this->course->id)->get_cm(get_fast_modinfo($this->course->id)->get_sections()[1][0]),
- get_fast_modinfo($this->course->id)->get_section_info(1));
- moveto_module(get_fast_modinfo($this->course->id)->get_cm(get_fast_modinfo($this->course->id)->get_sections()[1][3]),
- get_fast_modinfo($this->course->id)->get_section_info(1));
- moveto_module(get_fast_modinfo($this->course->id)->get_cm(get_fast_modinfo($this->course->id)->get_sections()[3][0]),
- get_fast_modinfo($this->course->id)->get_section_info(3));
- moveto_module(get_fast_modinfo($this->course->id)->get_cm(get_fast_modinfo($this->course->id)->get_sections()[3][3]),
- get_fast_modinfo($this->course->id)->get_section_info(3));
+ moveto_module(
+ get_fast_modinfo($this->course->id)->get_cm(get_fast_modinfo($this->course->id)->get_sections()[1][0]),
+ get_fast_modinfo($this->course->id)->get_section_info(1)
+ );
+ moveto_module(
+ get_fast_modinfo($this->course->id)->get_cm(get_fast_modinfo($this->course->id)->get_sections()[1][3]),
+ get_fast_modinfo($this->course->id)->get_section_info(1)
+ );
+ moveto_module(
+ get_fast_modinfo($this->course->id)->get_cm(get_fast_modinfo($this->course->id)->get_sections()[3][0]),
+ get_fast_modinfo($this->course->id)->get_section_info(3)
+ );
+ moveto_module(
+ get_fast_modinfo($this->course->id)->get_cm(get_fast_modinfo($this->course->id)->get_sections()[3][3]),
+ get_fast_modinfo($this->course->id)->get_section_info(3)
+ );
}
/**
@@ -873,7 +915,7 @@ public function test_duplicate_to_course_with_filter_sections_different_course_h
$this->resetAfterTest();
// Callback for filter_sections_different_course hook.
- $testcallback = function(filter_sections_different_course $hook) {
+ $testcallback = function (filter_sections_different_course $hook) {
foreach ($hook->get_sectionnums() as $sectionnum) {
// Restrict section 3 onward.
if ($sectionnum >= 3) {
@@ -902,9 +944,12 @@ public function test_duplicate_to_course_with_filter_sections_different_course_h
$selectedmoduleids[] = $sourcecoursemodinfo->get_sections()[3][0];
$selectedmoduleids[] = $sourcecoursemodinfo->get_sections()[3][2];
- $selectedmodules = array_filter($this->get_test_course_modules(), function($module) use ($selectedmoduleids) {
- return in_array($module->id, $selectedmoduleids);
- });
+ $selectedmodules = array_filter(
+ $this->get_test_course_modules(),
+ function ($module) use ($selectedmoduleids) {
+ return in_array($module->id, $selectedmoduleids);
+ }
+ );
// Target course.
$targetcourseid = $this->setup_target_course_for_duplicating(3);