summaryrefslogtreecommitdiffstats
path: root/modules-available/locationinfo/inc/coursebackend.inc.php
diff options
context:
space:
mode:
authorDirk Riestere2017-02-15 20:48:22 +0100
committerDirk Riestere2017-02-15 20:48:22 +0100
commitdd77e6825021a43c4ef2ee62441d4d506a16a215 (patch)
tree3435ce84d2f1d9d1b6fc5ea3deb385b96556410d /modules-available/locationinfo/inc/coursebackend.inc.php
parentAPI: Opening times multi id support added. (diff)
downloadslx-admin-dd77e6825021a43c4ef2ee62441d4d506a16a215.tar.gz
slx-admin-dd77e6825021a43c4ef2ee62441d4d506a16a215.tar.xz
slx-admin-dd77e6825021a43c4ef2ee62441d4d506a16a215.zip
Die Klassen sind wie besprochen eingerichtet
Diffstat (limited to 'modules-available/locationinfo/inc/coursebackend.inc.php')
-rw-r--r--modules-available/locationinfo/inc/coursebackend.inc.php87
1 files changed, 70 insertions, 17 deletions
diff --git a/modules-available/locationinfo/inc/coursebackend.inc.php b/modules-available/locationinfo/inc/coursebackend.inc.php
index 39ba3b90..184ca048 100644
--- a/modules-available/locationinfo/inc/coursebackend.inc.php
+++ b/modules-available/locationinfo/inc/coursebackend.inc.php
@@ -75,34 +75,87 @@ abstract class CourseBackend
*/
public abstract function getDisplayName();
- /**
+ /**
+ * initializes the class with url it needs to connect to.
+ */
+ public abstract function __contruct($url);
+
+
+ /**
+ * @returns array with parameter name as key and type as value
+ */
+ public abstract function getCredentials();
+
+ /**
+ * uses json to setCredentials, the json must follow the form given in
+ * getCredentials
+ * @returns void
+ */
+ public abstract function setCredentials($json);
+
+ /**
* @return int desired caching time of results, in seconds. 0 = no caching
*/
public abstract function getCacheTime();
+
+ /**
+ * @return int age after which ttables are no longer refreshed should be
+ * greater then CacheTime
+ */
+ public abstract function getRefreshTime();
- /**
+ /**
* Internal version of fetch, to be overridden by subclasses.
* @param $roomIds
- * @return mixed
+ * @return array a multidemensional array that uses the roomID as key
+ * and has the sheduls as string in the value
*/
- protected abstract function fetchSchedulesInternal($roomIds);
+ protected abstract function fetchSchedulesInternal($roomId);
/**
- * 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
+ * Method for fetching the schedule of the given room.
+ * @param int $roomId int of room ID to fetch
+ * @return string|bool some jsonstring as result, or false on error
*/
- public final function fetchSchedules($roomIds)
+ public final function fetchSchedule($roomID)
{
- // 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;
+ $dbquery1 = Database::simpleQuery("SELECT servertype, serverid, serverroomid, lastcalenderupdate FROM location_info WHERE locationid = :id", array('id' => $roomID));
+ $dbd1=$dbquery1->fetch(PDO::FETCH_ASSOC);
+ $serverID = $dbd1['serverid'];
+ $sroomID = $dbd1['serverroomid'];
+ $lastUpdate = $dbd1['lastcalenderupdate'];
+ //Check if in cache
+ if(strtotime($lastUpdate) > strtotime("-".$this->getCachedTime()."seconds") && $this->getCachedTime()>0) {
+ $dbquery3 = Database::simpleQuery("SELECT calendar FROM location_info WHERE locationid = :id", array('id' => $sroomID));
+ $dbd3=$dbquery3->fetch(PDO::FETCH_ASSOC);
+ return $dbd3['callendar'];
+ }
+ //Check if we should refresh other rooms recently requested by front ends
+ elseif ($this->getCachedTime()>0) {
+ $dbquery4 = Database::simpleQuery("SELECT serverroomid, lastcalenderupdate FROM location_info WHERE serverid= :id", array('id' => $serverID));
+ $roomIDs[] = $sroomID;
+ foreach($dbquery4->fetchAll(PDO::FETCH_COLUMN) as $row){
+ if($row['lastcalenderupdate']<$this->getRefreshTime()){
+ $roomIDs[] = $row['serverroomid'];
+ }
+ }
+ $roomIDs = array_unique($roomIDs);
+ }
+ else {
+ $roomIDs[] = $sroomID;
+ }
+ $dbquery2 = Database::simpleQuery("SELECT serverurl, credentials FROM `setting_location_info` WHERE serverid = :id", array('id' => $serverID));
+ $dbd2=$dbquery2->fetch(PDO::FETCH_ASSOC);
+ $this->setCredentials($dbd2['credentials']);
+ $result = $this->getJsons($roomIDs);
+
+ if($this->getCachedTime()>0){
+ foreach ($result as $key => $value) {
+ $now = strtotime('Now');
+ $dbquery1 = Database::simpleQuery("UPDATE location_info SET calendar = :ttable, lastcalenderupdate = :now WHERE locationid = :id ", array('id' => $key,'ttable' => $result[$key],'now'=> $now));
+ }
+ }
+ return $result[$roomID];
}
}