summaryrefslogtreecommitdiffstats
path: root/modules-available/locationinfo/inc/coursebackend/coursebackend_hisinone.inc.php
blob: 8bd18169d45b32593a6f8780bdd2a84c25b83c91 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php

class CourseBackend_HisInOne extends ICalCourseBackend
{

	public function setCredentialsInternal($data)
	{
		if (empty($data['baseUrl'])) {
			$this->addError("No url is given", true);
			return false;
		}

		$this->init($this->mangleProperty('baseUrl', $data['baseUrl']),
			$data['verifyCert'], $data['verifyHostname']);

		return true;
	}

	public function getCredentialDefinitions()
	{
		return [
			new BackendProperty('baseUrl', 'string'),
			new BackendProperty('verifyCert', 'bool', true),
			new BackendProperty('verifyHostname', 'bool', true)
		];
	}

	public function mangleProperty($prop, $value)
	{
		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=%ID%';
			} elseif (preg_match(',(.*[/=])\d*$', $value, $out)) {
				$value = $out[1] . '%ID%';
			} elseif (substr_count($value, '/') <= 3) {
				if (substr($value, -1) !== '/') {
					$value .= '/';
				}
				$value .= 'qisserver/pages/cm/exa/timetable/roomScheduleCalendarExport.faces?roomId=%ID%';
			}
		}
		return $value;
	}

	public function checkConnection()
	{
		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.
		foreach ([60, 100, 5, 10, 50, 110, 200, 210, 250, 300, 333, 500, 1000, 2000] as $roomId) {
			if ($this->downloadIcal($roomId) !== null)
				return true;
		}
		return false;
	}

	public function getCacheTime()
	{
		return 30 * 60;
	}

	public function getRefreshTime()
	{
		return 60 * 60;
	}


	public function getDisplayName()
	{
		return "HisInOne";
	}

}