Skip to content

Commit

Permalink
Improve data loading
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavobazzo committed Apr 16, 2024
1 parent cd75ab8 commit 01b1523
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
26 changes: 20 additions & 6 deletions src/filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
4 changes: 2 additions & 2 deletions src/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit 01b1523

Please sign in to comment.