ILIAS  release_7 Revision v7.30-3-g800a261c036
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 {
22 }
23
29 public function addUrl(ilECSCourseUrl $url, $a_target_mid)
30 {
31 global $DIC;
32
33 $ilLog = $DIC['ilLog'];
34
35 $ilLog->write(__METHOD__ . ': Add new course url ...');
36
37 $this->path_postfix = '/campusconnect/course_urls';
38
39 try {
40 $this->prepareConnection();
41
42 $this->addHeader('Content-Type', 'application/json');
43 $this->addHeader('Accept', 'application/json');
44 $this->addHeader(ilECSConnector::HEADER_MEMBERSHIPS, $a_target_mid);
45
46 $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->getHeader());
47 $this->curl->setOpt(CURLOPT_POST, true);
48 $this->curl->setOpt(CURLOPT_POSTFIELDS, json_encode($url));
49
50 $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': Sending url ' . print_r(json_encode($url), true));
51
52 $ret = $this->call();
53
54 $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
55
56 $ilLog->write(__METHOD__ . ': Checking HTTP status...');
57 if ($info != self::HTTP_CODE_CREATED) {
58 $ilLog->write(__METHOD__ . ': Cannot create course url ressource, did not receive HTTP 201. ');
59 $ilLog->write(__METHOD__ . ': POST was: ' . json_encode($url));
60 $ilLog->write(__METHOD__ . ': HTTP code: ' . $info);
61 throw new ilECSConnectorException('Received HTTP status code: ' . $info);
62 }
63 $ilLog->write(__METHOD__ . ': ... got HTTP 201 (created)');
64 } catch (ilCurlConnectionException $exc) {
65 throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage());
66 }
67 }
68}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
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.
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$ret
Definition: parser.php:6
$url