ILIAS  release_8 Revision v8.24
class.ilECSCourseUrlConnector.php
Go to the documentation of this file.
1<?php
2
18declare(strict_types=1);
19
26{
31 public function addUrl(ilECSCourseUrl $url, int $a_target_mid): void
32 {
33 $this->logger->info(__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, (string) $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, JSON_THROW_ON_ERROR));
47
48 $this->logger->debug('Sending url ' . print_r(json_encode($url, JSON_THROW_ON_ERROR), true));
49
50 $this->call();
51
52 $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
53
54 $this->logger->debug('Checking HTTP status...');
55 if ($info !== self::HTTP_CODE_CREATED) {
56 $this->logger->debug('Cannot create course url ressource, did not receive HTTP 201. ');
57 $this->logger->debug('POST was: ' . json_encode($url, JSON_THROW_ON_ERROR));
58 $this->logger->debug('HTTP code: ' . $info);
59 throw new ilECSConnectorException('Received HTTP status code: ' . $info);
60 }
61 $this->logger->debug('... got HTTP 201 (created)');
62 //TODO add returning of the new created courseurl id
63 } catch (ilCurlConnectionException $exc) {
64 throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage());
65 }
66 }
67}
addHeader(string $a_name, string $a_value)
Add Header.
prepareConnection()
prepare connection
Connector for writing ecs course urls.
addUrl(ilECSCourseUrl $url, int $a_target_mid)
Send url of newly created courses to ecs.
Represents a ecs course url.
$url