summaryrefslogtreecommitdiffstats
path: root/modules-available/locationinfo/inc/coursebackend/coursebackend_hisinone.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/locationinfo/inc/coursebackend/coursebackend_hisinone.inc.php')
-rw-r--r--modules-available/locationinfo/inc/coursebackend/coursebackend_hisinone.inc.php109
1 files changed, 7 insertions, 102 deletions
diff --git a/modules-available/locationinfo/inc/coursebackend/coursebackend_hisinone.inc.php b/modules-available/locationinfo/inc/coursebackend/coursebackend_hisinone.inc.php
index 82efae87..8bd18169 100644
--- a/modules-available/locationinfo/inc/coursebackend/coursebackend_hisinone.inc.php
+++ b/modules-available/locationinfo/inc/coursebackend/coursebackend_hisinone.inc.php
@@ -1,15 +1,7 @@
<?php
-class CourseBackend_HisInOne extends CourseBackend
+class CourseBackend_HisInOne extends ICalCourseBackend
{
- private $location;
- private $verifyHostname = true;
- private $verifyCert = true;
- /**
- * @var bool|resource
- */
- private $curlHandle = false;
-
public function setCredentialsInternal($data)
{
@@ -18,9 +10,8 @@ class CourseBackend_HisInOne extends CourseBackend
return false;
}
- $this->location = $this->mangleProperty('baseUrl', $data['baseUrl']);
- $this->verifyHostname = $data['verifyHostname'];
- $this->verifyCert = $data['verifyCert'];
+ $this->init($this->mangleProperty('baseUrl', $data['baseUrl']),
+ $data['verifyCert'], $data['verifyHostname']);
return true;
}
@@ -39,14 +30,14 @@ class CourseBackend_HisInOne extends CourseBackend
if ($prop === 'baseUrl') {
// Update form SOAP to iCal url
if (preg_match(',^(http.*?)/qisserver,', $value, $out)) {
- $value = $out[1] . '/qisserver/pages/cm/exa/timetable/roomScheduleCalendarExport.faces?roomId=';
+ $value = $out[1] . '/qisserver/pages/cm/exa/timetable/roomScheduleCalendarExport.faces?roomId=%ID%';
} elseif (preg_match(',(.*[/=])\d*$', $value, $out)) {
- $value = $out[1];
+ $value = $out[1] . '%ID%';
} elseif (substr_count($value, '/') <= 3) {
if (substr($value, -1) !== '/') {
$value .= '/';
}
- $value .= 'qisserver/pages/cm/exa/timetable/roomScheduleCalendarExport.faces?roomId=';
+ $value .= 'qisserver/pages/cm/exa/timetable/roomScheduleCalendarExport.faces?roomId=%ID%';
}
}
return $value;
@@ -54,10 +45,8 @@ class CourseBackend_HisInOne extends CourseBackend
public function checkConnection()
{
- if (empty($this->location)) {
- $this->addError("Credentials are not set", true);
+ if (!$this->isOK())
return false;
- }
// Unfortunately HisInOne returns an internal server error if you pass an invalid roomId.
// So we just try a bunch and see if anything works. Even if this fails, using
// the backend should work, given the URL is actually correct.
@@ -68,43 +57,6 @@ class CourseBackend_HisInOne extends CourseBackend
return false;
}
- /**
- * @param int $roomId room id
- * @return ICalEvent[]|null all events for this room in the range -7 days to +7 days, or NULL on error
- */
- private function downloadIcal($roomId)
- {
- if ($this->curlHandle === false) {
- $this->curlHandle = curl_init();
- }
-
- $ical = new ICalParser(['filterDaysBefore' => 7, 'filterDaysAfter' => 7]);
- $options = array(
- CURLOPT_WRITEFUNCTION => function ($ch, $data) use ($ical) {
- $ical->feedData($data);
- return strlen($data);
- },
- CURLOPT_FOLLOWLOCATION => true,
- CURLOPT_SSL_VERIFYHOST => $this->verifyHostname ? 2 : 0,
- CURLOPT_SSL_VERIFYPEER => $this->verifyCert ? 1 : 0,
- CURLOPT_URL => $this->location . $roomId,
- CURLOPT_TIMEOUT => 60,
- CURLOPT_CONNECTTIMEOUT => 4,
- );
-
- curl_setopt_array($this->curlHandle, $options);
-
- if (!curl_exec($this->curlHandle)) {
- $this->addError('Curl error: ' . curl_error($this->curlHandle), false);
- }
- $ical->finish();
- if (!$ical->isValid()) {
- $this->addError("Did not find a VCALENDAR in returned data for {$this->location}$roomId", false);
- return null;
- }
- return $ical->events();
- }
-
public function getCacheTime()
{
return 30 * 60;
@@ -121,51 +73,4 @@ class CourseBackend_HisInOne extends CourseBackend
return "HisInOne";
}
- public function fetchSchedulesInternal($requestedRoomIds)
- {
- if (empty($requestedRoomIds)) {
- return array();
- }
- $tTables = [];
- foreach ($requestedRoomIds as $roomId) {
- $data = $this->downloadIcal($roomId);
- if ($data === null) {
- $this->addError("Downloading ical for $roomId failed", false);
- continue;
- }
- foreach ($data as $event) {
- $tTables[$roomId][] = array(
- 'title' => $this->toTitle($event),
- 'start' => $event->dtstart,
- 'end' => $event->dtend,
- 'cancelled' => false, // ??? How
- );
- }
- }
- return $tTables;
- }
-
- /**
- * Get a usable title from either SUMMARY or DESCRIPTION
- * @param ICalEvent $event
- */
- private function toTitle($event)
- {
- $title = $event->summary;
- if (empty($title)) {
- $title = $event->description;
- }
- if (empty($title)) {
- $title = 'Unknown';
- }
- return preg_replace([',(\s*<br\s*/?>\s*|\r|\n|\\\r|\\\n)+,', '/\\\\([,;:])/'], ["\n", '$1'], $title);
- }
-
- public function __destruct()
- {
- if ($this->curlHandle !== false) {
- curl_close($this->curlHandle);
- }
- }
-
}