Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagephp
title1. Verify a user is enrolled
linenumberstrue
<?php
// Login to the site and request the access token
$curl = curl_init('http://your-domain.com/restws/session/token');
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "restws_webservice:webservice_password"); // Your web service user credentials go here.
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$token = curl_exec($curl);
// The token looks like "q71OBx05wtECfjA0KmXf6wiktewrywNhkMZv-OcfyOA%"

// Verify if the user is enrolled in the course
$curl = curl_init("http://your-domain.com/course_enrollment.json?uid=200&nid=300");
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-CSRF-Token: $token", "Content-Type: application/json"));
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "restws_webservice:webservice_password"); //Your credentials go here
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);

$json = curl_exec($curl);
$response = json_decode($json);

 

The verification request will return an array of information, including any records found to match the given criteria. The response array is structured to handle paginated requests, and includes a 'list' of the records currently on this page.

Code Block
languagephp
titleVerification Response
linenumberstrue
stdClass Object
(
    [self] => http://your-domain.com/course_enrollment?uid=200&nid=310 // The current page the list value displaying information
    [first] => http://your-domain.com/course_enrollment?uid=200&nid=310&page=0
    [last] => http://your-domain.com/course_enrollment?uid=200&nid=310&page=0
    [list] => Array
        (
            [0] => stdClass Object
                (
                    [eid] => 185
                    [nid] => stdClass Object
                        (
                            [uri] => http://your-domain.com/node/310
                            [id] => 310
                            [resource] => node
                            [uuid] => 9aabcf09-58c3-4679-85b3-c5f7ddc93ac6
                        )

                    [uid] => stdClass Object
                        (
                            [uri] => http://your-domain.com/user/200
                            [id] => 200
                            [resource] => user
                            [uuid] => ba5bc8af-25d7-48de-bb54-87ae70ac33b5
                        )

                    [enrollmenttype] => 
                    [status] => 1
                    [created] => 1459800985
                    [timestamp] => 1459800985
                    [enroll_end] => 0
                    [code] => 
                    [user_type] => 
                    [data] => 
                    [feed_nid] => 
                )

        )

)

 

Due to the fact that the verification request above included the uid and nid parameters, if an enrollment exists, there will be only one record in the response list, as a user cannot have multiple enrollment records per course in EthosCE. The example above shows a response where user 200 does have an enrollment in course node 310. If no record is present, the 'list' array will be empty.  Continuing from section #1:

...