/**
  * Get single directory tree
  * @return array an array of ecs cms directory tree entries
  */
 public function getCourse($course_id, $a_details = false)
 {
     $this->path_postfix = '/campusconnect/courses/' . (int) $course_id;
     if ($a_details and $course_id) {
         $this->path_postfix .= '/details';
     }
     try {
         $this->prepareConnection();
         $this->setHeader(array());
         if ($a_details) {
             $this->addHeader('Accept', 'application/json');
         } else {
             $this->addHeader('Accept', 'text/uri-list');
         }
         $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->getHeader());
         $res = $this->call();
         if (substr($res, 0, 4) == 'http') {
             $json = file_get_contents($res);
             $ecs_result = new ilECSResult($json);
         } else {
             $ecs_result = new ilECSResult($res);
         }
         // Return ECSEContentDetails for details switch
         if ($a_details) {
             include_once './Services/WebServices/ECS/classes/class.ilECSEContentDetails.php';
             $details = new ilECSEContentDetails();
             $details->loadFromJson($ecs_result->getResult());
             return $details;
         }
         // Return json result
         return $ecs_result->getResult();
     } catch (ilCurlConnectionException $e) {
         throw new ilECSConnectorException('Error calling ECS service: ' . $e->getMessage());
     }
 }
 /**
  * Get directory tree
  * @global ilLog $ilLog
  * @return ilECSResult
  * @throws ilECSConnectorException
  */
 public function getDirectoryTrees($a_mid = 0)
 {
     global $ilLog;
     $this->path_postfix = '/campusconnect/directory_trees';
     try {
         $this->prepareConnection();
         $this->setHeader(array());
         $this->addHeader('Accept', 'text/uri-list');
         $this->addHeader('X-EcsQueryStrings', 'all=true');
         if ($a_mid) {
             $this->addHeader('X-EcsReceiverMemberships', $a_mid);
         }
         $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->getHeader());
         $res = $this->call();
         $ecsResult = new ilECSResult($res, false, ilECSResult::RESULT_TYPE_URL_LIST);
         return $ecsResult->getResult();
     } catch (ilCurlConnectionException $exc) {
         throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage());
     }
 }
 /**
  * Get single directory tree
  * @return array an array of ecs cms directory tree entries
  */
 public function getCourse($course_id, $a_details = false)
 {
     $this->path_postfix = '/campusconnect/courses/' . (int) $course_id;
     if ($a_details and $course_id) {
         $this->path_postfix .= '/details';
     }
     try {
         $this->prepareConnection();
         $this->setHeader(array());
         $this->addHeader('Accept', 'text/uri-list');
         $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->getHeader());
         $res = $this->call();
         if (substr($res, 0, 4) == 'http') {
             $json = file_get_contents($res);
             $ecs_result = new ilECSResult($json);
         } else {
             $ecs_result = new ilECSResult($res);
         }
         return $ecs_result->getResult();
     } catch (ilCurlConnectionException $e) {
         throw new ilECSConnectorException('Error calling ECS service: ' . $e->getMessage());
     }
 }
 /**
  * Get resources from ECS server.
  *  
  * 
  *
  * @access public
  * @param string resource "path"
  * @param int e-content id
  * @return object ECSResult 
  * @throws ilECSConnectorException 
  */
 public function getResource($a_path, $a_econtent_id, $a_details_only = false)
 {
     global $ilLog;
     if ($a_econtent_id) {
         $ilLog->write(__METHOD__ . ': Get resource with ID: ' . $a_econtent_id);
     } else {
         $ilLog->write(__METHOD__ . ': Get all resources ...');
     }
     $this->path_postfix = $a_path;
     if ($a_econtent_id) {
         $this->path_postfix .= '/' . (int) $a_econtent_id;
     }
     if ($a_details_only) {
         $this->path_postfix .= '/details';
     }
     try {
         $this->prepareConnection();
         $res = $this->call();
         // Checking status code
         $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
         $ilLog->write(__METHOD__ . ': Checking HTTP status...');
         if ($info != self::HTTP_CODE_OK) {
             $ilLog->write(__METHOD__ . ': Cannot get ressource, did not receive HTTP 200. ');
             throw new ilECSConnectorException('Received HTTP status code: ' . $info);
         }
         $ilLog->write(__METHOD__ . ': ... got HTTP 200 (ok)');
         $result = new ilECSResult($res);
         $result->setHeaders($this->curl->getResponseHeaderArray());
         $result->setHTTPCode($info);
         return $result;
     } catch (ilCurlConnectionException $exc) {
         throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage());
     }
 }
 /**
  * Add new enrolment status
  */
 public function addEnrolmentStatus(ilECSEnrolmentStatus $enrolment, $a_target_mid)
 {
     global $ilLog;
     $ilLog->write(__METHOD__ . ': Add new enrolment status');
     $this->path_postfix = '/campusconnect/member_status';
     try {
         $this->prepareConnection();
         $this->addHeader('Content-Type', 'application/json');
         $this->addHeader('Accept', 'application/json');
         $this->addHeader(ilECSConnector::HEADER_MEMBERSHIPS, $a_target_mid);
         #$this->addHeader(ilECSConnector::HEADER_MEMBERSHIPS, 1);
         $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->getHeader());
         $this->curl->setOpt(CURLOPT_POST, true);
         $this->curl->setOpt(CURLOPT_POSTFIELDS, json_encode($enrolment));
         $ret = $this->call();
         $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
         $ilLog->write(__METHOD__ . ': Checking HTTP status...');
         if ($info != self::HTTP_CODE_CREATED) {
             $ilLog->write(__METHOD__ . ': Cannot create auth resource, did not receive HTTP 201. ');
             $ilLog->write(__METHOD__ . ': POST was: ' . print_r($enrolment, TRUE));
             $ilLog->write(__METHOD__ . ': HTTP code: ' . $info);
             throw new ilECSConnectorException('Received HTTP status code: ' . $info);
         }
         $ilLog->write(__METHOD__ . ': ... got HTTP 201 (created)');
         $result = new ilECSResult($ret);
         $enrolment_res = $result->getResult();
         $ilLog->write(__METHOD__ . ': ... Received result: ' . print_r($enrolment_res, TRUE));
         return $enrolment_res;
     } catch (ilCurlConnectionException $exc) {
         throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage());
     }
 }