From ee3e86bde78ea2b58bbe3da4c338be83ee2b2eca Mon Sep 17 00:00:00 2001 From: justinhunt Date: Thu, 24 Mar 2022 04:35:48 +0000 Subject: [PATCH] added course custom fields to variables --- CHANGES.txt | 3 +++ filter.php | 24 +++++++++++++++++++++++- version.php | 4 ++-- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 7cb7b6c..b643a5e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,5 +1,8 @@ Change List ========= +Version 1.4.14(Build 2022032400) +- Added course custom variables to variables to use in filter + Version 1.4.13(Build 2021080600) - fixed issue where numeric variables to dataset where forced as int - fixed issue where in the case of only 1 returned entry in dataset it was not available in JS diff --git a/filter.php b/filter.php index feb1206..b3e3330 100644 --- a/filter.php +++ b/filter.php @@ -272,7 +272,29 @@ function filter_generico_callback(array $link) { //if we have course variables e.g @@COURSE:ID@@ if (strpos($genericotemplate . ' ' . $dataset_vars, '@@COURSE:') !== false) { - $coursevars = get_object_vars($COURSE); + $coursevars=false; + if(!empty($filterprops['courseid']) && is_numeric($filterprops['courseid'] )){ + $thecourse = get_course($filterprops['courseid']); + if($thecourse){ + $coursevars = get_object_vars($thecourse); + //custom fields + if(class_exists('\core_customfield\handler')) { + $handler = \core_customfield\handler::get_handler('core_course', 'course'); + $customfields = $handler->get_instance_data($filterprops['courseid']); + foreach ($customfields as $customfield) { + if (empty($customfield->get_value())) { + continue; + } + $shortname = $customfield->get_field()->get('shortname'); + $coursevars[$shortname] = $customfield->get_value(); + } + } + } + } + if(!$coursevars){ + $coursevars = get_object_vars($COURSE); + } + $coursepropstubs = explode('@@COURSE:', $genericotemplate); $d_stubs = explode('@@COURSE:', $dataset_vars); if ($d_stubs) { diff --git a/version.php b/version.php index 08c280d..ab53a1c 100644 --- a/version.php +++ b/version.php @@ -25,8 +25,8 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2021080600; // The current plugin version (Date: YYYYMMDDXX) +$plugin->version = 2022032400; // The current plugin version (Date: YYYYMMDDXX) $plugin->requires = 2011070100; // Requires this Moodle version $plugin->component = 'filter_generico'; // Full name of the plugin (used for diagnostics) $plugin->maturity = MATURITY_STABLE; -$plugin->release = 'Version 1.4.13(Build 2021080600)'; +$plugin->release = 'Version 1.4.14(Build 2022032400)';