From c9f8053f08775c703f651ccd17aa74cf5fa5bf24 Mon Sep 17 00:00:00 2001 From: Gareth Barnard <1058419+gjb2048@users.noreply.github.com> Date: Thu, 24 Oct 2024 12:52:41 +0100 Subject: [PATCH] V405.0.1 --- .github/workflows/ci.yml | 8 +- Changes.md | 6 + Readme.md | 6 +- Support.md | 4 +- classes/admin_setting_information.php | 12 +- classes/admin_setting_markdown.php | 7 +- classes/observer.php | 6 +- classes/output/courseformat/content.php | 36 ++-- .../output/courseformat/content/section.php | 5 +- .../courseformat/content/section/summary.php | 9 +- .../content/sectionnavigation.php | 5 +- .../courseformat/content/sectionselector.php | 10 +- .../task/update_displayed_images_adhoc.php | 7 +- classes/task/update_displayed_images_task.php | 7 +- classes/toolbox.php | 57 +++--- db/events.php | 4 +- templates/coursestyles.mustache | 3 +- templates/grid_section.mustache | 64 ++++++ templates/local/content.mustache | 4 +- .../local/content/section/content.mustache | 189 +++++++++--------- version.php | 10 +- 21 files changed, 289 insertions(+), 170 deletions(-) create mode 100644 templates/grid_section.mustache diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3bca17f5..7b55a410 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,8 +21,8 @@ jobs: strategy: fail-fast: false matrix: - php: ['8.1', '8.2'] - moodle-branch: ['MOODLE_404_STABLE'] + php: ['8.3'] + moodle-branch: ['MOODLE_405_STABLE'] database: [mariadb] steps: @@ -45,9 +45,9 @@ jobs: echo $(cd ci/bin; pwd) >> $GITHUB_PATH echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH sudo locale-gen en_AU.UTF-8 - #echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV + echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV # Install nvm v0.39.7 (Temporary workaround for https://github.com/moodlehq/moodle-plugin-ci/issues/309). - curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash + #curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash - name: Install moodle-plugin-ci run: | moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1 diff --git a/Changes.md b/Changes.md index 8a7ad987..0810d147 100644 --- a/Changes.md +++ b/Changes.md @@ -1,6 +1,12 @@ History ============= +Version 405.0.1 - 24/10/2024 +---------------------------- +1. Release candidate version for Moodle 4.5. +2. Fix 'Generated images not showing when editing'. +3. Impact of MDL-81920 and MDL-81960. + Version 404.1.3 - 03/10/2024 ---------------------------- 1. Fix 'Orphaned sections problem when adding sections', a regression caused by diff --git a/Readme.md b/Readme.md index 4e9960ca..5ffb67ff 100644 --- a/Readme.md +++ b/Readme.md @@ -4,17 +4,17 @@ A topics based format that uses a grid of user selectable images to select a sec Required release of Moodle ========================== -This version works with Moodle 4.4 version 2024042200.00 (Build: 20240422) and above within the MOODLE_404_STABLE branch until the +This version works with Moodle 4.5 version 2024100700.00 (Build: 20241007) and above within the MOODLE_405_STABLE branch until the next release. -Please ensure that your hardware and software complies with 'Requirements' in '[Installing Moodle](https://docs.moodle.org/404/en/Installing_Moodle)'. +Please ensure that your hardware and software complies with 'Requirements' in '[Installing Moodle](https://docs.moodle.org/405/en/Installing_Moodle)'. Free software ============= The Grid format is 'free' software under the terms of the GNU GPLv3 License, please see 'COPYING.txt'. The primary source for downloading this branch of the format is https://moodle.org/plugins/view.php?plugin=format_grid -with 'Your Moodle version:' set at 'Moodle 4.4'. +with 'Your Moodle version:' set at 'Moodle 4.5'. The secondary source is https://github.com/gjbarnard/moodle-format_grid/tags diff --git a/Support.md b/Support.md index 4cc039cd..c8835c92 100644 --- a/Support.md +++ b/Support.md @@ -33,10 +33,10 @@ benefits. Required release of Moodle ========================== -This version works with Moodle 4.4 version 2024042200.00 (Build: 20240422) and above within the MOODLE_404_STABLE branch until the +This version works with Moodle 4.5 version 2024100700.00 (Build: 20241007) and above within the MOODLE_405_STABLE branch until the next release. -Please ensure that your hardware and software complies with 'Requirements' in '[Installing Moodle](https://docs.moodle.org/404/en/Installing_Moodle)'. +Please ensure that your hardware and software complies with 'Requirements' in '[Installing Moodle](https://docs.moodle.org/405/en/Installing_Moodle)'. Reporting issues ================ diff --git a/classes/admin_setting_information.php b/classes/admin_setting_information.php index 23a74e32..286096b9 100644 --- a/classes/admin_setting_information.php +++ b/classes/admin_setting_information.php @@ -26,13 +26,17 @@ namespace format_grid; +use admin_setting; +use core_plugin_manager; +use core\output\html_writer; + /** * Setting that displays information. Based on admin_setting_description in adminlib.php. * * @copyright © 2022-onwards G J Barnard. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. */ -class admin_setting_information extends \admin_setting { +class admin_setting_information extends admin_setting { /** @var int The branch this is for. */ protected $mbranch; @@ -93,7 +97,7 @@ public function output_html($data, $query = '') { if (!empty($formats['grid'])) { $plugininfo = $formats['grid']; } else { - $plugininfo = \core_plugin_manager::instance()->get_plugin_info('format_grid'); + $plugininfo = core_plugin_manager::instance()->get_plugin_info('format_grid'); $plugininfo->version = $plugininfo->versiondisk; } @@ -102,8 +106,8 @@ public function output_html($data, $query = '') { $attributes['aria-hidden'] = 'true'; $attributes['class'] = 'fa fa-heart'; $attributes['title'] = get_string('love', 'format_grid'); - $content = \html_writer::tag('span', $attributes['title'], ['class' => 'sr-only']); - $content = \html_writer::tag('span', $content, $attributes); + $content = html_writer::tag('span', $attributes['title'], ['class' => 'sr-only']); + $content = html_writer::tag('span', $content, $attributes); $context['versioninfo'] = get_string( 'versioninfo', 'format_grid', diff --git a/classes/admin_setting_markdown.php b/classes/admin_setting_markdown.php index c269489f..c2e01131 100644 --- a/classes/admin_setting_markdown.php +++ b/classes/admin_setting_markdown.php @@ -26,13 +26,16 @@ namespace format_grid; +use admin_setting; +use stdClass; + /** * Setting that displays markdown files. Based on admin_setting_description in adminlib.php. * * @copyright © 2022-onwards G J Barnard. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. */ -class admin_setting_markdown extends \admin_setting { +class admin_setting_markdown extends admin_setting { /** @var string Filename */ private $filename; @@ -89,7 +92,7 @@ public function write_setting($data) { public function output_html($data, $query = '') { global $CFG, $OUTPUT; - $context = new \stdClass(); + $context = new stdClass(); $context->title = $this->visiblename; $context->description = $this->description; diff --git a/classes/observer.php b/classes/observer.php index dcdb127b..80181238 100644 --- a/classes/observer.php +++ b/classes/observer.php @@ -25,10 +25,12 @@ * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace format_grid; + /** * Event observers supported by this format. */ -class format_grid_observer { +class observer { /** * Observer for the event course_content_deleted. * @@ -67,6 +69,6 @@ public static function course_restored(\core\event\course_restored $event) { */ protected static function delete_images($courseid) { // Delete any images associated with the course. - \format_grid\toolbox::delete_images($courseid); + toolbox::delete_images($courseid); } } diff --git a/classes/output/courseformat/content.php b/classes/output/courseformat/content.php index ba8c6f66..8556fd52 100644 --- a/classes/output/courseformat/content.php +++ b/classes/output/courseformat/content.php @@ -26,7 +26,13 @@ namespace format_grid\output\courseformat; +use completion_info; +use context_course; use core_courseformat\output\local\content as content_base; +use core\output\renderer_base; +use core\url; +use format_grid\toolbox; +use moodle_exception; use stdClass; /** @@ -63,7 +69,7 @@ class content extends content_base { * @param renderer_base $output typically, the renderer that's calling this method. * @return string Mustache template name. */ - public function get_template_name(\renderer_base $renderer): string { + public function get_template_name(renderer_base $renderer): string { return 'format_grid/local/content'; } @@ -73,7 +79,7 @@ public function get_template_name(\renderer_base $renderer): string { * @param renderer_base $output typically, the renderer that's calling this method. * @return stdClass data context for a Mustache template. */ - public function export_for_template(\renderer_base $output) { + public function export_for_template(renderer_base $output) { global $DB, $PAGE; $format = $this->format; $editing = $PAGE->user_is_editing(); @@ -125,9 +131,9 @@ public function export_for_template(\renderer_base $output) { $data->hasnavigation = true; $data->singlesection = array_shift($data->sections); $data->sectionreturn = $singlesectionno; - $data->maincoursepage = new \moodle_url('/course/view.php', ['id' => $course->id]); + $data->maincoursepage = new url('/course/view.php', ['id' => $course->id]); } else { - $toolbox = \format_grid\toolbox::get_instance(); + $toolbox = toolbox::get_instance(); $coursesectionimages = $DB->get_records('format_grid_image', ['courseid' => $course->id]); if (!empty($coursesectionimages)) { $fs = get_file_storage(); @@ -145,7 +151,7 @@ public function export_for_template(\renderer_base $output) { if (!empty($replacement)) { $coursesectionimages[$coursesectionimage->id] = $replacement; } - } catch (\moodle_exception $me) { + } catch (moodle_exception $me) { $coursesectionimages[$coursesectionimage->id]->imageerror = $me->getMessage(); } } @@ -188,7 +194,7 @@ public function export_for_template(\renderer_base $output) { $displayediswebp = (get_config('format_grid', 'defaultdisplayedimagefiletype') == 2); $completionshown = false; - $headerimages = false; + $sectionheaderimages = false; if ($editing) { $datasectionmap = []; foreach ($data->sections as $datasectionkey => $datasection) { @@ -241,7 +247,7 @@ public function export_for_template(\renderer_base $output) { if (!empty($data->sections[$datasectionmap[$section->id]])) { // Add the image to the section content. $data->sections[$datasectionmap[$section->id]]->gridimage = $sectionimages[$section->id]; - $headerimages = true; + $sectionheaderimages = true; } } else { // Section link. @@ -302,15 +308,15 @@ public function export_for_template(\renderer_base $output) { $data->gridsectionnumbers = implode(',', $gridsectionnums); } - if ($headerimages) { - $data->hasheaderimages = true; + if ($sectionheaderimages) { + $data->hassectionheaderimages = true; $coursesettings['imagecontainerwidth'] = 144; $data->coursestyles = $toolbox->get_displayed_image_container_properties($coursesettings); } } if ($this->hassteathwithcontent) { - $context = \context_course::instance($course->id); + $context = context_course::instance($course->id); if (has_capability('moodle/course:update', $context)) { $data->stealthwarning = get_string('stealthwarning', 'format_grid', $this->hassteathwithcontent); } @@ -337,7 +343,7 @@ public function export_for_template(\renderer_base $output) { * * @return array data context for a mustache template */ - protected function get_grid_sections(\renderer_base $output, $settings): array { + protected function get_grid_sections(renderer_base $output, $settings): array { $format = $this->format; $course = $format->get_course(); @@ -359,7 +365,7 @@ protected function get_grid_sections(\renderer_base $output, $settings): array { foreach ($sectioninfos as $thissection) { // The course/view.php check the section existence but the output can be called from other parts so we need to check it. if (!$thissection) { - throw new \moodle_exception( + throw new moodle_exception( 'unknowncoursesection', 'error', '', @@ -407,7 +413,7 @@ protected function get_grid_sections(\renderer_base $output, $settings): array { * @param stdClass $modinfo the course module information. * @param renderer_base $output typically, the renderer that's calling this method. */ - protected function calculate_section_activity_completion($section, $course, $modinfo, \renderer_base $output) { + protected function calculate_section_activity_completion($section, $course, $modinfo, renderer_base $output) { if (empty($this->sectioncompletioncalculated[$section->section])) { $this->sectioncompletionmarkup[$section->section] = ''; if (empty($modinfo->sections[$section->section])) { @@ -421,7 +427,7 @@ protected function calculate_section_activity_completion($section, $course, $mod $cancomplete = isloggedin() && !isguestuser(); $asectionisavailable = false; if ($cancomplete) { - $completioninfo = new \completion_info($course); + $completioninfo = new completion_info($course); foreach ($modinfo->sections[$section->section] as $cmid) { $thismod = $modinfo->cms[$cmid]; @@ -452,7 +458,7 @@ protected function calculate_section_activity_completion($section, $course, $mod $percentage = round(($complete / $total) * 100); $this->sectioncompletionpercentage[$section->section] = $percentage; - $data = new \stdClass(); + $data = new stdClass(); $data->percentagevalue = $this->sectioncompletionpercentage[$section->section]; if ($data->percentagevalue < 11) { $data->percentagecolour = 'low'; diff --git a/classes/output/courseformat/content/section.php b/classes/output/courseformat/content/section.php index 3ec05a79..90a5ce4c 100644 --- a/classes/output/courseformat/content/section.php +++ b/classes/output/courseformat/content/section.php @@ -29,6 +29,7 @@ use core_courseformat\base as course_format; use core_courseformat\output\local\content\section as section_base; +use core\output\renderer_base; use stdClass; /** @@ -51,7 +52,7 @@ class section extends section_base { * @param renderer_base $output typically, the renderer that's calling this function. * @return array data context for a mustache template. */ - public function export_for_template(\renderer_base $output): stdClass { + public function export_for_template(renderer_base $output): stdClass { $format = $this->format; $data = parent::export_for_template($output); @@ -74,7 +75,7 @@ public function export_for_template(\renderer_base $output): stdClass { * @param renderer_base $output typically, the renderer that's calling this function * @return bool if the cm has name data */ - protected function add_format_data(stdClass &$data, array $haspartials, \renderer_base $output): bool { + protected function add_format_data(stdClass &$data, array $haspartials, renderer_base $output): bool { parent::add_format_data($data, $haspartials, $output); $data->collapsemenu = false; diff --git a/classes/output/courseformat/content/section/summary.php b/classes/output/courseformat/content/section/summary.php index 4883c963..ce2e0ce3 100644 --- a/classes/output/courseformat/content/section/summary.php +++ b/classes/output/courseformat/content/section/summary.php @@ -31,6 +31,9 @@ use core_courseformat\output\local\content\section\summary as summary_base; use core_courseformat\base as course_format; +use context_course; +use core\output\renderer_base; +use format_grid\toolbox; use section_info; use stdClass; @@ -62,7 +65,7 @@ public function __construct(course_format $format, section_info $section) { * @param renderer_base $output typically, the renderer that's calling this function. * @return array data context for a mustache template. */ - public function export_for_template(\renderer_base $output): stdClass { + public function export_for_template(renderer_base $output): stdClass { $section = $this->thesection; @@ -113,8 +116,8 @@ protected function singlepagesummaryimage($summary, $output): string { ); if (!empty($coursesectionimage)) { $fs = get_file_storage(); - $coursecontext = \context_course::instance($courseid); - $toolbox = \format_grid\toolbox::get_instance(); + $coursecontext = context_course::instance($courseid); + $toolbox = toolbox::get_instance(); $replacement = $toolbox->check_displayed_image( $coursesectionimage, $courseid, diff --git a/classes/output/courseformat/content/sectionnavigation.php b/classes/output/courseformat/content/sectionnavigation.php index ed54b6ed..c851c5ed 100644 --- a/classes/output/courseformat/content/sectionnavigation.php +++ b/classes/output/courseformat/content/sectionnavigation.php @@ -26,6 +26,9 @@ namespace format_grid\output\courseformat\content; +use core\output\renderer_base; +use stdClass; + /** * Base class to render a course add section navigation. */ @@ -39,7 +42,7 @@ class sectionnavigation extends \core_courseformat\output\local\content\sectionn * @param renderer_base $output typically, the renderer that's calling this function * @return stdClass data context for a mustache template */ - public function export_for_template(\renderer_base $output): \stdClass { + public function export_for_template(renderer_base $output): stdClass { global $USER; if ($this->data !== null) { diff --git a/classes/output/courseformat/content/sectionselector.php b/classes/output/courseformat/content/sectionselector.php index cf99ba96..8c9c3491 100644 --- a/classes/output/courseformat/content/sectionselector.php +++ b/classes/output/courseformat/content/sectionselector.php @@ -26,6 +26,10 @@ namespace format_grid\output\courseformat\content; +use core\output\renderer_base; +use core\output\url_select; +use stdClass; + /** * Represents the section selector. */ @@ -36,7 +40,7 @@ class sectionselector extends \core_courseformat\output\local\content\sectionsel * @param \renderer_base $renderer The renderer requesting the template name * @return string */ - public function get_template_name(\renderer_base $renderer): string { + public function get_template_name(renderer_base $renderer): string { return 'format_grid/local/content/sectionselector'; } @@ -46,7 +50,7 @@ public function get_template_name(\renderer_base $renderer): string { * @param renderer_base $output typically, the renderer that's calling this function * @return stdClass data context for a mustache template */ - public function export_for_template(\renderer_base $output): \stdClass { + public function export_for_template(renderer_base $output): stdClass { $format = $this->format; $course = $format->get_course(); @@ -73,7 +77,7 @@ public function export_for_template(\renderer_base $output): \stdClass { $section++; } - $select = new \url_select($sectionmenu, '', ['' => get_string('jumpto')]); + $select = new url_select($sectionmenu, '', ['' => get_string('jumpto')]); $select->class = 'jumpmenu'; $select->formid = 'sectionmenu'; diff --git a/classes/task/update_displayed_images_adhoc.php b/classes/task/update_displayed_images_adhoc.php index ae0463b0..4c141cc6 100644 --- a/classes/task/update_displayed_images_adhoc.php +++ b/classes/task/update_displayed_images_adhoc.php @@ -27,6 +27,9 @@ */ namespace format_grid\task; +use core\output\progress_trace\text_progress_trace; +use format_grid\toolbox; + /** * Grid update displayed image adhoc task class. * @@ -42,7 +45,7 @@ class update_displayed_images_adhoc extends \core\task\adhoc_task { * Run the task. */ public function execute() { - $trace = new \text_progress_trace(); + $trace = new text_progress_trace(); $courseid = $this->get_custom_data(); self::do_update_displayed_images_task($trace, $courseid); } @@ -55,6 +58,6 @@ public function execute() { */ protected static function do_update_displayed_images_task(\progress_trace $trace, $courseid) { $trace->output('Executing Grid update displayed images adhoc task on course id ' . $courseid . '.'); - \format_grid\toolbox::update_displayed_images($courseid); + toolbox::update_displayed_images($courseid); } } diff --git a/classes/task/update_displayed_images_task.php b/classes/task/update_displayed_images_task.php index 34241031..bfa8e6b8 100644 --- a/classes/task/update_displayed_images_task.php +++ b/classes/task/update_displayed_images_task.php @@ -27,6 +27,9 @@ */ namespace format_grid\task; +use core_courseformat\base; +use core\task\manager; + /** * Grid update displayed images task. * @@ -48,12 +51,12 @@ public static function update_displayed_images_imageresizemethod() { foreach ($gridcourses as $gridcourse) { // Instead of course_get_format() for CLI usage. - $format = \core_courseformat\base::instance($gridcourse->id); + $format = base::instance($gridcourse->id); $imageresizemethod = $format->get_format_options()['imageresizemethod']; if ($imageresizemethod != 0) { $task = new update_displayed_images_adhoc(); $task->set_custom_data($gridcourse->id); - \core\task\manager::queue_adhoc_task($task); + manager::queue_adhoc_task($task); } } } diff --git a/classes/toolbox.php b/classes/toolbox.php index df7365a5..43cb01d0 100644 --- a/classes/toolbox.php +++ b/classes/toolbox.php @@ -26,6 +26,13 @@ namespace format_grid; +use context_course; +use core\lock\lock_config; +use core\url; +use Exception; +use moodle_exception; +use stdClass; + /** * The format's toolbox. * @@ -115,7 +122,7 @@ public function get_displayed_image_uri($coursesectionimage, $coursecontextid, $ $filename .= '.webp'; } } - $image = \moodle_url::make_pluginfile_url( + $image = url::make_pluginfile_url( $coursecontextid, 'format_grid', 'displayedsectionimage', @@ -143,7 +150,7 @@ public function check_displayed_image($sectionimage, $courseid, $coursecontextid if (empty($sectionimage->displayedimagestate)) { $lock = true; if (!defined('BEHAT_SITE_RUNNING')) { - $lockfactory = \core\lock\lock_config::get_lock_factory('format_grid'); + $lockfactory = lock_config::get_lock_factory('format_grid'); $lock = $lockfactory->get_lock('sectionid' . $sectionid, 5); } if ($lock) { @@ -152,7 +159,7 @@ public function check_displayed_image($sectionimage, $courseid, $coursecontextid if (!$file->is_directory()) { try { $newsectionimage = $this->setup_displayed_image($sectionimage, $file, $courseid, $sectionid, $format); - } catch (\Exception $e) { + } catch (Exception $e) { $lock->release(); throw $e; } @@ -162,7 +169,7 @@ public function check_displayed_image($sectionimage, $courseid, $coursecontextid $lock->release(); } } else { - throw new \moodle_exception( + throw new moodle_exception( 'imagemanagement', 'format_grid', '', @@ -239,7 +246,7 @@ public function setup_displayed_image($sectionimage, $sectionfile, $courseid, $s ); if (!empty($data)) { // Updated image. - $coursecontext = \context_course::instance($courseid); + $coursecontext = context_course::instance($courseid); // Remove existing displayed image. $existingfiles = $fs->get_area_files($coursecontext->id, 'format_grid', 'displayedsectionimage', $sectionid); @@ -284,7 +291,7 @@ public function setup_displayed_image($sectionimage, $sectionfile, $courseid, $s ['sectionid' => $sectionid] ); if ($sectionimage->displayedimagestate == -1) { - throw new \moodle_exception( + throw new moodle_exception( 'imagemanagement', 'format_grid', '', @@ -390,7 +397,7 @@ private static function generate_image($filepath, $requestedwidth, $requestedhei if (empty($imageinfo)) { unlink($filepath); - throw new \moodle_exception( + throw new moodle_exception( 'imagemanagement', 'format_grid', '', @@ -407,7 +414,7 @@ private static function generate_image($filepath, $requestedwidth, $requestedhei if (empty($originalheight)) { unlink($filepath); - throw new \moodle_exception( + throw new moodle_exception( 'imagemanagement', 'format_grid', '', @@ -420,7 +427,7 @@ private static function generate_image($filepath, $requestedwidth, $requestedhei } if (empty($originalwidth)) { unlink($filepath); - throw new \moodle_exception( + throw new moodle_exception( 'imagemanagement', 'format_grid', '', @@ -445,7 +452,7 @@ private static function generate_image($filepath, $requestedwidth, $requestedhei $imageargs[3] = PNG_NO_FILTER; // Filter. } else { unlink($filepath); - throw new \moodle_exception( + throw new moodle_exception( 'imagemanagement', 'format_grid', '', @@ -463,7 +470,7 @@ private static function generate_image($filepath, $requestedwidth, $requestedhei $imageargs[2] = 90; // Quality. } else { unlink($filepath); - throw new \moodle_exception( + throw new moodle_exception( 'imagemanagement', 'format_grid', '', @@ -483,7 +490,7 @@ private static function generate_image($filepath, $requestedwidth, $requestedhei $imageargs[2] = 90; // Quality. } else { unlink($filepath); - throw new \moodle_exception( + throw new moodle_exception( 'imagemanagement', 'format_grid', '', @@ -500,7 +507,7 @@ private static function generate_image($filepath, $requestedwidth, $requestedhei $imagefnc = 'imagegif'; } else { unlink($filepath); - throw new \moodle_exception( + throw new moodle_exception( 'imagemanagement', 'format_grid', '', @@ -514,7 +521,7 @@ private static function generate_image($filepath, $requestedwidth, $requestedhei break; default: unlink($filepath); - throw new \moodle_exception( + throw new moodle_exception( 'imagemanagement', 'format_grid', '', @@ -616,7 +623,7 @@ private static function generate_image($filepath, $requestedwidth, $requestedhei if (!call_user_func_array($imagefnc, $imageargs)) { ob_end_clean(); unlink($filepath); - throw new \moodle_exception( + throw new moodle_exception( 'imagemanagement', 'format_grid', '', @@ -691,7 +698,7 @@ private static function update_the_displayed_images($courseid = null) { $coursecontext = null; if (!defined('BEHAT_SITE_RUNNING')) { - $lockfactory = \core\lock\lock_config::get_lock_factory('format_grid'); + $lockfactory = lock_config::get_lock_factory('format_grid'); } $toolbox = self::get_instance(); $courseid = -1; @@ -705,7 +712,7 @@ private static function update_the_displayed_images($courseid = null) { $format = null; continue; } - $coursecontext = \context_course::instance($courseid); + $coursecontext = context_course::instance($courseid); } if (!empty($format)) { if (!defined('BEHAT_SITE_RUNNING')) { @@ -726,7 +733,7 @@ private static function update_the_displayed_images($courseid = null) { ); } } - } catch (\Exception $e) { + } catch (Exception $e) { if (!defined('BEHAT_SITE_RUNNING')) { $lock->release(); } @@ -736,7 +743,7 @@ private static function update_the_displayed_images($courseid = null) { $lock->release(); } } else { - throw new \moodle_exception( + throw new moodle_exception( 'imagemanagement', 'format_grid', '', @@ -757,7 +764,7 @@ public static function delete_images($courseid) { global $DB; $fs = get_file_storage(); - $coursecontext = \context_course::instance($courseid); + $coursecontext = context_course::instance($courseid); // Images. $images = $fs->get_area_files($coursecontext->id, 'format_grid', 'sectionimage'); foreach ($images as $image) { @@ -789,16 +796,16 @@ public static function delete_image($sectionid, $courseid) { $lockfactory = null; $lock = true; if (!defined('BEHAT_SITE_RUNNING')) { - $lockfactory = \core\lock\lock_config::get_lock_factory('format_grid'); + $lockfactory = lock_config::get_lock_factory('format_grid'); $lock = $lockfactory->get_lock('sectionid' . $coursesectionimage->sectionid, 5); } if ($lock) { - $coursecontext = \context_course::instance($courseid); + $coursecontext = context_course::instance($courseid); $files = $fs->get_area_files($coursecontext->id, 'format_grid', 'sectionimage', $coursesectionimage->sectionid); foreach ($files as $file) { try { $file->delete(); - } catch (\Exception $e) { + } catch (Exception $e) { $lock->release(); throw $e; } @@ -808,7 +815,7 @@ public static function delete_image($sectionid, $courseid) { foreach ($displayedfiles as $displayedfile) { try { $displayedfile->delete(); - } catch (\Exception $e) { + } catch (Exception $e) { $lock->release(); throw $e; } @@ -817,7 +824,7 @@ public static function delete_image($sectionid, $courseid) { $lock->release(); } } else { - throw new \moodle_exception( + throw new moodle_exception( 'imagemanagement', 'format_grid', '', diff --git a/db/events.php b/db/events.php index c26c57b2..2ebd5e59 100644 --- a/db/events.php +++ b/db/events.php @@ -31,10 +31,10 @@ $observers = [ [ 'eventname' => '\core\event\course_content_deleted', - 'callback' => 'format_grid_observer::course_content_deleted', + 'callback' => '\format_grid\observer::course_content_deleted', ], [ 'eventname' => '\core\event\course_restored', - 'callback' => 'format_grid_observer::course_restored', + 'callback' => '\format_grid\observer::course_restored', ], ]; diff --git a/templates/coursestyles.mustache b/templates/coursestyles.mustache index f86ca0b1..b3719c58 100644 --- a/templates/coursestyles.mustache +++ b/templates/coursestyles.mustache @@ -34,7 +34,8 @@ /* . +}} +{{! + @template format_grid/grid_section + + Context variables required for this template: + * gridimage - Has a grid image to show. + * currentsection - Current section? + * imageuri - Image URI. + * alttext - Image alternative text. + * generatedimageuri - Generated image URI. + * imageerror - Image error if any. + * image - Name of the image if any. + + Example context (json): + { + "gridimage": true, + "currentsection": true, + "imageuri": "https://mymoodle/pluginfile.php/358/format_grid/displayedsectionimage/42/1/ducking.jpg.webp", + "imagealttext": "Duckling", + "generatedimageuri": false, + "imageerror": "", + "image": "ducking.jpg.webp" + } +}} +{{#gridimage}} +
+
+ {{#imageuri}} +
+ {{imagealttext}} +
+ {{/imageuri}} + {{#generatedimageuri}} +
+
+ {{/generatedimageuri}} + {{#imageerror}} +
+

{{imageerror}}

+
+ {{/imageerror}} + {{#image}} + + {{/image}} +
+
+{{/gridimage}} diff --git a/templates/local/content.mustache b/templates/local/content.mustache index 580d7f2b..457a5ae3 100644 --- a/templates/local/content.mustache +++ b/templates/local/content.mustache @@ -164,9 +164,9 @@

{{#str}}maincoursepage{{/str}}

{{/hasnavigation}} {{{completionhelp}}} - {{#hasheaderimages}} + {{#hassectionheaderimages}} {{> format_grid/coursestyles }} - {{/hasheaderimages}} + {{/hassectionheaderimages}} {{#stealthwarning}}
{{stealthwarning}}
{{/stealthwarning}} diff --git a/templates/local/content/section/content.mustache b/templates/local/content/section/content.mustache index 9f76c738..4fbd520d 100644 --- a/templates/local/content/section/content.mustache +++ b/templates/local/content/section/content.mustache @@ -28,7 +28,8 @@ "name": "Section title", "title": "Section title", "url": "#", - "ishidden": true + "ishidden": true, + "headinglevel": 3 }, "cmlist": { "cms": [ @@ -39,6 +40,7 @@ "hasname": "true" }, "id": 3, + "cmid": 3, "module": "forum", "anchor": "activity-3", "extraclasses": "newmessages" @@ -51,6 +53,7 @@ "hasname": "true" }, "id": 4, + "cmid": 4, "anchor": "activity-4", "module": "assign", "extraclasses": "" @@ -63,7 +66,7 @@ "iscurrent": true, "currentlink": "This topic", "availability": { - "info": "Hidden from students", + "info": "Hidden from students", "hasavailability": true }, "summary": { @@ -75,107 +78,113 @@ }, "cmcontrols": "[Add an activity or resource]", "iscoursedisplaymultipage": true, - "sectionreturnid": 0, + "sectionreturnnum": 0, "contentcollapsed": false, "insertafter": true, "numsections": 42, "sitehome": false, + "isstealth": false, "highlightedlabel" : "Highlighted" } }} -{{#singleheader}} -{{$ core_courseformat/local/content/section/header }} - {{> core_courseformat/local/content/section/header }} -{{/ core_courseformat/local/content/section/header }} -{{/singleheader}} -{{#header}} -{{$ core_courseformat/local/content/section/header }} - {{> core_courseformat/local/content/section/header }} -{{/ core_courseformat/local/content/section/header }} -{{/header}} -{{#restrictionlock}} -
- {{#pix}}t/unlock, core{{/pix}} +
+ {{#singleheader}} + {{$ core_courseformat/local/content/section/header }} + {{> core_courseformat/local/content/section/header }} + {{/ core_courseformat/local/content/section/header }} + {{/singleheader}} + {{#header}} + {{$ core_courseformat/local/content/section/header }} + {{> core_courseformat/local/content/section/header }} + {{/ core_courseformat/local/content/section/header }} + {{/header}} + {{^singleheader}} + {{#restrictionlock}} +
+ {{#pix}}t/unlock, core{{/pix}} +
+ {{/restrictionlock}} + {{/singleheader}} +
+ {{$ core_courseformat/local/content/section/badges }} + {{> core_courseformat/local/content/section/badges }} + {{/ core_courseformat/local/content/section/badges }}
-{{/restrictionlock}} -
- {{$ core_courseformat/local/content/section/badges }} - {{> core_courseformat/local/content/section/badges }} - {{/ core_courseformat/local/content/section/badges }} -
-{{#collapsemenu}} - -{{/collapsemenu}} -{{#controlmenu}} - {{$ core_courseformat/local/content/section/controlmenu }} - {{> core_courseformat/local/content/section/controlmenu }} - {{/ core_courseformat/local/content/section/controlmenu }} -{{/controlmenu}} -
-{{#gridimage}} -
-
- {{#imageuri}} -
- {{imagealttext}} -
- {{/imageuri}} - {{#generatedimageuri}} -
-
- {{/generatedimageuri}} - {{#imageerror}} -
-

{{imageerror}}

+ {{#collapsemenu}} + - {{/imageerror}} - {{#image}} - - {{/image}} -
+ {{/collapsemenu}} + {{#controlmenu}} + {{$ core_courseformat/local/content/section/controlmenu }} + {{> core_courseformat/local/content/section/controlmenu }} + {{/ core_courseformat/local/content/section/controlmenu }} + {{/controlmenu}} + {{#header}} + {{^controlmenu}} + + {{/controlmenu}} + {{/header}}
-{{/gridimage}} +{{> format_grid/grid_section }}
+ class="content {{^iscoursedisplaymultipage}}{{^sitehome}}course-content-item-content collapse {{^contentcollapsed}}show{{/contentcollapsed}}{{/sitehome}}{{/iscoursedisplaymultipage}}">
- {{#summary}} - {{$ core_courseformat/local/content/section/summary }} - {{> core_courseformat/local/content/section/summary }} - {{/ core_courseformat/local/content/section/summary }} - {{/summary}} - {{#availability}} - {{$ core_courseformat/local/content/section/availability }} - {{> core_courseformat/local/content/section/availability }} - {{/ core_courseformat/local/content/section/availability }} - {{/availability}} + {{#isstealth}} +
+ {{#str}} orphansectionwarning, core_courseformat {{/str}} +
+ {{/isstealth}} + {{#summary}} + {{$ core_courseformat/local/content/section/summary }} + {{> core_courseformat/local/content/section/summary }} + {{/ core_courseformat/local/content/section/summary }} + {{/summary}} + {{#availability}} + {{$ core_courseformat/local/content/section/availability }} + {{> core_courseformat/local/content/section/availability }} + {{/ core_courseformat/local/content/section/availability }} + {{/availability}} +
+ {{#cmsummary}} + {{$ core_courseformat/local/content/section/cmsummary }} + {{> core_courseformat/local/content/section/cmsummary }} + {{/ core_courseformat/local/content/section/cmsummary }} + {{/cmsummary}} + {{#cmlist}} + {{$ core_courseformat/local/content/section/cmlist }} + {{> core_courseformat/local/content/section/cmlist }} + {{/ core_courseformat/local/content/section/cmlist }} + {{/cmlist}} + {{{cmcontrols}}}
-{{#cmsummary}} - {{$ core_courseformat/local/content/section/cmsummary }} - {{> core_courseformat/local/content/section/cmsummary }} - {{/ core_courseformat/local/content/section/cmsummary }} -{{/cmsummary}} -{{#cmlist}} - {{$ core_courseformat/local/content/section/cmlist }} - {{> core_courseformat/local/content/section/cmlist }} - {{/ core_courseformat/local/content/section/cmlist }} -{{/cmlist}} -{{{cmcontrols}}} {{#insertafter}} {{#numsections}} {{$ core_courseformat/local/content/addsection}} diff --git a/version.php b/version.php index 93423a79..9f5bc5b5 100644 --- a/version.php +++ b/version.php @@ -29,19 +29,19 @@ defined('MOODLE_INTERNAL') || die(); // Plugin version. -$plugin->version = 2024032905; +$plugin->version = 2024101500; // Required Moodle version. -$plugin->requires = 2024042200.00; // 4.4 (Build: 20240422). +$plugin->requires = 2024100700.00; // 4.5 (Build: 20241007). // Supported Moodle version. -$plugin->supported = [404, 404]; +$plugin->supported = [405, 405]; // Full name of the plugin. $plugin->component = 'format_grid'; // Software maturity level. -$plugin->maturity = MATURITY_STABLE; +$plugin->maturity = MATURITY_RC; // User-friendly version number. -$plugin->release = '404.1.3'; +$plugin->release = '405.0.1';