Skip to content

Commit

Permalink
fixed issue with course custom fields not processing properly
Browse files Browse the repository at this point in the history
  • Loading branch information
justinhunt committed Dec 19, 2022
1 parent 13c8628 commit 0a1b399
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
33 changes: 18 additions & 15 deletions filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,27 +273,30 @@ function filter_generico_callback(array $link) {
//if we have course variables e.g @@COURSE:ID@@
if (strpos($genericotemplate . ' ' . $dataset_vars, '@@COURSE:') !== false) {
$coursevars=false;
if(!empty($filterprops['courseid']) && is_numeric($filterprops['courseid'] )){
if(!empty($filterprops['courseid']) && is_numeric($filterprops['courseid'] )) {
$thecourse = get_course($filterprops['courseid']);
if($thecourse){
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();
}
}else{
$coursevars = get_object_vars($COURSE);
$filterprops['courseid']=$COURSE->id;
}
if($coursevars){
//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);
Expand Down
2 changes: 1 addition & 1 deletion presets/codebox.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"key":"codebox","name":"codebox","instructions":"This uses highlight js to display code snippets nicely. Put code in between codebox generico tags. You might find putting code and generico tags inside <pre> tags works well. Codebox can optionally prevent them being copied from browser. Set the language variable to one of css, html, php or javascript.","requirecss":"//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/styles/github.min.css","requirejs":"//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/highlight.min.js","shim":"","defaults":"language=html|css|php|javascript,allow_copy=true|false","amd":"1","body":"<code id=\"@@AUTOID@@\" class=\"@@language@@\">","bodyend":"</code>","script":"$('#' + @@AUTOID@@).each(function(i, block) {\n hljs.highlightBlock(block);\n $(block).bind('copy paste cut', function (e) {\n if(@@allow_copy@@=='false'){\n e.preventDefault(); //disable cut,copy,paste\n return false;\n }\n });\n});","style":"code.css{\n background-color: aliceblue;\n}\ncode.html{\n background-color: antiquewhite;\n}\ncode.php{\n background-color: lavender;\n}\ncode.javascript{\n background-color: khaki;\n}","dataset":"","datasetvars":"","alternate":"","alternateend":"","version":"1.0.1"}
{"key":"codebox","name":"Codebox","instructions":"This uses highlight js to display code snippets nicely. Put code in between codebox generico tags. You might find putting code and generico tags inside <pre> tags works well. Codebox can optionally prevent them being copied from browser. Set the language variable to one of css, html, php or javascript.","requirecss":"//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.6.0/styles/default.min.css","requirejs":"//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.6.0/highlight.min.js","shim":"hljs","defaults":"language=html|css|php|javascript,allow_copy=true|false","amd":"1","body":"<code id=\"@@AUTOID@@\" class=\"@@language@@\">","bodyend":"</code>","script":"$('#' + @@AUTOID@@).each(function(i, block) {\n hljs.highlightElement(block);\n $(block).bind('copy paste cut', function (e) {\n if(@@allow_copy@@=='false'){\n e.preventDefault(); //disable cut,copy,paste\n return false;\n }\n });//end of bind \n});//end of each","style":"code.css{\n background-color: aliceblue;\n}\ncode.html{\n background-color: antiquewhite;\n}\ncode.php{\n background-color: lavender;\n}\ncode.javascript{\n background-color: khaki;\n}","dataset":"","datasetvars":"","alternate":"","alternateend":"","version":"1.0.2"}

0 comments on commit 0a1b399

Please sign in to comment.