summaryrefslogtreecommitdiffstats
path: root/modules-available/locationinfo/inc/coursebackend.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2017-02-08 16:07:40 +0100
committerSimon Rettberg2017-02-08 16:07:40 +0100
commit6ec81b6f59dfb1a3baaf25be4048cd62a07e0abf (patch)
tree6f9159f2f4d0556e7ee0c78bff6027a6a0a64c08 /modules-available/locationinfo/inc/coursebackend.inc.php
parentfrontend: panel now shows current calendar events and a countdown, opening ti... (diff)
downloadslx-admin-6ec81b6f59dfb1a3baaf25be4048cd62a07e0abf.tar.gz
slx-admin-6ec81b6f59dfb1a3baaf25be4048cd62a07e0abf.tar.xz
slx-admin-6ec81b6f59dfb1a3baaf25be4048cd62a07e0abf.zip
[locationinfo] Add skeleton for pluggable course backend infrastructure
Diffstat (limited to 'modules-available/locationinfo/inc/coursebackend.inc.php')
-rw-r--r--modules-available/locationinfo/inc/coursebackend.inc.php108
1 files changed, 108 insertions, 0 deletions
diff --git a/modules-available/locationinfo/inc/coursebackend.inc.php b/modules-available/locationinfo/inc/coursebackend.inc.php
new file mode 100644
index 00000000..39ba3b90
--- /dev/null
+++ b/modules-available/locationinfo/inc/coursebackend.inc.php
@@ -0,0 +1,108 @@
+<?php
+
+/**
+ * Base class for course query backends
+ */
+abstract class CourseBackend
+{
+
+ /*
+ * Static part for handling interfaces
+ */
+
+ /**
+ * @var array list of known backends
+ */
+ private static $backendTypes = false;
+
+ /**
+ * Load all known backend types. This is done
+ * by including *.inc.php from inc/coursebackend/.
+ */
+ public static function loadDb()
+ {
+ if (self::$backendTypes !== false)
+ return;
+ self::$backendTypes = array();
+ foreach (glob(dirname(__FILE__) . '/coursebackend/coursebackend_*.inc.php', GLOB_NOSORT) as $file) {
+ require_once $file;
+ preg_match('#coursebackend_([^/\.]+)\.inc\.php$#i', $file, $out);
+ if (!class_exists('coursebackend_' . $out[1])) {
+ trigger_error("Backend type source unit $file doesn't seem to define class CourseBackend_{$out[1]}", E_USER_ERROR);
+ }
+ self::$backendTypes[$out[1]] = true;
+ }
+ }
+
+ /**
+ * Get all known config module types.
+ *
+ * @return array list of modules
+ */
+ public static function getList()
+ {
+ self::loadDb();
+ return array_keys(self::$backendTypes);
+ }
+
+ /**
+ * Get fresh instance of ConfigModule subclass for given module type.
+ *
+ * @param string $moduleType name of module type
+ * @return \ConfigModule module instance
+ */
+ public static function getInstance($moduleType)
+ {
+ self::loadDb();
+ if (!isset(self::$backendTypes[$moduleType])) {
+ error_log('Unknown module type: ' . $moduleType);
+ return false;
+ }
+ if (!is_object(self::$backendTypes[$moduleType])) {
+ $class = "coursebackend_$moduleType";
+ self::$backendTypes[$moduleType] = new $class;
+ }
+ return self::$backendTypes[$moduleType];
+ }
+
+
+ /*
+ * TODO: Insert required methods here
+ */
+
+ /**
+ * @return string return display name of backend
+ */
+ public abstract function getDisplayName();
+
+ /**
+ * @return int desired caching time of results, in seconds. 0 = no caching
+ */
+ public abstract function getCacheTime();
+
+ /**
+ * Internal version of fetch, to be overridden by subclasses.
+ * @param $roomIds
+ * @return mixed
+ */
+ protected abstract function fetchSchedulesInternal($roomIds);
+
+ /**
+ * Method for fetching the schedules of the given rooms.
+ * @param array $roomIds Array of room IDs to fetch
+ * @return array|bool some multidimensional array of rooms as result, or false on error
+ */
+ public final function fetchSchedules($roomIds)
+ {
+ // TODO: Check if in cache
+ // TODO: Check if we should refresh other rooms recently requested by front ends but not included in $roomIds
+ $aggregatedRoomIds = $roomIds; // + extra rooms
+ // ...
+ // If not in cache:
+ $result = $this->fetchSchedulesInternal($aggregatedRoomIds);
+ // TODO: Place in cache if necessary
+ // TODO: Remove entries from result that were not in $roomsIds
+ return $result;
+ }
+
+}