ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilECSCourseUrlConnector.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';
6
14{
19 public function __construct(ilECSSetting $settings = null)
20 {
21 parent::__construct($settings);
22 }
23
29 public function addUrl(ilECSCourseUrl $url, $a_target_mid)
30 {
31 global $ilLog;
32
33 $ilLog->write(__METHOD__ . ': Add new course url ...');
34
35 $this->path_postfix = '/campusconnect/course_urls';
36
37 try {
38 $this->prepareConnection();
39
40 $this->addHeader('Content-Type', 'application/json');
41 $this->addHeader('Accept', 'application/json');
42 $this->addHeader(ilECSConnector::HEADER_MEMBERSHIPS, $a_target_mid);
43
44 $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->getHeader());
45 $this->curl->setOpt(CURLOPT_POST, true);
46 $this->curl->setOpt(CURLOPT_POSTFIELDS, json_encode($url));
47
48 $GLOBALS['ilLog']->write(__METHOD__ . ': Sending url ' . print_r(json_encode($url), true));
49
50 $ret = $this->call();
51
52 $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
53
54 $ilLog->write(__METHOD__ . ': Checking HTTP status...');
55 if ($info != self::HTTP_CODE_CREATED) {
56 $ilLog->write(__METHOD__ . ': Cannot create course url ressource, did not receive HTTP 201. ');
57 $ilLog->write(__METHOD__ . ': POST was: ' . json_encode($url));
58 $ilLog->write(__METHOD__ . ': HTTP code: ' . $info);
59 throw new ilECSConnectorException('Received HTTP status code: ' . $info);
60 }
61 $ilLog->write(__METHOD__ . ': ... got HTTP 201 (created)');
62 } catch (ilCurlConnectionException $exc) {
63 throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage());
64 }
65 }
66}
An exception for terminatinating execution or to throw for unit testing.
addHeader($a_name, $a_value)
Add Header.
prepareConnection()
prepare connection
Connector for writing ecs course urls.
addUrl(ilECSCourseUrl $url, $a_target_mid)
Send url of newly created courses to ecs.
__construct(ilECSSetting $settings=null)
Constructor.
Represents a ecs course url.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
$info
Definition: index.php:5
$ret
Definition: parser.php:6
$url