nguyentran nguyentran - 6 months ago 12
PHP Question

How to add more mnet service using moodle site base

Currently, moodle support 4 mnet services

1. Remote enrolment service
2. Portfolio services
3. SSO (Identity Provider)
4. SSO (Service Provider)


to add more mnet service, I need to manually add code for admin/mnet/service.php and then add new in mnet/service (like existing service mnetservice_enrol).

I intent to add new service for retrive course detail information from mnet peer. get_remote_courses method is return course overview only not course detail.

I can not find any document about this is moodle offical site. Is there any toturial about this? or some advise from expert?

Answer

We can add more mnet service by adding mnet.php in yourplugin/db with format:

$publishes = array(
    'mnet_enrol' => array(
        'apiversion' => 1,
        'classname'  => 'enrol_mnet_mnetservice_enrol',
        'filename'   => 'enrol.php',
        'methods'    => array(
            'available_courses',
            'user_enrolments',
            'enrol_user',
            'unenrol_user',
            'course_enrolments',
            'category_enrolments'
        ),
    ),
);
$subscribes = array(
    'mnet_enrol' => array(
        'available_courses' => 'enrol/mnet/enrol.php/available_courses',
        'user_enrolments'   => 'enrol/mnet/enrol.php/user_enrolments',
        'enrol_user'        => 'enrol/mnet/enrol.php/enrol_user',
        'unenrol_user'      => 'enrol/mnet/enrol.php/unenrol_user',
        'course_enrolments' => 'enrol/mnet/enrol.php/course_enrolments',
        'category_enrolments'=>'enrol/mnet/enrol.php/category_enrolments'
    ),
);

New mnet service function is store in mnet_remote_rpc table:

+---------------------+----------------------------------------------+
| functionname        | xmlrpcpath                                   |
+---------------------+----------------------------------------------+
| user_authorise      | auth/mnet/auth.php/user_authorise            |
| keepalive_server    | auth/mnet/auth.php/keepalive_server          |
| kill_children       | auth/mnet/auth.php/kill_children             |
| refresh_log         | auth/mnet/auth.php/refresh_log               |
| fetch_user_image    | auth/mnet/auth.php/fetch_user_image          |
| fetch_theme_info    | auth/mnet/auth.php/fetch_theme_info          |
| update_enrolments   | auth/mnet/auth.php/update_enrolments         |
| keepalive_client    | auth/mnet/auth.php/keepalive_client          |
| kill_child          | auth/mnet/auth.php/kill_child                |
| available_courses   | enrol/mnet/enrol.php/available_courses       |
| user_enrolments     | enrol/mnet/enrol.php/user_enrolments         |
| enrol_user          | enrol/mnet/enrol.php/enrol_user              |
| unenrol_user        | enrol/mnet/enrol.php/unenrol_user            |
| course_enrolments   | enrol/mnet/enrol.php/course_enrolments       |
| send_content_intent | portfolio/mahara/lib.php/send_content_intent |
| send_content_ready  | portfolio/mahara/lib.php/send_content_ready  |
| category_enrolments | enrol/mnet/enrol.php/category_enrolments     |
+---------------------+----------------------------------------------+

it the same with adding new web service. To update new service you need to increase version in version.php.

Comments