ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilECSCourseUrlConnector.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
27 {
32  public function addUrl(ilECSCourseUrl $url, $a_target_mid): void
33  {
34  $this->logger->info(__METHOD__ . ': Add new course url ...');
35 
36  $this->path_postfix = '/campusconnect/course_urls';
37 
38  try {
39  $this->prepareConnection();
40 
41  $this->addHeader('Content-Type', 'application/json');
42  $this->addHeader('Accept', 'application/json');
43  $this->addHeader(ilECSConnector::HEADER_MEMBERSHIPS, (string) $a_target_mid);
44 
45  $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->getHeader());
46  $this->curl->setOpt(CURLOPT_POST, true);
47  $this->curl->setOpt(CURLOPT_POSTFIELDS, json_encode($url, JSON_THROW_ON_ERROR));
48 
49  $this->logger->debug('Sending url ' . print_r(json_encode($url, JSON_THROW_ON_ERROR), true));
50 
51  $this->call();
52 
53  $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
54 
55  $this->logger->debug('Checking HTTP status...');
56  if ($info !== self::HTTP_CODE_CREATED) {
57  $this->logger->debug('Cannot create course url ressource, did not receive HTTP 201. ');
58  $this->logger->debug('POST was: ' . json_encode($url, JSON_THROW_ON_ERROR));
59  $this->logger->debug('HTTP code: ' . $info);
60  throw new ilECSConnectorException('Received HTTP status code: ' . $info);
61  }
62  $this->logger->debug('... got HTTP 201 (created)');
63  //TODO add returning of the new created courseurl id
64  } catch (ilCurlConnectionException $exc) {
65  throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage());
66  }
67  }
68 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addUrl(ilECSCourseUrl $url, $a_target_mid)
Send url of newly created courses to ecs.
addHeader(string $a_name, string $a_value)
Add Header.
$url
Definition: shib_logout.php:66
Connector for writing ecs course urls.
Represents a ecs course url.
prepareConnection()
prepare connection