Project

General

Profile

Feature #6763

Add a webservice to check if user subscribed to course

Added by Rory Fogerty about 6 years ago. Updated over 5 years ago.

Status:
Feature implemented
Priority:
Normal
Assignee:
Category:
Web services
Target version:
Start date:
09/10/2013
Due date:
% Done:

100%

Estimated time:
Complexity:
Normal
SCRUM pts - complexity:
?

Description

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
$server->wsdl->addComplexType(
    'UserSubscribedInCourse',
    'complexType',
    'struct',
    'all',
    '',
    array(
        '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 5 years ago

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

History

#1

Updated by Yannick Warnier about 6 years ago

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

#2

Updated by Rory Fogerty about 6 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.

#3

Updated by Yannick Warnier about 6 years ago

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

#4

Updated by Rory Fogerty about 6 years ago

Suits me.

#5

Updated by Yannick Warnier over 5 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 https://github.com/chamilo/chamilo-lms/commit/9c9aac37325a19dd6a850b236b0b69c1de2c32fc
I just copy-pasted it, so I assume it works (given you provided it from a working installation, right?)

#6

Updated by Rory Fogerty over 5 years ago

Yep - its an integral part of the processing of signups on http://learningserver.com and http://bainesconsulting.com

Also available in: Atom PDF