ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
4include_once './Services/WebServices/ECS/classes/class.ilECSConnector.php';
5include_once './Services/WebServices/ECS/classes/class.ilECSConnectorException.php';
6include_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['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 $ilLog;
83
84 $ilLog->write(__METHOD__ . ': Add new enrolment status');
85
86 $this->path_postfix = '/campusconnect/member_status';
87
88 try {
89 $this->prepareConnection();
90
91 $this->addHeader('Content-Type', 'application/json');
92 $this->addHeader('Accept', 'application/json');
93 $this->addHeader(ilECSConnector::HEADER_MEMBERSHIPS, $a_target_mid);
94 #$this->addHeader(ilECSConnector::HEADER_MEMBERSHIPS, 1);
95
96 $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->getHeader());
97 $this->curl->setOpt(CURLOPT_POST, true);
98 $this->curl->setOpt(CURLOPT_POSTFIELDS, json_encode($enrolment));
99 $ret = $this->call();
100
101 $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
102
103 $ilLog->write(__METHOD__ . ': Checking HTTP status...');
104 if ($info != self::HTTP_CODE_CREATED) {
105 $ilLog->write(__METHOD__ . ': Cannot create auth resource, did not receive HTTP 201. ');
106 $ilLog->write(__METHOD__ . ': POST was: ' . print_r($enrolment, true));
107 $ilLog->write(__METHOD__ . ': HTTP code: ' . $info);
108 throw new ilECSConnectorException('Received HTTP status code: ' . $info);
109 }
110 $ilLog->write(__METHOD__ . ': ... got HTTP 201 (created)');
111
112 $result = new ilECSResult($ret);
113 $enrolment_res = $result->getResult();
114
115 $ilLog->write(__METHOD__ . ': ... Received result: ' . print_r($enrolment_res, true));
116
117 return $enrolment_res;
118 } catch (ilCurlConnectionException $exc) {
119 throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage());
120 }
121 }
122}
$result
An exception for terminatinating execution or to throw for unit testing.
addHeader($a_name, $a_value)
Add Header.
prepareConnection()
prepare connection
setHeader($a_header_strings)
Presentation of ecs content details (http://...campusconnect/courselinks/id/details)
Connector for course member ressource.
addEnrolmentStatus(ilECSEnrolmentStatus $enrolment, $a_target_mid)
Add new enrolment status.
getEnrolmentStatus($a_enrole_id=0, $a_details=false)
Get single directory tree.
__construct(ilECSSetting $settings=null)
Constructor.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
$info
Definition: index.php:5
$ret
Definition: parser.php:6
foreach($_POST as $key=> $value) $res