ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  {
35  $this->path_postfix = '/campusconnect/member_status/'. (int) $a_enrole_id;
36  }
37  if($a_details and $a_enrole_id)
38  {
39  $this->path_postfix .= '/details';
40  }
41 
42  try {
43 
44  $this->prepareConnection();
45  $this->setHeader(array());
46  if($a_details)
47  {
48  $this->addHeader('Accept', 'application/json');
49  }
50  else
51  {
52  #$this->addHeader('Accept', 'text/uri-list');
53  }
54  $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->getHeader());
55  $res = $this->call();
56 
57  if(substr($res, 0, 4) == 'http')
58  {
59  $json = file_get_contents($res);
60  $ecs_result = new ilECSResult($json);
61  }
62  else
63  {
64  $ecs_result = new ilECSResult($res);
65  }
66 
67  // Return ECSEContentDetails for details switch
68  if($a_details)
69  {
70  include_once './Services/WebServices/ECS/classes/class.ilECSEContentDetails.php';
71  $details = new ilECSEContentDetails();
72  $GLOBALS['ilLog']->write(print_r($res,true));
73  $details->loadFromJson($ecs_result->getResult());
74  return $details;
75  }
76  else
77  {
78  include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php';
79  $enrolment = new ilECSEnrolmentStatus();
80  $enrolment->loadFromJson($ecs_result->getResult());
81  return $enrolment;
82  }
83  }
84  catch(ilCurlConnectionException $e)
85  {
86  throw new ilECSConnectorException('Error calling ECS service: '.$e->getMessage());
87  }
88  }
89 
90 
94  public function addEnrolmentStatus(ilECSEnrolmentStatus $enrolment, $a_target_mid)
95  {
96  global $ilLog;
97 
98  $ilLog->write(__METHOD__.': Add new enrolment status');
99 
100  $this->path_postfix = '/campusconnect/member_status';
101 
102  try
103  {
104  $this->prepareConnection();
105 
106  $this->addHeader('Content-Type', 'application/json');
107  $this->addHeader('Accept', 'application/json');
108  $this->addHeader(ilECSConnector::HEADER_MEMBERSHIPS, $a_target_mid);
109  #$this->addHeader(ilECSConnector::HEADER_MEMBERSHIPS, 1);
110 
111  $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->getHeader());
112  $this->curl->setOpt(CURLOPT_POST,true);
113  $this->curl->setOpt(CURLOPT_POSTFIELDS,json_encode($enrolment));
114  $ret = $this->call();
115 
116  $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
117 
118  $ilLog->write(__METHOD__.': Checking HTTP status...');
119  if($info != self::HTTP_CODE_CREATED)
120  {
121  $ilLog->write(__METHOD__.': Cannot create auth resource, did not receive HTTP 201. ');
122  $ilLog->write(__METHOD__.': POST was: '.print_r($enrolment,TRUE));
123  $ilLog->write(__METHOD__.': HTTP code: '.$info);
124  throw new ilECSConnectorException('Received HTTP status code: '.$info);
125  }
126  $ilLog->write(__METHOD__.': ... got HTTP 201 (created)');
127 
128  $result = new ilECSResult($ret);
129  $enrolment_res = $result->getResult();
130 
131  $ilLog->write(__METHOD__.': ... Received result: '.print_r($enrolment_res,TRUE));
132 
133  return $enrolment_res;
134  }
135  catch(ilCurlConnectionException $exc)
136  {
137  throw new ilECSConnectorException('Error calling ECS service: '.$exc->getMessage());
138  }
139 
140  }
141 }
142 ?>
$result
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
__construct(ilECSSetting $settings=null)
Constructor.
Presentation of ecs content details (http://...campusconnect/courselinks/id/details) ...
$info
Definition: example_052.php:80
setHeader($a_header_strings)
Create styles array
The data for the language used.
Connector for course member ressource.
$ret
Definition: parser.php:6
addHeader($a_name, $a_value)
Add Header.
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.