Skip to content

Commit

Permalink
Merge pull request #28 from bdecentgmbh/MOODLE_404_STABLE
Browse files Browse the repository at this point in the history
Call it 1.6 R3
  • Loading branch information
stefanscholz authored Dec 9, 2024
2 parents b4f7a4c + 7c38752 commit f870d27
Show file tree
Hide file tree
Showing 41 changed files with 1,311 additions and 550 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Moodle Plugin CI

on: [push, pull_request]
on: [pull_request]

jobs:
test:
runs-on: ubuntu-20.04
runs-on: ubuntu-24.04

services:
postgres:
Expand All @@ -28,17 +28,17 @@ jobs:
fail-fast: false
matrix:
include:
- php: '8.0'
moodle-branch: 'MOODLE_403_STABLE'
database: 'pgsql'
- php: '8.0'
moodle-branch: 'MOODLE_402_STABLE'
- php: '8.2'
moodle-branch: 'MOODLE_404_STABLE'
database: 'mariadb'
- php: '8.0'
moodle-branch: 'MOODLE_401_STABLE'
- php: '8.2'
moodle-branch: 'MOODLE_404_STABLE'
database: 'pgsql'
- php: '8.1'
moodle-branch: 'MOODLE_404_STABLE'
database: 'pgsql'
- php: '7.4'
moodle-branch: 'MOODLE_400_STABLE'
- php: '8.1'
moodle-branch: 'MOODLE_404_STABLE'
database: 'mariadb'

steps:
Expand Down
2 changes: 1 addition & 1 deletion amd/build/designer_section.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion amd/build/designer_section.min.js.map

Large diffs are not rendered by default.

12 changes: 0 additions & 12 deletions amd/src/designer_section.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,6 @@
};
this.expandSection();

if ($('.course-type-flow').length > 0) {
$('.collapse').on('show.bs.collapse', function() {
$(this).parents('li.section').addClass('stack-header-collapsing');
var sectionid = $(this).parents('li.section').attr('id');
var section = document.getElementById(sectionid);
var distance = section.offsetTop - document.body.scrollTop;
setTimeout(() => window.scroll(0, distance), 50);
}).on('shown.bs.collapse', function() {
$(this).parents('li.section').removeClass('stack-header-collapsing');
});
}

