ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilECSEnrolmentStatusConnector.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once './Services/WebServices/ECS/classes/class.ilECSConnector.php';
5 include_once './Services/WebServices/ECS/classes/class.ilECSConnectorException.php';
6 include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php';
7 
15 {
16 
21  public function __construct(ilECSSetting $settings = null)
22  {
23  parent::__construct($settings);
24  }
25 
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 and $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  } else {
46  #$this->addHeader('Accept', 'text/uri-list');
47  }
48  $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->getHeader());
49  $res = $this->call();
50 
51  if (substr($res, 0, 4) == 'http') {
52  $json = file_get_contents($res);
53  $ecs_result = new ilECSResult($json);
54  } else {
55  $ecs_result = new ilECSResult($res);
56  }
57 
58  // Return ECSEContentDetails for details switch
59  if ($a_details) {
60  include_once './Services/WebServices/ECS/classes/class.ilECSEContentDetails.php';
61  $details = new ilECSEContentDetails();
62  $GLOBALS['DIC']['ilLog']->write(print_r($res, true));
63  $details->loadFromJson($ecs_result->getResult());
64  return $details;
65  } else {
66  include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php';
67  $enrolment = new ilECSEnrolmentStatus();
68  $enrolment->loadFromJson($ecs_result->getResult());
69  return $enrolment;
70  }
71  } catch (ilCurlConnectionException $e) {
72  throw new ilECSConnectorException('Error calling ECS service: ' . $e->getMessage());
73  }
74  }
75 
76 
80  public function addEnrolmentStatus(ilECSEnrolmentStatus $enrolment, $a_target_mid)
81  {
82  global $DIC;
83 
84  $ilLog = $DIC['ilLog'];
85 
86  $ilLog->write(__METHOD__ . ': Add new enrolment status');
87 
88  $this->path_postfix = '/campusconnect/member_status';
89 
90  try {
91  $this->prepareConnection();
92 
93  $this->addHeader('Content-Type', 'application/json');
94  $this->addHeader('Accept', 'application/json');
95  $this->addHeader(ilECSConnector::HEADER_MEMBERSHIPS, $a_target_mid);
96  #$this->addHeader(ilECSConnector::HEADER_MEMBERSHIPS, 1);
97 
98  $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->getHeader());
99  $this->curl->setOpt(CURLOPT_POST, true);
100  $this->curl->setOpt(CURLOPT_POSTFIELDS, json_encode($enrolment));
101  $ret = $this->call();
102 
103  $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
104 
105  $ilLog->write(__METHOD__ . ': Checking HTTP status...');
106  if ($info != self::HTTP_CODE_CREATED) {
107  $ilLog->write(__METHOD__ . ': Cannot create auth resource, did not receive HTTP 201. ');
108  $ilLog->write(__METHOD__ . ': POST was: ' . print_r($enrolment, true));
109  $ilLog->write(__METHOD__ . ': HTTP code: ' . $info);
110  throw new ilECSConnectorException('Received HTTP status code: ' . $info);
111  }
112  $ilLog->write(__METHOD__ . ': ... got HTTP 201 (created)');
113 
114  $result = new ilECSResult($ret);
115  $enrolment_res = $result->getResult();
116 
117  $ilLog->write(__METHOD__ . ': ... Received result: ' . print_r($enrolment_res, true));
118 
119  return $enrolment_res;
120  } catch (ilCurlConnectionException $exc) {
121  throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage());
122  }
123  }
124 }
$result
global $DIC
Definition: saml.php:7
__construct(ilECSSetting $settings=null)
Constructor.
Presentation of ecs content details (http://...campusconnect/courselinks/id/details) ...
foreach($_POST as $key=> $value) $res
setHeader($a_header_strings)
Connector for course member ressource.
$ret
Definition: parser.php:6
addHeader($a_name, $a_value)
Add Header.
prepareConnection()
prepare connection
$info
Definition: index.php:5
getEnrolmentStatus($a_enrole_id=0, $a_details=false)
Get single directory tree.
addEnrolmentStatus(ilECSEnrolmentStatus $enrolment, $a_target_mid)
Add new enrolment status.
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.