summaryrefslogtreecommitdiffstats
path: root/modules-available/locationinfo/inc/coursebackend.inc.php
diff options
context:
space:
mode:
authorDirk Riestere2017-02-22 14:20:47 +0100
committerDirk Riestere2017-02-22 14:20:47 +0100
commit27f292725a4014e053d902a5ebdddff858193d45 (patch)
treed6317d776354d13f6b449b1866741b47a0f7981b /modules-available/locationinfo/inc/coursebackend.inc.php
parentTypos behoben, und die cretendials werden auserhalb der Klasse gesetzt (diff)
downloadslx-admin-27f292725a4014e053d902a5ebdddff858193d45.tar.gz
slx-admin-27f292725a4014e053d902a5ebdddff858193d45.tar.xz
slx-admin-27f292725a4014e053d902a5ebdddff858193d45.zip
fetchSchedule nimmt jetzt einen Array an und gibt mehrere Schedules zurück
Diffstat (limited to 'modules-available/locationinfo/inc/coursebackend.inc.php')
-rw-r--r--modules-available/locationinfo/inc/coursebackend.inc.php66
1 files changed, 37 insertions, 29 deletions
diff --git a/modules-available/locationinfo/inc/coursebackend.inc.php b/modules-available/locationinfo/inc/coursebackend.inc.php
index ff77bade..e10cb08b 100644
--- a/modules-available/locationinfo/inc/coursebackend.inc.php
+++ b/modules-available/locationinfo/inc/coursebackend.inc.php
@@ -76,9 +76,11 @@ abstract class CourseBackend
public abstract function getDisplayName();
/**
- * initializes the class with url it needs to connect to.
+ * initializes the class.
+ * @param string $url adress of the server
+ * @param int $serverID ID of the server
*/
- public abstract function __construct($url);
+ public abstract function __construct($url,$serverID);
/**
@@ -113,47 +115,53 @@ abstract class CourseBackend
protected abstract function fetchSchedulesInternal($roomId);
/**
- * Method for fetching the schedule of the given room.
+ * Method for fetching the schedule of the given rooms on a server.
* @param int $roomId int of room ID to fetch
+ * @param int $serverid id of the server
* @return string|bool some jsonstring as result, or false on error
*/
- public final function fetchSchedule($roomID)
+ public final function fetchSchedule($roomIDs)
{
- $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->getCacheTime()."seconds") && $this->getCacheTime()>0) {
- $dbquery3 = Database::simpleQuery("SELECT calendar FROM location_info WHERE locationid = :id", array('id' => $sroomID));
- $dbd3=$dbquery3->fetch(PDO::FETCH_ASSOC);
- return $dbd3['callendar'];
+ $sqlr=implode(",", $roomIDs);
+ $sqlr = '('.$sqlr.')';
+ $dbquery1 = Database::simpleQuery("SELECT locationid, calendar, serverroomid, lastcalenderupdate FROM location_info WHERE locationid In :ids", array('ids' => $sqlr));
+ foreach ($dbquery1->fetchAll(PDO::FETCH_ASSOC) as $row){
+ $sroomID = $row['serverroomid'];
+ $lastUpdate = $row['lastcalenderupdate'];
+ $calendar = $row['calendar'];
+ //Check if in cache if lastUpdate is null then it is interpreted as 1970
+ if(strtotime($lastUpdate) > strtotime("-".$this->getCacheTime()."seconds") && $this->getCacheTime()>0) {
+ $result[$row['locationid']]=$calendar;
+ }
+ else {
+ $sroomIDs[$row['locationid']] = $sroomID;
+ }
+
}
//Check if we should refresh other rooms recently requested by front ends
- elseif ($this->getCacheTime()>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'];
+ if ($this->getCacheTime()>0) {
+ $dbquery4 = Database::simpleQuery("SELECT locationid ,serverroomid, lastcalenderupdate FROM location_info WHERE serverid= :id", array('id' => $this->serverID));
+ foreach($dbquery4->fetchAll(PDO::FETCH_COLUMN) as $row){
+ if($row['lastcalenderupdate']<$this->getRefreshTime()){
+ $sroomIDs[$row['locationid']] = $row['serverroomid'];
+ }
}
- }
- $roomIDs = array_unique($roomIDs);
}
- else {
- $roomIDs[] = $sroomID;
+ $results = $this->fetchSchedulesInternal($sroomIDs);
+ foreach ($sroomIDs as $location => $serverroom){
+ $newresult[$location] = $results[$serverroom];
}
- $dbquery2 = Database::simpleQuery("SELECT serverurl FROM `setting_location_info` WHERE serverid = :id", array('id' => $serverID));
- $dbd2=$dbquery2->fetch(PDO::FETCH_ASSOC);
- $result = $this->fetchSchedulesInternal($roomIDs);
if($this->getCacheTime()>0){
- foreach ($result as $key => $value) {
+ foreach ($newresult 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));
+ $dbquery1 = Database::simpleQuery("UPDATE location_info SET calendar = :ttable, lastcalenderupdate = :now WHERE locationid = :id ", array('id' => $key,'ttable' => $value,'now'=> $now));
}
}
+ //get all sheduls that are wanted from roomIDs
+ foreach($roomIDs as $id){
+ $result[$id] = $newresult[$id];
+ }
return $result[$roomID];
}