var contactModal = document.getElementsByClassName('toggle-contact-button');
Array.from(contactModal).forEach(function(element) {
element.addEventListener('click', function(e) {
Expand Down
6 changes: 4 additions & 2 deletions backup/moodle2/restore_format_designer_plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,13 @@ protected function after_restore_section() {
}

// Restore the courseheaderbgimage.
$this->add_related_files('local_designer', 'courseheaderbgimage', null, null, $this->step->get_task()->get_old_courseid());
$this->add_related_files('local_designer', 'courseheaderbgimage', null, null,
$this->step->get_task()->get_old_courseid());
// Restore the coursebgimage.
$this->add_related_files('local_designer', 'coursebgimage', null, null, $this->step->get_task()->get_old_courseid());
// Restore the additionalcontent.
$this->add_related_files('local_designer', 'additionalcontent', null, null, $this->step->get_task()->get_old_courseid());
$this->add_related_files('local_designer', 'additionalcontent', null, null,
$this->step->get_task()->get_old_courseid());
// Restore the prerequisiteinfo.
$this->add_related_files('local_designer', 'prerequisiteinfo', null, null, $this->step->get_task()->get_old_courseid());
}
Expand Down
108 changes: 108 additions & 0 deletions classes/cache/loader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Format Designer - Custom cache loader for the smart menus.
*
* @package format_designer
* @copyright 2023 bdecent GmbH <https://bdecent.de>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace format_designer\cache;

defined('MOODLE_INTERNAL') || die();

require_once($CFG->dirroot.'/cache/classes/loaders.php');

/**
* Custom cache loader to handle the smart menus and items deletion.
*/
class loader extends \cache_application {

/**
* Delete the cached menus or menu items for all of its users.
*
* Fetch the cache store, generate the keys with menu or item id and keyword of user cache.
* Get the list of cached files by their filename, filenames are stored in the format of "menuid/itemid_u_ userid".
* Generate the key with menu/item id and the keyword of "_u" to get list of all users cache file for this menu/item.
*
* Delete all the files using delete_many method.
*
* @param int $id ID of the menu or item.
* @return void
*/
public function delete_vaild_section_completed_cache($courseid, $sectionid = 0) {
$store = $this->get_store();
$prefix = "v_s_c_c_{$courseid}";
if ($list = $store->find_by_prefix($prefix)) {
$keys = array_map(function($key) {
$key = current(explode('-', $key));
return $key;
}, $list);
$this->delete_many($keys);
}
}


public function delete_user_section_completed_cache($courseid, $sectionid = 0, $userid = 0) {
$prefix = "s_c_c_{$courseid}";
$this->delete_prefix_cache($prefix);
}


public function delete_due_overdue_activities_count($courseid, $userid = 0) {
$prefix = "d_o_a_c_c{$courseid}";
if ($userid) {
$prefix .= "_u{$userid}";
}
$this->delete_prefix_cache($prefix);
}


public function delete_course_progress_uncompletion_criteria($courseid, $userid = 0) {
$prefix = "u_c_c_s{$courseid}";
if ($userid) {
$prefix .= "_u{$userid}";
}
$this->delete_prefix_cache($prefix);
}

public function delete_criteria_progress($courseid, $userid = 0) {
$prefix = "c_p_c{$courseid}";
if ($userid) {
$prefix .= "_u_{$userid}";
}
$this->delete_prefix_cache($prefix);
}


public function delete_prerequisites_courses() {
$prefix = "data_prereq_main_c";
$this->delete_prefix_cache($prefix);
}

public function delete_prefix_cache($prefix) {
$store = $this->get_store();
if ($list = $store->find_by_prefix($prefix)) {
$keys = array_map(function($key) {
$key = current(explode('-', $key));
return $key;
}, $list);
$this->delete_many($keys);
}
}
}
164 changes: 162 additions & 2 deletions classes/events.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

namespace format_designer;

require_once($CFG->dirroot . "/course/format/designer/lib.php");


/**
* Designer format event observer.
*/
Expand All @@ -42,14 +45,18 @@ public static function course_section_created($event) {
$sectionid = $data['objectid'];
$sectionnum = $data['other']['sectionnum'];
$contextid = $data['contextid'];
$courseid = $data['courseid'];;
$courseid = $data['courseid'];
$filearea = 'sectiondesignbackground';
$option = get_config('format_designer', 'sectiondesignerbackgroundimage');
$coursecontext = \context_course::instance($courseid);

if (course_get_format($courseid)->get_course()->format !== 'designer') {
return true;
}

// course_section_cache_updated.
self::course_section_cache_updated($courseid, $sectionid);

$format = course_get_format($courseid);
$options = $format->section_format_options();
$sectiondata = ['id' => $sectionid];
Expand All @@ -58,8 +65,161 @@ public static function course_section_created($event) {
$sectiondata[$name] = get_config('format_designer', $name);
}
}
if (!defined('NO_OUTPUT_BUFFERING') || (defined('NO_OUTPUT_BUFFERING') && !NO_OUTPUT_BUFFERING)) {
if (!defined('NO_OUTPUT_BUFFERING') || (defined('NO_OUTPUT_BUFFERING') && !NO_OUTPUT_BUFFERING)
&& (!defined('AJAX_SCRIPT') || AJAX_SCRIPT == '0')) {
$format->update_section_format_options($sectiondata);
}
}

/**
* After course deleted, deleted the format_designer_options data related to the format_designer options.
*
* @param object $event
* @return void
*/
public static function course_deleted($event) {
global $DB;
$courseid = $event->courseid;
$DB->delete_records('format_designer_options', ['courseid' => $courseid]);
$cache = format_designer_get_cache_object();
$cache->delete_prerequisites_courses();
self::course_cache_updated($courseid);
}

public static function course_completion_updated($event) {
$data = $event->get_data();
$courseid = $data['courseid'];
if (course_get_format($courseid)->get_course()->format !== 'designer') {
return true;
}
self::course_cache_updated($courseid);
}

public static function course_updated($event) {
$courseid = $event->courseid;
if (course_get_format($courseid)->get_course()->format !== 'designer') {
return true;
}
self::course_cache_updated($courseid);
}

public static function course_completed($event) {
$userid = $event->relateduserid;
$courseid = $event->courseid;
if (course_get_format($courseid)->get_course()->format !== 'designer') {
return true;
}
self::course_user_cache_updated($courseid, $userid);
}

public static function course_module_completion_updated($event) {
$userid = $event->relateduserid;
$courseid = $event->courseid;
if (course_get_format($courseid)->get_course()->format !== 'designer') {
return true;
}
self::course_user_cache_updated($courseid, $userid);
}


public static function course_module_created($event) {
self::course_section_module_cache_updated($event->courseid, $event->objectid);
}

/**
* After course module deleted, deleted the format_designer_options data related to the format_designer options.
*
* @param object $event
* @return void
*/
public static function course_module_deleted($event) {
global $DB;
$courseid = $event->courseid;
if (course_get_format($courseid)->get_course()->format !== 'designer') {
return true;
}
$cmid = $event->objectid;
$DB->delete_records('format_designer_options', ['courseid' => $courseid, 'cmid' => $cmid]);

// Clear cache.
self::course_section_module_cache_updated($event->courseid, $event->objectid);
}

public static function course_module_updated($event) {
self::course_section_module_cache_updated($event->courseid, $event->objectid);
}


public static function course_section_deleted($event) {
$data = $event->get_data();
$sectionid = $data['objectid'];
$courseid = $data['courseid'];
self::course_section_cache_updated($courseid, $sectionid);
}

public static function course_section_updated($event) {
$data = $event->get_data();
$sectionid = $data['objectid'];
$courseid = $data['courseid'];
self::course_section_cache_updated($courseid, $sectionid);
}

public static function course_cache_updated($courseid) {
$cache = format_designer_get_cache_object();
$cache->delete_vaild_section_completed_cache($courseid);
$cache->delete_user_section_completed_cache($courseid);
$cache->delete_course_progress_uncompletion_criteria($courseid);
$cache->delete_due_overdue_activities_count($courseid);
$cache->delete_criteria_progress($courseid);
$cache->delete("g_c_a{$courseid}");
$cache->delete("g_c_s_ic{$courseid}");
}


public static function course_user_cache_updated($courseid , $userid) {
$cache = format_designer_get_cache_object();
$cache->delete_vaild_section_completed_cache($courseid);
$cache->delete_user_section_completed_cache($courseid);
$cache->delete_course_progress_uncompletion_criteria($courseid, $userid);
$cache->delete_due_overdue_activities_count($courseid, $userid);
$cache->delete_criteria_progress($courseid, $userid);
$cache->delete("g_c_a{$courseid}");
$cache->delete("g_c_s_ic{$courseid}");
}


public static function course_section_module_cache_updated($courseid, $cmid, $sectionid = 0) {
global $DB;

if (course_get_format($courseid)->get_course()->format !== 'designer') {
return true;
}

$cm = $DB->get_record("course_modules", ['id' => $cmid]);
// Clear cache.
$cache = format_designer_get_cache_object();
$cache->delete_vaild_section_completed_cache($courseid);
$cache->delete_user_section_completed_cache($courseid);
$cache->delete_course_progress_uncompletion_criteria($courseid);
$cache->delete_due_overdue_activities_count($courseid);
$cache->delete_criteria_progress($courseid);
$cache->delete("fdo_cm_j_{$courseid}");
$cache->delete("g_c_a{$courseid}");
$cache->delete("g_c_s_ic{$courseid}");
}

public static function course_section_cache_updated($courseid, $sectionid) {
if (course_get_format($courseid)->get_course()->format !== 'designer') {
return true;
}
// Clear cache.
$cache = format_designer_get_cache_object();
$cache->delete_vaild_section_completed_cache($courseid, $sectionid);
$cache->delete_user_section_completed_cache($courseid, $sectionid);
$cache->delete_due_overdue_activities_count($courseid);
$cache->delete_course_progress_uncompletion_criteria($courseid);
$cache->delete_criteria_progress($courseid);
$cache->delete("g_c_a{$courseid}");
$cache->delete("g_c_s_ic{$courseid}");
}
}
3 changes: 1 addition & 2 deletions classes/external/set_section_options.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ public static function get_module($id, $sectionid, $sectionreturn = null) {
$renderer = $PAGE->get_renderer('format_designer');

$format = course_get_format($course);
$sectiontype = $format->get_section_option($sectionid, 'sectiontype') ?:
get_config('format_designer', 'sectiontype');
$sectiontype = $format->get_section_option($sectionid, 'sectiontype') ?: get_config('format_designer', 'sectiontype');

$section = (object) ['sectiontype' => $sectiontype];
$cmlistdata = $renderer->render_course_module($cm, $sectionreturn, [], $section);
Expand Down
Loading

0 comments on commit f870d27

Please sign in to comment.