Versions Compared

Key

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

Using the EthosCE Web Services feature, users have the ability to update enrollment group course lists via a PUT update call.

...

title
Info

Warning!

The list sent in field_enrollment_group_courses, is a complete update of values, it is not additive. For instance, given an enrollment group with 6 courses associated, node ids 101 - 106, if an update is made containing only 3 values, node ids 201 - 203, only the 3 newly sent courses will appear under Activities. The original 6 courses will no longer be associated with the Enrollment group, howeverhowever, they will remain in the system, with all associated learner data.

...

The PHP/Curl script below will update the the enrollment  group course list of node id 27 to the course list of nodes 15, 16, and 17.

...

...

Updating courses in an enrollment group
Code Block
languagephp
<?php
$domain = 'your-domain.com';
$userpass = 'restws_webservice:restws_webservice';

// Build a course to send, in JSON. The fields and allowed values are available on the full documentation site.
$course_list = array(
  "field_enrollment_group_courses" => array(
    array('id' => 15),
    array('id' => 16),
    array('id' => 17),
  ),
);
$enrollment_group_nid = 3112;
$json = json_encode($course_list);
$curl = curl_init('http://' . $domain . '/node/' . $enrollment_group_nid);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, $userpass); //Your credentials go here
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
$http_return = curl_exec($curl);
$response = json_decode($http_return);
print_r($response);