Feature #6763

Add a webservice to check if user subscribed to course

Added by Rory Fogerty almost 7 years ago. Updated over 6 years ago.

Feature implemented
Rory Fogerty
Web services
Target version:
Start date:
Due date:
% Done:


Estimated time:
SCRUM pts - complexity:


Suggest adding the following code to /main/webservices/registration.soap.php

This provides a webservice that checks if a user is subscribed to a course.

/* Register WSUserSubscribedInCourse function */
// Register the data structures used by the service

//prepare input params

// Input params for editing users
        'course'       => array('name' => 'course',     'type' => 'xsd:string'), //Course string code
        'user_id'      => array('name' => 'user_id',    'type' => 'xsd:string'), //Chamilo user_id
        'secret_key'   => array('name' => 'secret_key', 'type' => 'xsd:string')

// Register the method to expose
$server->register('WSUserSubscribedInCourse',                            // method name
    array('UserSubscribedInCourse' => 'tns:UserSubscribedInCourse'),    // input parameters
    array('return' => 'xsd:string'),                                        // output parameters
    'urn:WSRegistration',                                                    // namespace
    'urn:WSRegistration#WSUserSubscribedInCourse',                       // soapaction
    'rpc',                                                                    // style
    'encoded',                                                                // use
    'This service checks if user assigned to course'    // documentation

// Define the method WSUserSubscribedInCourse
function WSUserSubscribedInCourse ($params) {
    global $debug;

    if ($debug) error_log('WSUserSubscribedInCourse');
    if ($debug) error_log('Params '. print_r($params, 1));
    if (!WSHelperVerifyKey($params)) {
        return return_error(WS_ERROR_SECRET_KEY);
    $course_code  = $params['course']; //Course code
    $user_id      = $params['user_id']; //chamilo user id

    // Check if assigned
    return(CourseManager::is_user_subscribed_in_course ($user_id,$course_code));


Also tidy up line 915 as follows to allow a phone number to be inserted.

$phone = $params['phone'];

Associated revisions

Revision 9c9aac37 (diff)
Added by Yannick Warnier over 6 years ago

Add WSUserSubscribedInCourse web service to registration.soap.php - refs #6763



Updated by Yannick Warnier almost 7 years ago

should probably be called isusersubscribedtocoursebycode, as from 1.9.0 on, there is also an int id for each course


Updated by Rory Fogerty almost 7 years ago

Yeah, I thought about that but since the internal process it calls is CourseManager::is_user_subscribed_in_course I thought it best to call it the same to be consistent.


Updated by Yannick Warnier almost 7 years ago

You're right. Let's call an hypothetical new one isUserSubscribedToCourseId() :-)


Updated by Rory Fogerty almost 7 years ago

Suits me.


Updated by Yannick Warnier over 6 years ago

  • Category set to Web services
  • Status changed from New to Feature implemented
  • Assignee set to Rory Fogerty
  • Target version set to 1.9.8
  • % Done changed from 0 to 100

Sent in
I just copy-pasted it, so I assume it works (given you provided it from a working installation, right?)


Updated by Rory Fogerty over 6 years ago

Yep - its an integral part of the processing of signups on and

Also available in: Atom PDF