From 01b15235d86e4144e2bfd687088b3824dfcc0f32 Mon Sep 17 00:00:00 2001 From: Gustavo Bazzo Date: Tue, 16 Apr 2024 13:34:10 -0400 Subject: [PATCH] Improve data loading --- src/filter.php | 26 ++++++++++++++++++++------ src/lib.php | 2 +- src/version.php | 4 ++-- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/filter.php b/src/filter.php index c3fcb8b..2a70149 100644 --- a/src/filter.php +++ b/src/filter.php @@ -61,6 +61,8 @@ class filter_recitactivity extends moodle_text_filter { protected $DEFAULT_TARGET = '_self'; /** @var object */ protected $stats = null; + /** @var boolean */ + protected $dataloaded = false; protected const NO_COMPLETION = 0; protected const COMPLETION_NOT_COMPLETED = 1; @@ -93,10 +95,6 @@ public function setup($page, $context) { } $this->dao = filter_recitactivity_dao_factory::getInstance()->getDAO(); - - $this->load_course_teachers($this->courseid); - $this->load_data(); - $this->setStats(); } /** @@ -151,11 +149,21 @@ protected function load_cm_completions() { $this->cmcompletions = $this->dao->load_cm_completions($this->page->course->id); } + protected function load_data(){ + if($this->dataloaded){ + return; + } + + $this->load_course_teachers($this->courseid); + $this->load_coursemodules(); + $this->setStats(); + + $this->dataloaded = true; + } /** * Load course modules list - * */ - protected function load_data() { + protected function load_coursemodules() { global $USER; $modules = get_fast_modinfo($this->courseid); @@ -395,6 +403,12 @@ public function filter($text, array $options = array()) { $matches = $matches[0]; // It will match the wanted RE, for instance [[i/Activité 3]]. + // if no matches then it returns the original text + if(count($matches) == 0){ + return $text; + } + + $this->load_data(); $result = $text; foreach ($matches as $match) { diff --git a/src/lib.php b/src/lib.php index c307340..6902321 100644 --- a/src/lib.php +++ b/src/lib.php @@ -30,6 +30,6 @@ function filter_recitactivity_before_standard_top_of_body_html() { global $PAGE; - $PAGE->requires->js(new moodle_url('/filter/recitactivity/filter.js?v=v1180'), false); + $PAGE->requires->js(new moodle_url('/filter/recitactivity/filter.js'), false); $PAGE->requires->js_init_call('filter_recitactivity_init_vars', array()); } \ No newline at end of file diff --git a/src/version.php b/src/version.php index d3ca4db..10f64d2 100644 --- a/src/version.php +++ b/src/version.php @@ -26,9 +26,9 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2024020101; // The current plugin version (Date: YYYYMMDDXX). +$plugin->version = 2024020102; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2020061500.00; // Moodle 3.9.0 $plugin->component = 'filter_recitactivity'; // Full name of the plugin (used for diagnostics) -$plugin->release = 'v1.18.2-stable'; +$plugin->release = 'v1.18.3-stable'; $plugin->maturity = MATURITY_STABLE; $plugin->supported = [39, 401]; // Moodle 3.9.x, 3.10.x, 3.11.x and 4.0.x are supported. \ No newline at end of file