ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCalendarRemoteReader.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
28 protected const TYPE_ICAL = 1;
29
30 // Fixed in the moment
31 private int $type = self::TYPE_ICAL;
32 private ?ilCurlConnection $curl = null;
33
34 private string $url = '';
35 private string $user = '';
36 private string $pass = '';
37
38 private string $ical = '';
39
41
42 public function __construct(string $a_url)
43 {
44 global $DIC;
45
46 $this->logger = $DIC->logger()->cal();
47 $this->url = $a_url;
48 }
49
50 public function setUser(string $a_user): void
51 {
52 $this->user = $a_user;
53 }
54
55 public function setPass(string $a_pass): void
56 {
57 $this->pass = $a_pass;
58 }
59
60 public function getType(): int
61 {
62 return $this->type;
63 }
64
65 public function getUrl(): string
66 {
67 return $this->url;
68 }
69
70 public function read(): void
71 {
72 $this->initCurl();
73
74 switch ($this->getType()) {
75 case self::TYPE_ICAL:
76 $this->readIcal();
77 break;
78 }
79 }
80
81 public function import(ilCalendarCategory $cat): void
82 {
83 switch ($this->getType()) {
84 case self::TYPE_ICAL:
85 $this->importIcal($cat);
86 break;
87 }
88 }
89
90 protected function readIcal(): void
91 {
92 $this->ical = $this->call();
93 $this->logger->debug($this->ical);
94 }
95
96 protected function importIcal(ilCalendarCategory $cat): void
97 {
98 // Delete old appointments
101 }
103
104 // Import new appointments
105 $parser = new ilICalParser($this->ical, ilICalParser::INPUT_STRING);
106 $parser->setCategoryId($cat->getCategoryID());
107 $parser->parse();
108 }
109
113 protected function initCurl(): void
114 {
115 try {
116 $this->replaceWebCalProtocol();
117
118 $this->curl = new ilCurlConnection($this->getUrl());
119 $this->curl->init();
120
121 $this->curl->setOpt(CURLOPT_SSL_VERIFYPEER, 0);
122 $this->curl->setOpt(CURLOPT_SSL_VERIFYHOST, 0);
123 $this->curl->setOpt(CURLOPT_RETURNTRANSFER, 1);
124
125 $this->curl->setOpt(CURLOPT_FOLLOWLOCATION, 1);
126 $this->curl->setOpt(CURLOPT_MAXREDIRS, 3);
127
128 if ($this->user) {
129 $this->curl->setOpt(CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
130 $this->curl->setOpt(CURLOPT_USERPWD, $this->user . ':' . $this->pass);
131 }
132 } catch (Exception $e) {
133 throw $e;
134 }
135 }
136
137 protected function replaceWebCalProtocol(): void
138 {
139 if (substr($this->getUrl(), 0, 6) == 'webcal') {
140 $purged = preg_replace('/webcal/', 'http', $this->getUrl(), 1);
141 $this->url = (string) $purged;
142 }
143 }
144
148 private function call(): string
149 {
150 try {
151 return $this->curl->exec();
152 } catch (ilCurlConnectionException $exc) {
153 throw($exc);
154 }
155 }
156}
static _deleteByCategoryId(int $a_cat_id)
Delete assignments by category id @access public.
static _getAssignedAppointments(array $a_cat_id)
Get assigned apointments.
Stores calendar categories.
static _delete(int $a_entry_id)
Reader for remote ical calendars.
importIcal(ilCalendarCategory $cat)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Component logger with individual log levels by component id.
global $DIC
Definition: shib_login.php:26