在课程结业时更新外部数据库 [英] On Course Completion update external database
问题描述
我的情况;
Moodle中的用户完成了一个课程.一旦发生这种情况,我想更新一个外部数据库.我的理解是每次执行cron作业时都会触发course_completed事件.
A user in Moodle completes a course. I'd like to update an external database once this happens. My understanding is that the course_completed event is triggered every time the cron job is run.
用哪种简单的值(例如,已完成课程的用户名/ID,CourseID以及完成日期)更新外部数据库的最佳方法是什么?
Which is the best approach to update an external database with some simple values e.g Username/ID, CourseID and maybe Date of Completion, of the completed courses?
我宁愿不hacking/cron.php来做到这一点,但如果需要的话,我会这么做!
I'd rather not hack the completion/cron.php to do this, but will if I have to!
推荐答案
您需要创建一个本地插件.
You'll need to create a local plugin.
http://docs.moodle.org/dev/Local_plugins
在/local/myplugnname中创建插件
Create the plugin in /local/myplugnname
创建一个events.php文件
Create an events.php file
/local/mypluginname/db/events.php
有了这个
$handlers = array (
'course_completed' => array (
'handlerfile' => '/local/mypluginname/lib.php',
'handlerfunction' => 'local_mypluginname_course_completed',
'schedule' => 'cron',
'internal' => 1,
),
在这里查看更多信息 http://docs.moodle.org/dev/Events_API #Handling_an_event
您将需要一个version.php文件来安装插件并添加事件处理程序.
You'll need a version.php file to install the plugin and add the event handler.
然后创建一个函数
function local_mypluginname_course_completed($eventdata)
在
/local/mypluginname/lib.pgp
在cron运行时将被调用
This will be called when the cron runs
要了解$ eventdata的内容,请查看
To find out the contents of $eventdata have a look at
events_trigger('course_completed', $this->get_record_data());
在
/completion/completion_completion.php
要更新远程数据库,请查看db身份验证中的代码
To update a remote database have a look at the code in db authentication
/auth/db/auth.php
类似
$mydb = ADONewConnection('mysql');
$mydb->Connect($dbhost, $dbuser, $dbpass, $dbname, false);
$mydb->Execute($insertsql);
$mydb->Close();
这篇关于在课程结业时更新外部数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!