Maybe one of you can see what I am obviously overlooking. I created a module. It is an admin/tool. It has an observer that captures course completion events. If it is a specific course I invoke a function of the module to do x,y,x. If it is another specific course that has been completed I do the same--send that info to a function of the module (its lib.php file) to trigger a,b,c. The problem I'm having is I cannot get the function to be acted upon. Yes I have updated the version of my module after each change. Yes I have cleared out the cache. I have tried this on another moodle and have the same problem. The cron is running. There are not debug messages. I've tried namespaces and just calling the function. Same issue. My IDE recognizes the function with and without namespace. Permissions on the file on the server are correct as well as the owner. So I'm obviously missing something that is starring at me. I do not have an issue with capture the event or triggering it. That all works just fine. I am using tracing/logging to ensure that the code works just fine up until it gets to the lib.php function . . . just stops and doesn't go any further.
The structure of my module looks like this:
admin/tool/mytool
admin/tool/mytool/classes/
admin/tool/mytool/classes/form.php
admin/tool/mytool/classes/tool_mytool_observer.php (where I capture the course_completed event and try to invoke a fuction)
admin/tool/mytool/db
admin/tool/mytool/db/events.php
admin/tool/mytool/db/install.xml
admin/tool/mytool/upgrade.php
admin/tool/mytool/lang
admin/tool/mytool/index.php
admin/tool/mytool/lib.php (where the function is I want to use)
admin/tool/mytool/settings.php
admin/tool/mytool/version.php
My code:
admin/tool/classes/tool_mytool_observer.php:
<?php
namespace tool_mytool;
defined('MOODLE_INTERNAL') || die();
class tool_mytool_observer {
public static function ccChanged(\core\event\course_completed $event) {
global $DB;
$courseID = $event->courseid;
$studentID = $event->relateduserid;
if($courseID==6){
//this is the function that I cannot get the code to execute (or any
//other lib.php function for that matter
\tool_mytool\sendNotifications($studentID,'student');
}
}
admin/tool/lib.php:
<?php
namespace tool_mytool;
defined('MOODLE_INTERNAL') || die();
require_once(dirname(__DIR__,3).'/lib/moodlelib.php');
require_once(dirname(__DIR__,3).'/lib/completionlib.php');
function sendNotifications($userID,$userRole){
....
}
So what could be preventing the code from using the functions? I've moved the functions around (I know that sounds stupid) in the lib.php file. I've tried all I know. I was going to try the "includefile" in the events callback file in the db dir but I have written other similar modules using events and had no issues with using functions in their lib.php files.
So I'm at a loss as to what is going on here. Do you see anything?