From 9c0e2415843dff617eb8fbeea47313b3f921d68d Mon Sep 17 00:00:00 2001 From: Nithy1anand Date: Mon, 27 Nov 2023 11:41:52 +0530 Subject: [PATCH] Fixed the code checker issues. --- classes/course_importer.php | 2 +- classes/external.php | 10 ++-- classes/form/template_form.php | 6 +- classes/form/template_table_settings_form.php | 2 +- classes/observer.php | 8 +-- classes/output/course_template_list.php | 4 +- classes/output/import_course_list.php | 6 +- classes/template_table.php | 24 ++++---- db/access.php | 8 +-- db/caches.php | 8 +-- db/events.php | 8 +-- db/services.php | 8 +-- db/uninstall.php | 2 +- db/upgrade.php | 2 +- format.php | 2 +- freetemplates.php | 4 +- lib.php | 59 +++++++++---------- settings.php | 10 ++-- template.php | 17 +++--- templates.php | 6 +- tests/behat/behat_format_kickstart.php | 4 +- tests/format_kickstart_test.php | 40 +++++++------ version.php | 2 +- 23 files changed, 124 insertions(+), 118 deletions(-) diff --git a/classes/course_importer.php b/classes/course_importer.php index 05deb23..42fc07e 100644 --- a/classes/course_importer.php +++ b/classes/course_importer.php @@ -74,7 +74,7 @@ public static function import_from_template($templateid, $courseid) { self::import('template' . $templateid, $courseid); } else { - $course = (array) $DB->get_record('course', array('id' => $courseid)); + $course = (array) $DB->get_record('course', ['id' => $courseid]); $course['format'] = $template->format; // Get format opitions. $params['format'] = $template->format; diff --git a/classes/external.php b/classes/external.php index 0506645..5843950 100644 --- a/classes/external.php +++ b/classes/external.php @@ -26,7 +26,7 @@ defined('MOODLE_INTERNAL') || die(); -use \format_kickstart\course_importer; +use format_kickstart\course_importer; require_once($CFG->libdir.'/externallib.php'); @@ -42,10 +42,10 @@ class external extends \external_api { public static function import_template_parameters() { return new \external_function_parameters( - array( + [ 'templateid' => new \external_value(PARAM_INT, 'Kickstart Template id'), - 'courseid' => new \external_value(PARAM_INT, 'Course id') - ) + 'courseid' => new \external_value(PARAM_INT, 'Course id'), + ], ); } @@ -62,7 +62,7 @@ public static function import_template($templateid, $courseid) { $context = \context_course::instance($courseid); require_capability('format/kickstart:import_from_template', $context); $params = self::validate_parameters(self::import_template_parameters(), - array('templateid' => $templateid, 'courseid' => $courseid)); + ['templateid' => $templateid, 'courseid' => $courseid]); course_importer::import_from_template($templateid, $courseid); return true; } diff --git a/classes/form/template_form.php b/classes/form/template_form.php index 2e03e7f..be28d5c 100644 --- a/classes/form/template_form.php +++ b/classes/form/template_form.php @@ -57,7 +57,7 @@ public function definition() { $attributes = []; $checkformat = !empty($template) && isset($template['courseformat']) && $template['courseformat']; if ($checkformat) { - $attributes = array('disabled' => true); + $attributes = ['disabled' => true]; } $mform->addElement('text', 'title', get_string('title', 'format_kickstart'), $attributes); $mform->setType('title', PARAM_TEXT); @@ -77,7 +77,7 @@ public function definition() { 'subdirs' => 0, 'maxfiles' => 1, 'accepted_types' => ['.mbz'], - 'return_types' => FILE_INTERNAL | FILE_EXTERNAL + 'return_types' => FILE_INTERNAL | FILE_EXTERNAL, ]); $mform->addHelpButton('course_backup', 'course_backup', 'format_kickstart'); $mform->addRule('course_backup', get_string('required'), 'required'); @@ -108,7 +108,7 @@ public function definition() { } $mform->addElement('autocomplete', 'cohortids', get_string('cohorts', 'cohort'), $options, [ - 'multiple' => true + 'multiple' => true, ]); $mform->hideIf('cohortids', 'restrictcohort'); diff --git a/classes/form/template_table_settings_form.php b/classes/form/template_table_settings_form.php index 81ba1dc..98c7e37 100644 --- a/classes/form/template_table_settings_form.php +++ b/classes/form/template_table_settings_form.php @@ -51,7 +51,7 @@ public function definition() { -1 => get_string('all'), 25 => '25', 50 => '50', - 100 => '100' + 100 => '100', ]); $mform->setType('pagesize', PARAM_INT); $mform->setDefault('pagesize', 25); diff --git a/classes/observer.php b/classes/observer.php index b2e2734..a1a9fc2 100644 --- a/classes/observer.php +++ b/classes/observer.php @@ -45,20 +45,20 @@ public static function format_kickstart_changeconfig($event) { $format = substr($plugin, 7); if ($disable) { $removetemplates = $DB->get_records_menu('format_kickstart_template', - array('format' => $format, 'courseformat' => 1), '', 'id,id'); + ['format' => $format, 'courseformat' => 1], '', 'id,id'); if ($removetemplates) { $removetemplates = array_keys($removetemplates); $templates = array_diff($templates, $removetemplates); } - $DB->set_field('format_kickstart_template', 'visible', 0, array('format' => $format, 'courseformat' => 1)); + $DB->set_field('format_kickstart_template', 'visible', 0, ['format' => $format, 'courseformat' => 1]); } else { $addtemplates = $DB->get_records_menu('format_kickstart_template', - array('format' => $format, 'courseformat' => 1), '', 'id,id'); + ['format' => $format, 'courseformat' => 1], '', 'id,id'); if ($addtemplates) { $addtemplates = array_keys($addtemplates); $templates = array_merge($templates, $addtemplates); } - $DB->set_field('format_kickstart_template', 'visible', 1, array('format' => $format, 'courseformat' => 1)); + $DB->set_field('format_kickstart_template', 'visible', 1, ['format' => $format, 'courseformat' => 1]); } set_config('kickstart_templates', implode(',', $templates)); } diff --git a/classes/output/course_template_list.php b/classes/output/course_template_list.php index dd8a5d1..49e015a 100644 --- a/classes/output/course_template_list.php +++ b/classes/output/course_template_list.php @@ -148,7 +148,7 @@ public function get_templates() { $template->hashtags = implode(' ', $tags); $template->link = new \moodle_url('/course/format/kickstart/confirm.php', [ 'template_id' => $template->id, - 'course_id' => $COURSE->id + 'course_id' => $COURSE->id, ]); if (!$template->courseformat) { $templatecount++; @@ -198,7 +198,7 @@ public function export_for_template(renderer_base $output) { 'notemplates' => empty($templates), 'canmanage' => has_capability('format/kickstart:manage_templates', \context_system::instance()), 'createtemplateurl' => new \moodle_url('/course/format/kickstart/template.php', ['action' => 'create']), - 'managetemplateurl' => new \moodle_url('/course/format/kickstart/templates.php') + 'managetemplateurl' => new \moodle_url('/course/format/kickstart/templates.php'), ]; } diff --git a/classes/output/import_course_list.php b/classes/output/import_course_list.php index 037672b..0f3b956 100644 --- a/classes/output/import_course_list.php +++ b/classes/output/import_course_list.php @@ -69,12 +69,12 @@ public function export_for_template(renderer_base $output) { } $course->url = new \moodle_url('/course/view.php', ['id' => $course->id]); $course->fullname = format_string($course->fullname, true, [ - 'context' => \context_course::instance($course->id) + 'context' => \context_course::instance($course->id), ]); $course->importurl = new \moodle_url('/local/kickstart_pro/import.php', [ 'id' => $COURSE->id, 'importid' => $course->id, - 'target' => $target + 'target' => $target, ]); $courses[] = $course; } @@ -90,7 +90,7 @@ public function export_for_template(renderer_base $output) { 'searchlabel' => get_string('showing', 'format_kickstart', ['count' => $component->get_count()]), 'moreresults' => $component->has_more_results(), 'prourl' => 'https://bdecent.de/products/moodle-plugins/kickstart-course-wizard-pro/', - 'courseurl' => new \moodle_url('/course/view.php', ['id' => $COURSE->id]) + 'courseurl' => new \moodle_url('/course/view.php', ['id' => $COURSE->id]), ]; } } diff --git a/classes/template_table.php b/classes/template_table.php index b2d51cd..ab49801 100644 --- a/classes/template_table.php +++ b/classes/template_table.php @@ -148,14 +148,14 @@ public function col_status($data) { $status = ''; if ($data->status) { $status .= \html_writer::link($templateurl->out(false, - array('action' => 'disable', 'template' => $data->id)), - $OUTPUT->pix_icon('t/hide', get_string('disable'), 'moodle', array('class' => 'iconsmall')), - array('id' => "sort-template-up-action")). ''; + ['action' => 'disable', 'template' => $data->id]), + $OUTPUT->pix_icon('t/hide', get_string('disable'), 'moodle', ['class' => 'iconsmall']), + ['id' => "sort-template-up-action"]). ''; } else { $status .= \html_writer::link($templateurl->out(false, - array('action' => 'enable', 'template' => $data->id)), - $OUTPUT->pix_icon('t/show', get_string('enable'), 'moodle', array('class' => 'iconsmall')), - array('id' => "sort-template-up-action")). ''; + ['action' => 'enable', 'template' => $data->id]), + $OUTPUT->pix_icon('t/show', get_string('enable'), 'moodle', ['class' => 'iconsmall']), + ['id' => "sort-template-up-action"]). ''; } return $status; } @@ -173,21 +173,21 @@ public function col_updown($data) { $updown = ''; $strup = get_string('up'); $strdown = get_string('down'); - $spacer = $OUTPUT->pix_icon('spacer', '', 'moodle', array('class' => 'iconsmall')); + $spacer = $OUTPUT->pix_icon('spacer', '', 'moodle', ['class' => 'iconsmall']); if ($this->cnt) { $updown .= \html_writer::link($templateurl->out(false, - array('action' => 'up', 'template' => $data->id)), - $OUTPUT->pix_icon('t/up', $strup, 'moodle', array('class' => 'iconsmall')), - array('id' => "sort-template-up-action")). ''; + ['action' => 'up', 'template' => $data->id]), + $OUTPUT->pix_icon('t/up', $strup, 'moodle', ['class' => 'iconsmall']), + ['id' => "sort-template-up-action"]). ''; } else { $updown .= $spacer; } if ($this->cnt < ($this->totaltemplates - 1)) { $updown .= ' '. \html_writer::link($templateurl->out(false, - array('action' => 'down', 'template' => $data->id)), + ['action' => 'down', 'template' => $data->id]), $OUTPUT->pix_icon('t/down', $strdown, 'moodle', - array('class' => 'iconsmall')), array('id' => "sort-template-down-action")); + ['class' => 'iconsmall']), ['id' => "sort-template-down-action"]); } else { $updown .= $spacer; } diff --git a/db/access.php b/db/access.php index 23e594b..fa30ecf 100644 --- a/db/access.php +++ b/db/access.php @@ -30,7 +30,7 @@ 'contextlevel' => CONTEXT_SYSTEM, 'archetypes' => [ 'manager' => CAP_ALLOW, - ] + ], ], 'format/kickstart:import_from_template' => [ 'captype' => 'write', @@ -38,8 +38,8 @@ 'archetypes' => [ 'manager' => CAP_ALLOW, 'coursecreator' => CAP_ALLOW, - 'editingteacher' => CAP_ALLOW - ] - ] + 'editingteacher' => CAP_ALLOW, + ], + ], ]; diff --git a/db/caches.php b/db/caches.php index c50fa12..6096f23 100644 --- a/db/caches.php +++ b/db/caches.php @@ -24,8 +24,8 @@ defined('MOODLE_INTERNAL') || die(); -$definitions = array( - 'templates' => array( +$definitions = [ + 'templates' => [ 'mode' => cache_store::MODE_APPLICATION, - ), -); + ], +]; diff --git a/db/events.php b/db/events.php index 7d99e35..092dc0b 100644 --- a/db/events.php +++ b/db/events.php @@ -24,9 +24,9 @@ */ defined('MOODLE_INTERNAL') || die(); -$observers = array( - array( +$observers = [ + [ 'eventname' => 'core\event\config_log_created', 'callback' => '\format_kickstart\observer::format_kickstart_changeconfig', - ), -); + ], +]; diff --git a/db/services.php b/db/services.php index 8e519e2..7ae633e 100644 --- a/db/services.php +++ b/db/services.php @@ -24,8 +24,8 @@ defined('MOODLE_INTERNAL') || die(); -$functions = array( - 'format_kickstart_import_template' => array( +$functions = [ + 'format_kickstart_import_template' => [ 'classname' => 'format_kickstart\external', 'methodname' => 'import_template', 'description' => 'Import the template', @@ -33,5 +33,5 @@ 'capabilities' => 'format/kickstart:import_from_template', 'ajax' => true, 'loginrequired' => true, - ), -); + ], +]; diff --git a/db/uninstall.php b/db/uninstall.php index f362d59..3fae1f6 100644 --- a/db/uninstall.php +++ b/db/uninstall.php @@ -31,7 +31,7 @@ function xmldb_format_kickstart_uninstall() { $DB->delete_records_select( 'course_format_options', "courseid = :siteid AND format != :site", - array("siteid" => $SITE->id, 'site' => 'site') + ["siteid" => $SITE->id, 'site' => 'site'], ); unset_config('kickstart_templates'); return true; diff --git a/db/upgrade.php b/db/upgrade.php index 9a1bb83..d15a328 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -233,7 +233,7 @@ function xmldb_format_kickstart_upgrade($oldversion) { if ($oldversion < 2023040300) { $DB->set_field('tag_instance', 'itemtype', 'format_kickstart_template', - array('itemtype' => 'kickstart_template', 'component' => 'format_kickstart')); + ['itemtype' => 'kickstart_template', 'component' => 'format_kickstart']); // Kickstart savepoint reached. upgrade_plugin_savepoint(true, 2023040300, 'format', 'kickstart'); } diff --git a/format.php b/format.php index 455d3d5..3048a68 100644 --- a/format.php +++ b/format.php @@ -41,7 +41,7 @@ $output = $PAGE->get_renderer('format_kickstart'); $PAGE->requires->js_call_amd('format_kickstart/formatkickstart', 'init', - array('contextid' => $context->id, 'courseid' => $course->id)); + ['contextid' => $context->id, 'courseid' => $course->id]); if (has_capability('format/kickstart:import_from_template', $context)) { // Check the template add or remove. diff --git a/freetemplates.php b/freetemplates.php index fbf3e8e..eb2da61 100644 --- a/freetemplates.php +++ b/freetemplates.php @@ -27,7 +27,7 @@ global $freetemplates; $freetemplates = [ - '0' => array( + '0' => [ 'id' => 0, 'title' => 'demo test 1', 'description' => '

test content of the block content

', @@ -42,6 +42,6 @@ 'restrictrole' => 0, 'roleids' => [], 'descriptionformat' => 1, - ), + ], ]; diff --git a/lib.php b/lib.php index 750f1cb..b08c549 100644 --- a/lib.php +++ b/lib.php @@ -71,7 +71,7 @@ public function course_format_options($foreditform = false) { 'element_attributes' => [ [ 'tile' => new lang_string('strtile', 'format_kickstart'), - 'list' => new lang_string('strlist', 'format_kickstart') + 'list' => new lang_string('strlist', 'format_kickstart'), ], ], 'default' => get_config('format_kickstart', 'defaulttemplatesview'), @@ -82,7 +82,7 @@ public function course_format_options($foreditform = false) { 'help_component' => 'format_kickstart', 'default' => [ 'text' => !empty($defaultuserinstructions) ? $defaultuserinstructions : '', - 'format' => FORMAT_HTML + 'format' => FORMAT_HTML, ], 'type' => PARAM_RAW, 'element_type' => 'editor', @@ -90,7 +90,7 @@ public function course_format_options($foreditform = false) { 'userinstructions_format' => [ 'element_type' => 'hidden', 'type' => PARAM_INT, - 'label' => 'hidden' + 'label' => 'hidden', ], 'teacherinstructions' => [ 'label' => new lang_string('teacherinstructions', 'format_kickstart'), @@ -98,7 +98,7 @@ public function course_format_options($foreditform = false) { 'help_component' => 'format_kickstart', 'default' => [ 'text' => !empty($defaultteacherinstructions) ? $defaultteacherinstructions : '', - 'format' => FORMAT_HTML + 'format' => FORMAT_HTML, ], 'type' => PARAM_RAW, 'element_type' => 'editor', @@ -106,8 +106,8 @@ public function course_format_options($foreditform = false) { 'teacherinstructions_format' => [ 'element_type' => 'hidden', 'type' => PARAM_INT, - 'label' => 'hidden' - ] + 'label' => 'hidden', + ], ]; } @@ -143,8 +143,8 @@ protected function update_format_options($data, $sectionid = null) { // Nothing to update anyway. return false; } - $defaultoptions = array(); - $cached = array(); + $defaultoptions = []; + $cached = []; foreach ($allformatoptions as $key => $option) { $defaultoptions[$key] = null; if (array_key_exists('default', $option)) { @@ -153,16 +153,16 @@ protected function update_format_options($data, $sectionid = null) { $cached[$key] = ($sectionid === 0 || !empty($option['cache'])); } $records = $DB->get_records('course_format_options', - array('courseid' => $this->courseid, + ['courseid' => $this->courseid, 'format' => $this->format, - 'sectionid' => $sectionid - ), '', 'name,id,value'); + 'sectionid' => $sectionid, + ], '', 'name,id,value'); $changed = $needrebuild = false; foreach ($defaultoptions as $key => $value) { if (isset($records[$key])) { if (array_key_exists($key, $data) && $records[$key]->value !== $data[$key]) { $DB->set_field('course_format_options', 'value', - $data[$key], array('id' => $records[$key]->id)); + $data[$key], ['id' => $records[$key]->id]); $changed = true; $needrebuild = $needrebuild || $cached[$key]; } @@ -179,13 +179,13 @@ protected function update_format_options($data, $sectionid = null) { $newvalue = !is_array($newvalue) ? $newvalue : $newvalue['text']; - $DB->insert_record('course_format_options', array( + $DB->insert_record('course_format_options', [ 'courseid' => $this->courseid, 'format' => $this->format, 'sectionid' => $sectionid, 'name' => $key, - 'value' => $newvalue - )); + 'value' => $newvalue, + ]); } } if ($needrebuild) { @@ -239,13 +239,13 @@ public function get_course() { if (is_string($course->userinstructions)) { $course->userinstructions = [ 'text' => $course->userinstructions, - 'format' => $course->userinstructions_format + 'format' => $course->userinstructions_format, ]; } if (is_string($course->teacherinstructions)) { $course->teacherinstructions = [ 'text' => $course->teacherinstructions, - 'format' => $course->teacherinstructions_format + 'format' => $course->teacherinstructions_format, ]; } @@ -388,8 +388,7 @@ function format_kickstart_import_courseformat_template() { function format_kickstart_add_couseformat_template($templatename, $format, $counttemplate, $isenabled) { global $DB, $CFG; $templates = isset($CFG->kickstart_templates) ? explode(",", $CFG->kickstart_templates) : []; - if (!$DB->record_exists('format_kickstart_template', ['title' => $templatename, - 'courseformat' => 1])) { + if (!$DB->record_exists('format_kickstart_template', ['title' => $templatename, 'courseformat' => 1])) { $template = new stdClass(); $template->title = $templatename; $template->sort = $counttemplate; @@ -417,10 +416,10 @@ function format_kickstart_update_template_format_options($template) { global $DB, $SITE, $CFG; $isdesignerformat = ($template->format == 'designer') ? true : false; $records = $DB->get_records('course_format_options', - array( + [ 'courseid' => $SITE->id, - 'format' => $template->format - ) + 'format' => $template->format, + ] ); if ($records) { $courseformat = $template->format; @@ -431,7 +430,7 @@ function format_kickstart_update_template_format_options($template) { } foreach ($records as $record) { if (!$existrecord = $DB->get_record('format_kickstart_options', ['format' => $courseformat, - 'templateid' => $template->id, 'name' => $record->name])) { + 'templateid' => $template->id, 'name' => $record->name, ])) { $data = new stdClass(); $data->templateid = $template->id; $data->displayname = $template->title; @@ -467,10 +466,10 @@ function format_kickstart_get_template_format_options($template) { $courseformat = strtolower($template->title); } $records = $DB->get_records_menu('format_kickstart_options', - array( + [ 'templateid' => $template->id, - 'format' => $courseformat - ), + 'format' => $courseformat, + ], '', 'name,value' ); @@ -498,7 +497,7 @@ function format_kickstart_check_format_template() { global $DB, $SITE, $CFG; $templates = isset($CFG->kickstart_templates) ? explode(",", $CFG->kickstart_templates) : []; // Add the kickstart templates to visible template remove the store config. - $records = $DB->get_records_menu('format_kickstart_template', array('visible' => 1), '', 'id,id'); + $records = $DB->get_records_menu('format_kickstart_template', ['visible' => 1], '', 'id,id'); if ($records) { $records = array_keys($records); $addtemplates = array_diff($records, $templates); @@ -508,7 +507,7 @@ function format_kickstart_check_format_template() { $cache = cache::make('format_kickstart', 'templates'); if (!$cache->get('templateformat')) { - $records = $DB->get_records_menu('format_kickstart_template', array('courseformat' => 1), '', 'id,format'); + $records = $DB->get_records_menu('format_kickstart_template', ['courseformat' => 1], '', 'id,format'); $records = array_unique($records); $formats = core_plugin_manager::instance()->get_plugins_of_type('format'); $formats = array_keys($formats); @@ -570,7 +569,7 @@ function format_kickstart_get_designer_coursetypes() { 0 => get_string('normal'), DESIGNER_TYPE_KANBAN => get_string('kanbanboard', 'format_designer'), DESIGNER_TYPE_COLLAPSIBLE => get_string('collapsiblesections', 'format_designer'), - DESIGNER_TYPE_FLOW => get_string('type_flow', 'format_designer') + DESIGNER_TYPE_FLOW => get_string('type_flow', 'format_designer'), ]; return $coursetypes; } @@ -589,7 +588,7 @@ function format_kickstart_get_designer_coursetypes() { * @param array $options additional options affecting the file serving * @return bool false if file not found, does not return if found - just send the file */ -function format_kickstart_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) { +function format_kickstart_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = []) { require_login(); if ($context->contextlevel != CONTEXT_SYSTEM && $filearea != 'description') { return false; diff --git a/settings.php b/settings.php index 0f5c25d..faf3966 100644 --- a/settings.php +++ b/settings.php @@ -47,7 +47,7 @@ get_string('automatictemplate_desc', 'format_kickstart'), 1)); if (function_exists('local_kickstart_pro_get_template_backimages')) { - $templatebgoptions = array('maxfiles' => 10, 'subdirs' => 0, 'accepted_types' => ['.jpg', '.png']); + $templatebgoptions = ['maxfiles' => 10, 'subdirs' => 0, 'accepted_types' => ['.jpg', '.png']]; $settings->add(new admin_setting_configstoredfile( 'format_kickstart/templatebackimages', get_string('default_templatebackground', 'format_kickstart'), @@ -64,7 +64,7 @@ get_string('importtarget_desc', 'format_kickstart'), \backup::TARGET_EXISTING_DELETING, [ \backup::TARGET_EXISTING_DELETING => get_string('restoretoexistingcoursedeleting', 'format_kickstart'), - \backup::TARGET_EXISTING_ADDING => get_string('restoretoexistingcourseadding', 'format_kickstart') + \backup::TARGET_EXISTING_ADDING => get_string('restoretoexistingcourseadding', 'format_kickstart'), ])); $settings->add(new admin_setting_configselect('format_kickstart/defaulttemplatesview', @@ -72,7 +72,7 @@ get_string('defaulttemplatesview_desc', 'format_kickstart'), 'tile', [ 'tile' => get_string('strtile', 'format_kickstart'), - 'list' => get_string('strlist', 'format_kickstart') + 'list' => get_string('strlist', 'format_kickstart'), ])); $settings->add(new admin_setting_confightmleditor('format_kickstart/defaultuserinstructions', @@ -88,13 +88,13 @@ $options = [ 0 => get_string('no'), 1 => get_string('yes'), - 2 => get_string('usedefault', 'format_kickstart') + 2 => get_string('usedefault', 'format_kickstart'), ]; $settings->add(new admin_setting_heading( 'restoresettings', get_string('generalrestoresettings', 'backup'), - get_string('usedefault_help', 'format_kickstart') + get_string('usedefault_help', 'format_kickstart'), )); $settings->add(new admin_setting_configselect( diff --git a/template.php b/template.php index 852e189..ebd4cd8 100644 --- a/template.php +++ b/template.php @@ -37,7 +37,7 @@ $PAGE->navbar->add(get_string('manage_templates', 'format_kickstart'), new moodle_url('/course/format/kickstart/templates.php')); // Prepare the template images. -$templatebgoptions = array('maxfiles' => 10, 'subdirs' => 0, 'accepted_types' => ['.jpg', '.png']); +$templatebgoptions = ['maxfiles' => 10, 'subdirs' => 0, 'accepted_types' => ['.jpg', '.png']]; require_login(); require_capability('format/kickstart:manage_templates', $context); $templates = isset($CFG->kickstart_templates) ? explode(",", $CFG->kickstart_templates) : []; @@ -45,8 +45,9 @@ require_once($CFG->dirroot."/local/kickstart_pro/lib.php"); } -$editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $CFG->maxbytes, -'trusttext' => false, 'noclean' => true, 'context' => $context); +$editoroptions = ['maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $CFG->maxbytes, + 'trusttext' => false, 'noclean' => true, 'context' => $context, +]; switch ($action) { @@ -54,12 +55,13 @@ $PAGE->set_title(get_string('create_template', 'format_kickstart')); $PAGE->set_heading(get_string('create_template', 'format_kickstart')); $PAGE->navbar->add(get_string('create_template', 'format_kickstart')); - if (!format_kickstart_has_pro() && $DB->count_records('format_kickstart_template', array('courseformat' => 0)) >= 2 * 2) { + if (!format_kickstart_has_pro() && $DB->count_records('format_kickstart_template', ['courseformat' => 0]) >= 2 * 2) { redirect(new moodle_url('/course/format/kickstart/buypro.php')); } $form = new \format_kickstart\form\template_form($PAGE->url, ['templatebgoptions' => $templatebgoptions, - 'editoroptions' => $editoroptions]); + 'editoroptions' => $editoroptions, + ]); if ($data = $form->get_data()) { $data->description = $data->description_editor['text']; @@ -100,7 +102,7 @@ $template = new stdClass(); // Get global settings bg and set the images. if (format_kickstart_has_pro() && function_exists('local_kickstart_pro_get_template_backimages')) { - $templateoptions = array('maxfiles' => 10, 'subdirs' => 0, 'accepted_types' => ['.jpg', '.png']); + $templateoptions = ['maxfiles' => 10, 'subdirs' => 0, 'accepted_types' => ['.jpg', '.png']]; $draftitem = file_get_submitted_draft_itemid('templatebackimages'); file_prepare_draft_area($draftitem, \context_system::instance()->id, 'format_kickstart', 'templatebackimages', 0, $templateoptions); @@ -125,7 +127,8 @@ $template->tags = core_tag_tag::get_item_tags_array('format_kickstart', 'format_kickstart_template', $template->id); $form = new \format_kickstart\form\template_form($PAGE->url, ['templatebgoptions' => $templatebgoptions, - 'template' => (array) $template, 'editoroptions' => $editoroptions]); + 'template' => (array) $template, 'editoroptions' => $editoroptions, + ]); if ($data = $form->get_data()) { if (isset($data->courseformatoptions)) { diff --git a/templates.php b/templates.php index e523b71..f067cbc 100644 --- a/templates.php +++ b/templates.php @@ -73,10 +73,10 @@ set_config('kickstart_templates', implode(',', $enabled)); break; case 'disable': - $DB->set_field('format_kickstart_template', 'status', 0, array('id' => $templateid)); + $DB->set_field('format_kickstart_template', 'status', 0, ['id' => $templateid]); break; case 'enable' : - $DB->set_field('format_kickstart_template', 'status', 1, array('id' => $templateid)); + $DB->set_field('format_kickstart_template', 'status', 1, ['id' => $templateid]); break; } redirect($PAGE->url); @@ -89,7 +89,7 @@ $PAGE->set_button($OUTPUT->single_button(new moodle_url('/course/format/kickstart/template.php', ['action' => 'create']), get_string('create_template', 'format_kickstart'))); -if (!format_kickstart_has_pro() && $DB->count_records('format_kickstart_template', array('courseformat' => 0)) >= 2 * 2) { +if (!format_kickstart_has_pro() && $DB->count_records('format_kickstart_template', ['courseformat' => 0]) >= 2 * 2) { \core\notification::warning(get_string('buypromaxtemplates', 'format_kickstart')); } diff --git a/tests/behat/behat_format_kickstart.php b/tests/behat/behat_format_kickstart.php index 4076a73..3f6b5ca 100644 --- a/tests/behat/behat_format_kickstart.php +++ b/tests/behat/behat_format_kickstart.php @@ -44,7 +44,7 @@ class behat_format_kickstart extends behat_base { * @param TableNode $table The course data */ public function i_create_a_kickstart_template_with(TableNode $table) { - $url = new moodle_url('/course/format/kickstart/template.php', array('action' => 'create', 'sesskey' => sesskey())); + $url = new moodle_url('/course/format/kickstart/template.php', ['action' => 'create', 'sesskey' => sesskey()]); $this->execute('behat_general::i_visit', [$url]); $this->execute("behat_forms::i_set_the_following_fields_to_these_values", $table); $this->execute("behat_forms::press_button", get_string('savechanges')); @@ -60,7 +60,7 @@ public function i_set_kickstart_format_setting_with(TableNode $table) { $this->execute("behat_general::i_am_on_homepage"); $this->execute("behat_navigation::i_navigate_to_in_site_administration", - array("Plugins" . ' > ' . "Course formats". '>'."General settings") + ["Plugins" . ' > ' . "Course formats". '>'."General settings"], ); $this->execute("behat_forms::i_set_the_following_fields_to_these_values", $table); $this->execute("behat_forms::press_button", get_string('savechanges')); diff --git a/tests/format_kickstart_test.php b/tests/format_kickstart_test.php index 07efab6..f1909e6 100644 --- a/tests/format_kickstart_test.php +++ b/tests/format_kickstart_test.php @@ -54,10 +54,10 @@ public function test_importing() { 'startdate' => 1000, 'enddate' => 1000, 'sortorder' => 10001, - 'enablecompletion' => 1 + 'enablecompletion' => 1, ]); $module = $this->getDataGenerator()->create_module('forum', [ - 'course' => $course->id + 'course' => $course->id, ]); $template = new \stdClass(); $template->title = ''; @@ -73,7 +73,8 @@ public function test_importing() { 'filearea' => 'course_backups', 'itemid' => $template->id, 'filepath' => '/', - 'filename' => 'course-10-online.mbz']; + 'filename' => 'course-10-online.mbz', + ]; $fs->create_file_from_pathname($fileinfo, $CFG->dirroot . '/course/format/kickstart/tests/course-10-online.mbz'); @@ -90,7 +91,7 @@ public function test_importing() { 'cacherev', 'hiddensections', 'coursedisplay', - 'showactivitydates' + 'showactivitydates', ]; foreach ($course as $field => $value) { @@ -135,7 +136,7 @@ public function test_check_kickstart_has_pro() { * Get the template info. */ public function format_format_kickstart_template_info() { - $template = array( + $template = [ 'id' => 0, 'title' => 'demo test 1', 'description' => '

test content of the block content

', @@ -150,7 +151,7 @@ public function format_format_kickstart_template_info() { 'restrictrole' => 0, 'roleids' => [], 'descriptionformat' => 1, - ); + ]; return (object) $template; } @@ -165,7 +166,7 @@ public function test_format_kickstart_add_couseformat_template() { $counttemplate = $DB->count_records("format_kickstart_template"); format_kickstart_add_couseformat_template($templatename, $format, $counttemplate, true); $count = $DB->count_records('format_kickstart_template'); - $this->assertTrue($DB->record_exists('format_kickstart_template', array('format' => $format, 'courseformat' => 1))); + $this->assertTrue($DB->record_exists('format_kickstart_template', ['format' => $format, 'courseformat' => 1])); } /** @@ -176,11 +177,13 @@ public function test_format_kickstart_update_template_format_options() { global $DB; $this->create_kickstart_template_options(); $format = 'topics'; - $template = $DB->get_record('format_kickstart_template', array('format' => $format, 'courseformat' => 1)); - $this->assertTrue($DB->record_exists('format_kickstart_options', array('format' => $format, - 'templateid' => $template->id, 'name' => 'hiddensections'))); - $this->assertTrue($DB->record_exists('format_kickstart_options', array('format' => $format, - 'templateid' => $template->id, 'name' => 'coursedisplay'))); + $template = $DB->get_record('format_kickstart_template', ['format' => $format, 'courseformat' => 1]); + $this->assertTrue($DB->record_exists('format_kickstart_options', ['format' => $format, + 'templateid' => $template->id, 'name' => 'hiddensections', + ])); + $this->assertTrue($DB->record_exists('format_kickstart_options', ['format' => $format, + 'templateid' => $template->id, 'name' => 'coursedisplay', + ])); } /** @@ -195,7 +198,7 @@ public function create_kickstart_template_options() { $data['hiddensections'] = 1; $data['coursedisplay'] = 0; $data['courseformatoptions'] = 1; - $template = $DB->get_record('format_kickstart_template', array('format' => $format, 'courseformat' => 1)); + $template = $DB->get_record('format_kickstart_template', ['format' => $format, 'courseformat' => 1]); $courseformat = course_get_format((object) $params); $courseformat->update_course_format_options($data); return format_kickstart_update_template_format_options($template); @@ -209,7 +212,7 @@ public function create_kickstart_template_options() { public function test_format_kickstart_get_template_format_options() { global $DB; $format = 'topics'; - $template = $DB->get_record('format_kickstart_template', array('format' => $format, 'courseformat' => 1)); + $template = $DB->get_record('format_kickstart_template', ['format' => $format, 'courseformat' => 1]); $this->create_kickstart_template_options(); $val = format_kickstart_get_template_format_options($template); $this->assertEquals($val['coursedisplay'], 0); @@ -224,13 +227,14 @@ public function test_format_kickstart_get_template_format_options() { public function test_format_kickstart_remove_kickstart_templates() { global $DB, $CFG, $SITE; $format = 'topics'; - $template = $DB->get_record('format_kickstart_template', array('format' => $format, 'courseformat' => 1)); + $template = $DB->get_record('format_kickstart_template', ['format' => $format, 'courseformat' => 1]); $this->create_kickstart_template_options(); - $this->assertTrue(!empty($DB->get_record('format_kickstart_template', array('id' => $template->id)))); + $this->assertTrue(!empty($DB->get_record('format_kickstart_template', ['id' => $template->id]))); $this->assertTrue(!empty($DB->get_records('course_format_options', ['courseid' => $SITE->id, - 'format' => $template->format]))); + 'format' => $template->format, + ]))); format_kickstart_remove_kickstart_templates($template->id); - $this->assertFalse($DB->get_record('format_kickstart_template', array('id' => $template->id))); + $this->assertFalse($DB->get_record('format_kickstart_template', ['id' => $template->id])); $this->assertFalse(array_search($template->id, explode(",", $CFG->kickstart_templates))); } } diff --git a/version.php b/version.php index 68d2fae..a5219d1 100644 --- a/version.php +++ b/version.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2023112301; // The current plugin version (Date: YYYYMMDDXX). +$plugin->version = 2023112700; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2022041900; // Requires this Moodle version. $plugin->release = 'Version 1.3'; $plugin->component = 'format_kickstart'; // Full name of the plugin (used for diagnostics).