diff --git a/backup/moodle2/backup_format_grid_plugin.class.php b/backup/moodle2/backup_format_grid_plugin.class.php index 7feafec1..a06a1007 100644 --- a/backup/moodle2/backup_format_grid_plugin.class.php +++ b/backup/moodle2/backup_format_grid_plugin.class.php @@ -54,13 +54,13 @@ protected function define_section_plugin_structure() { // Create one standard named plugin element (the visible container). // The sectionid and courseid not required as populated on restore. $recomendedname = $this->get_recommended_name(); - $section = new backup_nested_element($recomendedname, array('sectionid'), array('image', 'contenthash')); + $section = new backup_nested_element($recomendedname, ['sectionid'], ['image', 'contenthash']); // Connect the visible container ASAP. $plugin->add_child($section); // Set source to populate the data. - $section->set_source_table('format_grid_image', array('sectionid' => backup::VAR_SECTIONID)); + $section->set_source_table('format_grid_image', ['sectionid' => backup::VAR_SECTIONID]); $section->annotate_files('format_grid', 'sectionimage', 'sectionid'); return $plugin; diff --git a/backup/moodle2/restore_format_grid_plugin.class.php b/backup/moodle2/restore_format_grid_plugin.class.php index 3d31ecda..e91013df 100644 --- a/backup/moodle2/restore_format_grid_plugin.class.php +++ b/backup/moodle2/restore_format_grid_plugin.class.php @@ -54,7 +54,7 @@ protected function define_course_plugin_structure() { $this->originalnumsections = (int)$maxsection; } - $paths = array(); + $paths = []; // Add own format stuff. $elename = 'grid'; // This defines the postfix of 'process_*' below. @@ -80,14 +80,14 @@ public function process_grid($data) { $courseid = $this->task->get_courseid(); /* We only process this information if the course we are restoring to has 'grid' format (target format can change depending of restore options). */ - $format = $DB->get_field('course', 'format', array('id' => $courseid)); + $format = $DB->get_field('course', 'format', ['id' => $courseid]); if ($format !== 'grid') { return; } $data->courseid = $courseid; - if (!($course = $DB->get_record('course', array('id' => $data->courseid)))) { + if (!($course = $DB->get_record('course', ['id' => $data->courseid]))) { throw new \moodle_exception('invalidcourseid', 'format_grid', '', get_string('invalidcourseid', 'error')); } // From /course/view.php. @@ -107,7 +107,7 @@ public function after_restore_course() { /* We only process this information if the course we are restoring to has 'grid' format (target format can change depending of restore options). */ - $format = $DB->get_field('course', 'format', array('id' => $courseid)); + $format = $DB->get_field('course', 'format', ['id' => $courseid]); if ($format !== 'grid') { return; } @@ -123,7 +123,7 @@ public function after_restore_course() { if (!$file->is_directory()) { $filename = $file->get_filename(); $filesectionid = $file->get_itemid(); - $gridimage = $DB->get_record('format_grid_image', array('sectionid' => $filesectionid), 'image'); + $gridimage = $DB->get_record('format_grid_image', ['sectionid' => $filesectionid], 'image'); if (($gridimage) && ($gridimage->image == $filename)) { // Ensure the correct file. $filerecord = new stdClass(); $filerecord->contextid = $coursecontext->id; @@ -134,7 +134,7 @@ public function after_restore_course() { $newfile = $fs->create_file_from_storedfile($filerecord, $file); if ($newfile) { $DB->set_field('format_grid_image', 'contenthash', $newfile->get_contenthash(), - array('sectionid' => $filesectionid)); + ['sectionid' => $filesectionid]); } } } @@ -179,7 +179,7 @@ public function after_restore_course() { */ protected function define_section_plugin_structure() { - $paths = array(); + $paths = []; // Add own format stuff. $elepath = $this->get_pathfor('/'); // Note: $this->get_recommended_name() gets! -> section/the name. @@ -220,7 +220,7 @@ public function process_gridsection($data) { $existinggridimage = false; if (($target == backup::TARGET_CURRENT_ADDING) || ($target == backup::TARGET_EXISTING_ADDING)) { - $existinggridimage = $DB->get_record('format_grid_image', array('sectionid' => $newsectionid), 'image'); + $existinggridimage = $DB->get_record('format_grid_image', ['sectionid' => $newsectionid], 'image'); } if (!$existinggridimage) { // No image, so add the one from the backup file. diff --git a/classes/admin_setting_information.php b/classes/admin_setting_information.php index f759fb6e..3b2e5ca8 100644 --- a/classes/admin_setting_information.php +++ b/classes/admin_setting_information.php @@ -100,19 +100,19 @@ public function output_html($data, $query='') { } $classes[] = 'fa fa-heart'; - $attributes = array(); + $attributes = []; $attributes['aria-hidden'] = 'true'; $attributes['class'] = 'fa fa-heart'; $attributes['title'] = get_string('love', 'format_grid'); - $content = \html_writer::tag('span', $attributes['title'], array('class' => 'sr-only')); + $content = \html_writer::tag('span', $attributes['title'], ['class' => 'sr-only']); $content = \html_writer::tag('span', $content, $attributes); $context['versioninfo'] = get_string('versioninfo', 'format_grid', - array( + [ 'moodle' => $CFG->release, 'release' => $plugininfo->release, 'version' => $plugininfo->version, - 'love' => $content - ) + 'love' => $content, + ] ); if (!empty($plugininfo->maturity)) { diff --git a/classes/observer.php b/classes/observer.php index 46838a04..5d058cee 100644 --- a/classes/observer.php +++ b/classes/observer.php @@ -55,7 +55,7 @@ public static function course_content_deleted(\core\event\course_content_deleted */ public static function course_restored(\core\event\course_restored $event) { global $DB; - $format = $DB->get_field('course', 'format', array('id' => $event->objectid)); + $format = $DB->get_field('course', 'format', ['id' => $event->objectid]); // If not in the grid format, then don't need the images etc. if ($format != 'grid') { // Then delete the images. diff --git a/classes/output/courseformat/content.php b/classes/output/courseformat/content.php index e4987dc5..fb1dfee0 100644 --- a/classes/output/courseformat/content.php +++ b/classes/output/courseformat/content.php @@ -39,9 +39,9 @@ */ class content extends content_base { - private $sectioncompletionpercentage = array(); - private $sectioncompletionmarkup = array(); - private $sectioncompletioncalculated = array(); + private $sectioncompletionpercentage = []; + private $sectioncompletionmarkup = []; + private $sectioncompletioncalculated = []; /** * @var bool Grid format does not add section after each topic. @@ -106,11 +106,11 @@ public function export_for_template(\renderer_base $output) { $data->hasnavigation = true; $data->singlesection = array_shift($data->sections); $data->sectionreturn = $singlesection; - $data->maincoursepage = new \moodle_url('/course/view.php', array('id' => $course->id)); + $data->maincoursepage = new \moodle_url('/course/view.php', ['id' => $course->id]); } else { $coursesettings = $format->get_settings(); $toolbox = \format_grid\toolbox::get_instance(); - $coursesectionimages = $DB->get_records('format_grid_image', array('courseid' => $course->id)); + $coursesectionimages = $DB->get_records('format_grid_image', ['courseid' => $course->id]); if (!empty($coursesectionimages)) { $fs = get_file_storage(); $coursecontext = \context_course::instance($course->id); @@ -128,8 +128,8 @@ public function export_for_template(\renderer_base $output) { $data->popup = false; if ((!empty($coursesettings['popup'])) && ($coursesettings['popup'] == 2)) { $data->popup = true; - $data->popupsections = array(); - $potentialpopupsections = array(); + $data->popupsections = []; + $potentialpopupsections = []; foreach ($sections as $section) { $potentialpopupsections[$section->id] = $section; } @@ -137,20 +137,20 @@ public function export_for_template(\renderer_base $output) { } // Suitable array. - $sectionimages = array(); + $sectionimages = []; foreach ($coursesectionimages as $coursesectionimage) { $sectionimages[$coursesectionimage->sectionid] = $coursesectionimage; } // Now iterate over the sections. - $data->gridsections = array(); + $data->gridsections = []; $sectionsforgrid = $this->get_grid_sections($output, $coursesettings); $displayediswebp = (get_config('format_grid', 'defaultdisplayedimagefiletype') == 2); $completionshown = false; $headerimages = false; if ($editing) { - $datasectionmap = array(); + $datasectionmap = []; foreach ($data->sections as $datasectionkey => $datasection) { $datasectionmap[$datasection->id] = $datasectionkey; } @@ -187,7 +187,7 @@ public function export_for_template(\renderer_base $output) { // Section link. $sectionimages[$section->id]->sectionurl = new \moodle_url( '/course/view.php', - array('id' => $course->id, 'section' => $section->num) + ['id' => $course->id, 'section' => $section->num] ); $sectionimages[$section->id]->sectionurl = $sectionimages[$section->id]->sectionurl->out(false); diff --git a/classes/output/courseformat/content/section/controlmenu.php b/classes/output/courseformat/content/section/controlmenu.php index a315e36c..caa0f78a 100644 --- a/classes/output/courseformat/content/section/controlmenu.php +++ b/classes/output/courseformat/content/section/controlmenu.php @@ -84,7 +84,7 @@ public function section_control_items() { 'pixattr' => ['class' => ''], 'attr' => [ 'class' => 'editing_highlight', - 'data-action' => 'removemarker' + 'data-action' => 'removemarker', ], ]; } else { @@ -97,7 +97,7 @@ public function section_control_items() { 'pixattr' => ['class' => ''], 'attr' => [ 'class' => 'editing_highlight', - 'data-action' => 'setmarker' + 'data-action' => 'setmarker', ], ]; } diff --git a/classes/output/courseformat/content/section/summary.php b/classes/output/courseformat/content/section/summary.php index 0108ba16..048cb381 100644 --- a/classes/output/courseformat/content/section/summary.php +++ b/classes/output/courseformat/content/section/summary.php @@ -111,7 +111,7 @@ protected function singlepagesummaryimage($summary, $output): string { $sectionid = $this->thesection->id; $coursesectionimage = $DB->get_record( 'format_grid_image', - array('courseid' => $courseid, 'sectionid' => $sectionid) + ['courseid' => $courseid, 'sectionid' => $sectionid] ); if (!empty($coursesectionimage)) { $fs = get_file_storage(); diff --git a/classes/toolbox.php b/classes/toolbox.php index 1e9bf95e..fcc0e607 100644 --- a/classes/toolbox.php +++ b/classes/toolbox.php @@ -40,11 +40,11 @@ class toolbox { protected static $instance = null; // Width constants - 128, 192, 210, 256, 320, 384, 448, 512, 576, 640, 704 and 768:... - private static $imagecontainerwidths = array(128 => '128', 192 => '192', 210 => '210', 256 => '256', 320 => '320', - 384 => '384', 448 => '448', 512 => '512', 576 => '576', 640 => '640', 704 => '704', 768 => '768'); + private static $imagecontainerwidths = [128 => '128', 192 => '192', 210 => '210', 256 => '256', 320 => '320', + 384 => '384', 448 => '448', 512 => '512', 576 => '576', 640 => '640', 704 => '704', 768 => '768', ]; // Ratio constants - 3-2, 3-1, 3-3, 2-3, 1-3, 4-3 and 3-4:... - private static $imagecontainerratios = array( - 1 => '3-2', 2 => '3-1', 3 => '3-3', 4 => '2-3', 5 => '1-3', 6 => '4-3', 7 => '3-4'); + private static $imagecontainerratios = [ + 1 => '3-2', 2 => '3-1', 3 => '3-3', 4 => '2-3', 5 => '1-3', 6 => '4-3', 7 => '3-4', ]; /** * This is a lonely object. @@ -221,12 +221,12 @@ public function setup_displayed_image($sectionimage, $sectionfile, $courseid, $s } } - $debugdata = array( + $debugdata = [ 'id' => $sectionfile->get_id(), 'itemid' => $sectionfile->get_itemid(), 'filename' => $filename, - 'sectionid' => $sectionid - ); + 'sectionid' => $sectionid, + ]; $data = self::generate_image($tmpfilepath, $displayedimageinfo['width'], $displayedimageinfo['height'], $crop, $newmime, $debugdata); if (!empty($data)) { @@ -242,7 +242,7 @@ public function setup_displayed_image($sectionimage, $sectionfile, $courseid, $s } $created = time(); - $displayedimagefilerecord = array( + $displayedimagefilerecord = [ 'contextid' => $coursecontext->id, 'component' => 'format_grid', 'filearea' => 'displayedsectionimage', @@ -254,7 +254,8 @@ public function setup_displayed_image($sectionimage, $sectionfile, $courseid, $s 'license' => $sectionfile->get_license(), 'timecreated' => $created, 'timemodified' => $created, - 'mimetype' => $mime); + 'mimetype' => $mime, + ]; if ($isdisplayedwebponly) { // Displayed WebP image from non-WebP original. // Displayed image is a webp image from the original, so change a few things. @@ -269,7 +270,7 @@ public function setup_displayed_image($sectionimage, $sectionfile, $courseid, $s unlink($tmpfilepath); $DB->set_field('format_grid_image', 'displayedimagestate', $sectionimage->displayedimagestate, - array('sectionid' => $sectionid)); + ['sectionid' => $sectionid]); if ($sectionimage->displayedimagestate == -1) { throw new \moodle_exception('cannotconvertuploadedimagetodisplayedimage', 'format_grid', '', get_string('cannotconvertuploadedimagetodisplayedimage', 'format_grid', @@ -290,8 +291,8 @@ public function setup_displayed_image($sectionimage, $sectionfile, $courseid, $s * @return array with the key => value of 'height' and 'width' for the container. */ public function get_displayed_image_container_properties($settings) { - return array('height' => self::calculate_height($settings['imagecontainerwidth'], $settings['imagecontainerratio']), - 'width' => $settings['imagecontainerwidth']); + return ['height' => self::calculate_height($settings['imagecontainerwidth'], $settings['imagecontainerratio']), + 'width' => $settings['imagecontainerwidth'], ]; } /** @@ -401,9 +402,9 @@ private static function generate_image($filepath, $requestedwidth, $requestedhei $original = imagecreatefromstring(file_get_contents($filepath)); // Need to alter / check for webp support. - $imageargs = array( - 1 => null // File. - ); + $imageargs = [ + 1 => null, // File. + ]; switch ($mime) { case 'image/png': if (function_exists('imagepng')) { @@ -607,7 +608,7 @@ private static function update_the_displayed_images($courseid = null) { global $DB; if (!empty($courseid)) { - $coursesectionimages = $DB->get_records('format_grid_image', array('courseid' => $courseid)); + $coursesectionimages = $DB->get_records('format_grid_image', ['courseid' => $courseid]); } else { $coursesectionimages = $DB->get_records('format_grid_image'); } @@ -681,7 +682,7 @@ public static function delete_images($courseid) { $displayedimage->delete(); } - $DB->delete_records("format_grid_image", array('courseid' => $courseid)); + $DB->delete_records("format_grid_image", ['courseid' => $courseid]); } /** @@ -693,7 +694,7 @@ public static function delete_images($courseid) { public static function delete_image($sectionid, $courseid) { global $DB; - $coursesectionimage = $DB->get_record('format_grid_image', array('courseid' => $courseid, 'sectionid' => $sectionid)); + $coursesectionimage = $DB->get_record('format_grid_image', ['courseid' => $courseid, 'sectionid' => $sectionid]); if (!empty($coursesectionimage)) { $fs = get_file_storage(); @@ -732,7 +733,7 @@ public static function delete_image($sectionid, $courseid) { get_string('cannotgetmanagesectionimagelock', 'format_grid') ); } - $DB->delete_records("format_grid_image", array('courseid' => $courseid, 'sectionid' => $sectionid)); + $DB->delete_records("format_grid_image", ['courseid' => $courseid, 'sectionid' => $sectionid]); } } } diff --git a/db/events.php b/db/events.php index d120fb59..aab0061d 100644 --- a/db/events.php +++ b/db/events.php @@ -30,14 +30,13 @@ defined('MOODLE_INTERNAL') || die(); // List of observers. -$observers = array( - - array( +$observers = [ + [ 'eventname' => '\core\event\course_content_deleted', 'callback' => 'format_grid_observer::course_content_deleted', - ), - array( + ], + [ 'eventname' => '\core\event\course_restored', 'callback' => 'format_grid_observer::course_restored', - ) -); + ], +]; diff --git a/db/upgrade.php b/db/upgrade.php index 38d21838..14e5ed21 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -72,7 +72,7 @@ function xmldb_format_grid_upgrade($oldversion = 0) { // Upgrade from old images. $oldimages = $DB->get_records('format_grid_icon'); if (!empty($oldimages)) { - $newimages = array(); + $newimages = []; foreach ($oldimages as $oldimage) { if (!empty($oldimage->image)) { try { @@ -90,7 +90,7 @@ function xmldb_format_grid_upgrade($oldversion = 0) { // Contenthash later! $DB->insert_record('format_grid_image', $newimagecontainer, true); if (!array_key_exists($newimagecontainer->courseid, $newimages)) { - $newimages[$newimagecontainer->courseid] = array(); + $newimages[$newimagecontainer->courseid] = []; } $newimages[$newimagecontainer->courseid][$newimagecontainer->sectionid] = $newimagecontainer; } @@ -133,7 +133,7 @@ function xmldb_format_grid_upgrade($oldversion = 0) { } if ($thefile !== false) { $DB->set_field('format_grid_image', 'contenthash', - $thefile->get_contenthash(), array('sectionid' => $filesectionid)); + $thefile->get_contenthash(), ['sectionid' => $filesectionid]); // Don't delete the section file in case used in the summary. } } @@ -169,15 +169,15 @@ function xmldb_format_grid_upgrade($oldversion = 0) { if ($oldversion < 2022112605) { $records = $DB->get_records('course_format_options', - array( + [ 'format' => 'grid', - 'name' => 'numsections' - ), '', 'id' + 'name' => 'numsections', + ], '', 'id' ); $records = array_keys($records); foreach ($records as $id) { - $DB->set_field('course_format_options', 'name', 'gnumsections', array('id' => $id)); + $DB->set_field('course_format_options', 'name', 'gnumsections', ['id' => $id]); } // Grid savepoint reached. diff --git a/lib.php b/lib.php index 19b1f214..caeb7e2e 100755 --- a/lib.php +++ b/lib.php @@ -169,7 +169,7 @@ public function page_title(): string { * 'sr' (int) used by multipage formats to specify to which section to return * @return null|moodle_url */ - public function get_view_url($section, $options = array()) { + public function get_view_url($section, $options = []) { global $CFG; $course = $this->get_course(); $url = new moodle_url('/course/view.php', ['id' => $course->id]); @@ -312,162 +312,162 @@ public function course_format_options($foreditform = false) { } else { // Existing course that may not have 'numsections' - see get_last_section(). global $DB; $defaultnumsections = $DB->get_field_sql('SELECT max(section) from {course_sections} - WHERE course = ?', array($courseid)); + WHERE course = ?', [$courseid]); } - $courseformatoptions = array( - 'gnumsections' => array( + $courseformatoptions = [ + 'gnumsections' => [ 'default' => $defaultnumsections, 'type' => PARAM_INT, - ), - 'hiddensections' => array( + ], + 'hiddensections' => [ 'default' => $courseconfig->hiddensections, - 'type' => PARAM_INT - ), - 'popup' => array( + 'type' => PARAM_INT, + ], + 'popup' => [ 'default' => 0, - 'type' => PARAM_INT - ), - 'imagecontainerwidth' => array( + 'type' => PARAM_INT, + ], + 'imagecontainerwidth' => [ 'default' => 0, - 'type' => PARAM_INT - ), - 'imagecontainerratio' => array( + 'type' => PARAM_INT, + ], + 'imagecontainerratio' => [ 'default' => '-', - 'type' => PARAM_ALPHANUMEXT - ), - 'imageresizemethod' => array( + 'type' => PARAM_ALPHANUMEXT, + ], + 'imageresizemethod' => [ 'default' => 0, - 'type' => PARAM_INT - ), - 'showcompletion' => array( + 'type' => PARAM_INT, + ], + 'showcompletion' => [ 'default' => 0, - 'type' => PARAM_INT - ), - 'singlepagesummaryimage' => array( + 'type' => PARAM_INT, + ], + 'singlepagesummaryimage' => [ 'default' => 0, - 'type' => PARAM_INT - ) - ); + 'type' => PARAM_INT, + ], + ]; } if ($foreditform && !isset($courseformatoptions['gnumsections']['label'])) { if (is_null($courseconfig)) { $courseconfig = get_config('moodlecourse'); } - $sectionmenu = array(); + $sectionmenu = []; for ($i = 0; $i <= $courseconfig->maxsections; $i++) { $sectionmenu[$i] = "$i"; } - $courseformatoptionsedit = array( - 'gnumsections' => array( + $courseformatoptionsedit = [ + 'gnumsections' => [ 'label' => new lang_string('numbersections', 'format_grid'), 'element_type' => 'select', - 'element_attributes' => array($sectionmenu), - ), - 'hiddensections' => array( + 'element_attributes' => [$sectionmenu], + ], + 'hiddensections' => [ 'label' => new lang_string('hiddensections'), 'help' => 'hiddensections', 'help_component' => 'moodle', 'element_type' => 'select', - 'element_attributes' => array( - array( + 'element_attributes' => [ + [ 0 => new lang_string('hiddensectionscollapsed'), - 1 => new lang_string('hiddensectionsinvisible') - ) - ), - ) - ); + 1 => new lang_string('hiddensectionsinvisible'), + ], + ], + ], + ]; // TODO - Use capabilities? $popupvalues = $this->generate_default_entry( 'popup', 0, - array( + [ 1 => new lang_string('no'), - 2 => new lang_string('yes') - ) + 2 => new lang_string('yes'), + ], ); - $courseformatoptionsedit['popup'] = array( + $courseformatoptionsedit['popup'] = [ 'label' => new lang_string('popup', 'format_grid'), 'help' => 'popup', 'help_component' => 'format_grid', 'element_type' => 'select', - 'element_attributes' => array($popupvalues) - ); + 'element_attributes' => [$popupvalues], + ]; $imagecontainerwidthvalues = $this->generate_default_entry( 'imagecontainerwidth', 0, \format_grid\toolbox::get_image_container_widths() ); - $courseformatoptionsedit['imagecontainerwidth'] = array( + $courseformatoptionsedit['imagecontainerwidth'] = [ 'label' => new lang_string('imagecontainerwidth', 'format_grid'), 'help' => 'imagecontainerwidth', 'help_component' => 'format_grid', 'element_type' => 'select', - 'element_attributes' => array($imagecontainerwidthvalues) - ); + 'element_attributes' => [$imagecontainerwidthvalues], + ]; $imagecontainerratiovalues = $this->generate_default_entry( 'imagecontainerratio', '-', \format_grid\toolbox::get_image_container_ratios() ); - $courseformatoptionsedit['imagecontainerratio'] = array( + $courseformatoptionsedit['imagecontainerratio'] = [ 'label' => new lang_string('imagecontainerratio', 'format_grid'), 'help' => 'imagecontainerratio', 'help_component' => 'format_grid', 'element_type' => 'select', - 'element_attributes' => array($imagecontainerratiovalues) - ); + 'element_attributes' => [$imagecontainerratiovalues], + ]; $imageresizemethodvalues = $this->generate_default_entry( 'imageresizemethod', 0, - array( + [ 1 => new lang_string('scale', 'format_grid'), // Scale. - 2 => new lang_string('crop', 'format_grid') // Crop. - ) + 2 => new lang_string('crop', 'format_grid'), // Crop. + ], ); - $courseformatoptionsedit['imageresizemethod'] = array( + $courseformatoptionsedit['imageresizemethod'] = [ 'label' => new lang_string('imageresizemethod', 'format_grid'), 'help' => 'imageresizemethod', 'help_component' => 'format_grid', 'element_type' => 'select', - 'element_attributes' => array($imageresizemethodvalues) - ); + 'element_attributes' => [$imageresizemethodvalues], + ]; $showcompletionvalues = $this->generate_default_entry( 'showcompletion', 0, - array( + [ 1 => new lang_string('no'), - 2 => new lang_string('yes') - ) + 2 => new lang_string('yes'), + ], ); - $courseformatoptionsedit['showcompletion'] = array( + $courseformatoptionsedit['showcompletion'] = [ 'label' => new lang_string('showcompletion', 'format_grid'), 'help' => 'showcompletion', 'help_component' => 'format_grid', 'element_type' => 'select', - 'element_attributes' => array($showcompletionvalues) - ); + 'element_attributes' => [$showcompletionvalues], + ]; $singlepagesummaryimagevalues = $this->generate_default_entry( 'singlepagesummaryimage', 0, - array( + [ 1 => new lang_string('off', 'format_grid'), 2 => new lang_string('left', 'format_grid'), 3 => new lang_string('centre', 'format_grid'), - 4 => new lang_string('right', 'format_grid') - ) + 4 => new lang_string('right', 'format_grid'), + ], ); - $courseformatoptionsedit['singlepagesummaryimage'] = array( + $courseformatoptionsedit['singlepagesummaryimage'] = [ 'label' => new lang_string('singlepagesummaryimage', 'format_grid'), 'element_type' => 'select', - 'element_attributes' => array($singlepagesummaryimagevalues), + 'element_attributes' => [$singlepagesummaryimagevalues], 'help' => 'singlepagesummaryimage', - 'help_component' => 'format_grid' - ); + 'help_component' => 'format_grid', + ]; $courseformatoptions = array_merge_recursive($courseformatoptions, $courseformatoptionsedit); } @@ -485,7 +485,7 @@ public function course_format_options($foreditform = false) { */ private function generate_default_entry($settingname, $defaultindex, $values) { $defaultvalue = get_config('format_grid', 'default'.$settingname); - $defarray = array($defaultindex => new lang_string('default', 'format_grid', $values[$defaultvalue])); + $defarray = [$defaultindex => new lang_string('default', 'format_grid', $values[$defaultvalue])]; return array_replace($defarray, $values); } @@ -561,7 +561,7 @@ public function update_course_format_options($data, $oldcourse = null) { /* The previous format does not have the field 'numsections' and $data['gnumsections'] is not set, we fill it with the maximum section number from the DB. */ $maxsection = $DB->get_field_sql('SELECT max(section) from {course_sections} - WHERE course = ?', array($this->courseid)); + WHERE course = ?', [$this->courseid]); if ($maxsection) { // If there are no sections, or just default 0-section, 'gnumsections' will be set to default. $data['gnumsections'] = $maxsection; @@ -576,7 +576,7 @@ public function update_course_format_options($data, $oldcourse = null) { if ($changes && array_key_exists('gnumsections', $data)) { $numsections = (int)$data['gnumsections']; $maxsection = $DB->get_field_sql('SELECT max(section) from {course_sections} - WHERE course = ?', array($this->courseid)); + WHERE course = ?', [$this->courseid]); if ($numsections < $maxsection) { // The setting gnumsections has decreased, try to completely delete the orphaned sections (unless they are not empty). for ($sectionnum = $maxsection; $sectionnum > $numsections; $sectionnum--) { @@ -616,64 +616,64 @@ public function update_course_format_options($data, $oldcourse = null) { public function section_format_options($foreditform = false) { static $sectionformatoptions = false; if ($sectionformatoptions === false) { - $sectionformatoptions = array( - 'sectionimage_filemanager' => array( + $sectionformatoptions = [ + 'sectionimage_filemanager' => [ 'default' => '', - 'type' => PARAM_RAW - ), - 'sectionimagealttext' => array( + 'type' => PARAM_RAW, + ], + 'sectionimagealttext' => [ 'default' => '', - 'type' => PARAM_TEXT - ), - 'sectionbreak' => array( + 'type' => PARAM_TEXT, + ], + 'sectionbreak' => [ 'default' => 1, // No. - 'type' => PARAM_INT - ), - 'sectionbreakheading' => array( + 'type' => PARAM_INT, + ], + 'sectionbreakheading' => [ 'default' => '', - 'type' => PARAM_RAW - ) - ); + 'type' => PARAM_RAW, + ], + ]; } if ($foreditform && !isset($sectionformatoptions['sectionimage_filemanager']['label'])) { - $sectionformatoptionsedit = array( - 'sectionimage_filemanager' => array( + $sectionformatoptionsedit = [ + 'sectionimage_filemanager' => [ 'label' => new lang_string('sectionimage', 'format_grid'), 'help' => 'sectionimage', 'help_component' => 'format_grid', 'element_type' => 'sectionfilemanager', - 'element_attributes' => array( - array( + 'element_attributes' => [ + [ 'course' => $this->course, - 'sectionid' => optional_param('id', 0, PARAM_INT) - ) - ) - ), - 'sectionimagealttext' => array( + 'sectionid' => optional_param('id', 0, PARAM_INT), + ], + ], + ], + 'sectionimagealttext' => [ 'label' => new lang_string('sectionimagealttext', 'format_grid'), 'help' => 'sectionimagealttext', 'help_component' => 'format_grid', - 'element_type' => 'text' - ), - 'sectionbreak' => array( + 'element_type' => 'text', + ], + 'sectionbreak' => [ 'label' => new lang_string('sectionbreak', 'format_grid'), 'help' => 'sectionbreak', 'help_component' => 'format_grid', 'element_type' => 'select', - 'element_attributes' => array( - array( + 'element_attributes' => [ + [ 1 => new lang_string('no'), - 2 => new lang_string('yes') - ) - ), - ), - 'sectionbreakheading' => array( + 2 => new lang_string('yes'), + ], + ], + ], + 'sectionbreakheading' => [ 'label' => new lang_string('sectionbreakheading', 'format_grid'), 'help' => 'sectionbreakheading', 'help_component' => 'format_grid', - 'element_type' => 'textarea' - ) - ); + 'element_type' => 'textarea', + ], + ]; $sectionformatoptions = array_merge_recursive($sectionformatoptions, $sectionformatoptionsedit); } @@ -696,7 +696,7 @@ public function delete_section($section, $forcedeleteifnotempty = false) { } if (!is_object($section)) { global $DB; - $section = $DB->get_record('course_sections', array('course' => $this->get_courseid(), 'section' => $section), + $section = $DB->get_record('course_sections', ['course' => $this->get_courseid(), 'section' => $section], 'id,section,sequence,summary'); } if (!$section || !$section->section) { @@ -800,7 +800,7 @@ public function section_action($section, $action, $sr) { * @param int $numsections The number of sections. */ public function restore_gnumsections($numsections) { - $data = array('gnumsections' => $numsections); + $data = ['gnumsections' => $numsections]; $this->update_course_format_options($data); } @@ -808,7 +808,7 @@ public function restore_gnumsections($numsections) { * A section has been added. Should only be called from the state actions instance. */ public function section_added() { - $data = array('gnumsections' => $this->settings['gnumsections'] + 1); + $data = ['gnumsections' => $this->settings['gnumsections'] + 1]; $this->update_format_options($data); } @@ -816,7 +816,7 @@ public function section_added() { * A section has been deleted. Should only be called from the state actions instance. */ public function section_deleted() { - $data = array('gnumsections' => $this->settings['gnumsections'] - 1); + $data = ['gnumsections' => $this->settings['gnumsections'] - 1]; $this->update_format_options($data); } @@ -856,7 +856,7 @@ public static function update_displayed_images_callback() { * @param array $options additional options affecting the file serving * @return bool */ -function format_grid_pluginfile($course, $birecordorcm, $context, $filearea, $args, $forcedownload, array $options=array()) { +function format_grid_pluginfile($course, $birecordorcm, $context, $filearea, $args, $forcedownload, array $options=[]) { if ($context->contextlevel != CONTEXT_COURSE) { send_file_not_found(); } diff --git a/settings.php b/settings.php index 9428307d..bc1ddfc3 100644 --- a/settings.php +++ b/settings.php @@ -67,10 +67,10 @@ $title = get_string('defaultpopup', 'format_grid'); $description = get_string('defaultpopup_desc', 'format_grid'); $default = 1; - $choices = array( + $choices = [ 1 => new lang_string('no'), - 2 => new lang_string('yes') - ); + 2 => new lang_string('yes'), + ]; $page->add(new admin_setting_configselect($name, $title, $description, $default, $choices)); // Icon width. @@ -98,10 +98,10 @@ $title = get_string('defaultimageresizemethod', 'format_grid'); $description = get_string('defaultimageresizemethod_desc', 'format_grid'); $default = 1; // Scale. - $choices = array( + $choices = [ 1 => new lang_string('scale', 'format_grid'), - 2 => new lang_string('crop', 'format_grid') - ); + 2 => new lang_string('crop', 'format_grid'), + ]; $setting = new admin_setting_configselect($name, $title, $description, $default, $choices); $setting->set_updatedcallback('format_grid::update_displayed_images_callback'); $page->add($setting); @@ -111,10 +111,10 @@ $title = get_string('defaultdisplayedimagefiletype', 'format_grid'); $description = get_string('defaultdisplayedimagefiletype_desc', 'format_grid'); $default = 1; // Original. - $choices = array( + $choices = [ 1 => new lang_string('original', 'format_grid'), - 2 => new lang_string('webp', 'format_grid') - ); + 2 => new lang_string('webp', 'format_grid'), + ]; $setting = new admin_setting_configselect($name, $title, $description, $default, $choices); $setting->set_updatedcallback('format_grid::update_displayed_images_callback'); $page->add($setting); @@ -124,10 +124,10 @@ $title = get_string('defaultshowcompletion', 'format_grid'); $description = get_string('defaultshowcompletion_desc', 'format_grid'); $default = 1; - $choices = array( + $choices = [ 1 => new lang_string('no'), - 2 => new lang_string('yes') - ); + 2 => new lang_string('yes'), + ]; $page->add(new admin_setting_configselect($name, $title, $description, $default, $choices)); // Show the grid image in the section summary on a single page. @@ -135,12 +135,12 @@ $title = get_string('defaultsinglepagesummaryimage', 'format_grid'); $description = get_string('defaultsinglepagesummaryimage_desc', 'format_grid'); $default = 1; - $choices = array( + $choices = [ 1 => new lang_string('off', 'format_grid'), 2 => new lang_string('left', 'format_grid'), 3 => new lang_string('centre', 'format_grid'), - 4 => new lang_string('right', 'format_grid') - ); + 4 => new lang_string('right', 'format_grid'), + ]; $page->add(new admin_setting_configselect($name, $title, $description, $default, $choices)); } $ADMIN->add('format_grid', $page); diff --git a/version.php b/version.php index 0fdf7d4a..225962bc 100644 --- a/version.php +++ b/version.php @@ -35,7 +35,7 @@ $plugin->requires = 2022112800.00; // 4.1 (Build: 20221128). // Supported Moodle version. -$plugin->supported = array(401, 401); +$plugin->supported = [401, 401]; // Full name of the plugin. $plugin->component = 'format_grid';