Created
June 23, 2021 07:35
-
-
Save sharpchi/ca0c4403809faf7b5a4094ce70b1caa1 to your computer and use it in GitHub Desktop.
Overriding a webservice for the Moodle activity chooser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A little something for your Moodle plugin to filter the activity chooser. | |
* @param object $function Details of the function to be called. | |
* @param array $params Parameters passed by the ajax call. | |
* @return boolean|array If the callback returns anything other than false, we assume it replaces the original function. | |
*/ | |
function theme_mytheme_override_webservice_execution($function, $params) { | |
if ($function->name === 'core_course_get_course_content_items') { | |
$courseid = $params[0]; // This should be courseid. | |
$result = call_user_func_array([$function->classname, $function->methodname], $params); | |
foreach ($result['content_items'] as $index => $contentitem) { | |
if (!canuse($contentitem->name, $courseid)) { | |
unset($result['content_items'][$index]); | |
} | |
} | |
return $result; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment