ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilECSEnrolmentStatusConnector.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
26 {
31  public function getEnrolmentStatus($a_enrole_id = 0, $a_details = false)
32  {
33  if ($a_enrole_id) {
34  $this->path_postfix = '/campusconnect/member_status/' . (int) $a_enrole_id;
35  }
36  if ($a_details && $a_enrole_id) {
37  $this->path_postfix .= '/details';
38  }
39 
40  try {
41  $this->prepareConnection();
42  $this->setHeader(array());
43  if ($a_details) {
44  $this->addHeader('Accept', 'application/json');
45  }
46  $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->getHeader());
47  $res = $this->call();
48 
49  if (strpos($res, 'http') === 0) {
50  $json = file_get_contents($res);
51  $ecs_result = new ilECSResult($json);
52  } else {
53  $ecs_result = new ilECSResult($res);
54  }
55 
56  // Return ECSEContentDetails for details switch
57  if ($a_details) {
58  $details = new ilECSEContentDetails();
59  $this->logger->debug(print_r($res, true));
60  $details->loadFromJson($ecs_result->getResult());
61  return $details;
62  }
63  $enrolment = new ilECSEnrolmentStatus();
64  $enrolment->loadFromJson($ecs_result->getResult());
65  return $enrolment;
66  } catch (ilCurlConnectionException $e) {
67  throw new ilECSConnectorException('Error calling ECS service: ' . $e->getMessage());
68  }
69  }
70 
71 
75  public function addEnrolmentStatus(ilECSEnrolmentStatus $enrolment, $a_target_mid)
76  {
77  $this->logger->info('Add new enrolment status');
78 
79  $this->path_postfix = '/campusconnect/member_status';
80 
81  try {
82  $this->prepareConnection();
83 
84  $this->addHeader('Content-Type', 'application/json');
85  $this->addHeader('Accept', 'application/json');
86  $this->addHeader(ilECSConnector::HEADER_MEMBERSHIPS, (string) $a_target_mid);
87  #$this->addHeader(ilECSConnector::HEADER_MEMBERSHIPS, 1);
88 
89  $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->getHeader());
90  $this->curl->setOpt(CURLOPT_POST, true);
91  $this->curl->setOpt(CURLOPT_POSTFIELDS, json_encode($enrolment, JSON_THROW_ON_ERROR));
92  $ret = $this->call();
93 
94  $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
95 
96  $this->logger->debug(': Checking HTTP status...');
97  if ($info !== self::HTTP_CODE_CREATED) {
98  $this->logger->debug(': Cannot create auth resource, did not receive HTTP 201. ');
99  $this->logger->debug(': POST was: ' . print_r($enrolment, true));
100  $this->logger->debug(': HTTP code: ' . $info);
101  throw new ilECSConnectorException('Received HTTP status code: ' . $info);
102  }
103  $this->logger->debug(': ... got HTTP 201 (created)');
104 
105  $result = new ilECSResult($ret);
106  $enrolment_res = $result->getResult();
107 
108  $this->logger->debug(': ... Received result: ' . print_r($enrolment_res, true));
109 
110  return $enrolment_res;
111  } catch (ilCurlConnectionException $exc) {
112  throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage());
113  }
114  }
115 }
$res
Definition: ltiservices.php:66
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addHeader(string $a_name, string $a_value)
Add Header.
Presentation of ecs content details (http://...campusconnect/courselinks/id/details) ...
Presentation of ecs enrolment status.
Connector for course member ressource.
setHeader(array $a_header_strings)
prepareConnection()
prepare connection
getEnrolmentStatus($a_enrole_id=0, $a_details=false)
Get single directory tree.
addEnrolmentStatus(ilECSEnrolmentStatus $enrolment, $a_target_mid)
Add new enrolment status.