diff options
author | Simon Rettberg | 2022-12-02 15:21:26 +0100 |
---|---|---|
committer | Simon Rettberg | 2022-12-02 15:24:08 +0100 |
commit | 200d92c8491d5060af5dd839aa82d1e51b058dd6 (patch) | |
tree | afd9274f2de28b4c387f08550712629798883b26 /modules-available/locationinfo/api.inc.php | |
parent | [inc/ArrayUtil] Fix sort flag handling (diff) | |
download | slx-admin-200d92c8491d5060af5dd839aa82d1e51b058dd6.tar.gz slx-admin-200d92c8491d5060af5dd839aa82d1e51b058dd6.tar.xz slx-admin-200d92c8491d5060af5dd839aa82d1e51b058dd6.zip |
[statistics] Per-location usage stats; include active lecture count
Diffstat (limited to 'modules-available/locationinfo/api.inc.php')
-rw-r--r-- | modules-available/locationinfo/api.inc.php | 68 |
1 files changed, 1 insertions, 67 deletions
diff --git a/modules-available/locationinfo/api.inc.php b/modules-available/locationinfo/api.inc.php index 2fbf1e84..ab1f2358 100644 --- a/modules-available/locationinfo/api.inc.php +++ b/modules-available/locationinfo/api.inc.php @@ -36,7 +36,7 @@ function HandleParameters() $output = getLocationTree($locationIds); } elseif ($get === "calendar") { $locationIds = LocationInfo::getLocationsOr404($uuid); - $output = getCalendar($locationIds); + $output = LocationInfo::getCalendar($locationIds); } if ($output !== false) { Header('Content-Type: application/json; charset=utf-8'); @@ -153,69 +153,3 @@ function findLocations($locations, $idList) } return $ret; } - -// ########## <Calendar> ########### -/** - * Gets the calendar of the given ids. - * - * @param int[] $idList list with the location ids. - * @return array Calendar. - */ -function getCalendar($idList) -{ - if (empty($idList)) - return []; - - // Build SQL query for multiple ids. - $query = "SELECT l.locationid, l.serverid, l.serverlocationid, s.servertype, s.credentials - FROM `locationinfo_locationconfig` AS l - INNER JOIN locationinfo_coursebackend AS s ON (s.serverid = l.serverid) - WHERE l.locationid IN (:idlist) - ORDER BY s.servertype ASC"; - $dbquery = Database::simpleQuery($query, array('idlist' => array_values($idList))); - - $serverList = array(); - foreach ($dbquery as $dbresult) { - if (!isset($serverList[$dbresult['serverid']])) { - $serverList[$dbresult['serverid']] = array( - 'credentials' => (array)json_decode($dbresult['credentials'], true), - 'type' => $dbresult['servertype'], - 'idlist' => array() - ); - } - $serverList[$dbresult['serverid']]['idlist'][] = $dbresult['locationid']; - } - - $resultArray = array(); - foreach ($serverList as $serverid => $server) { - $serverInstance = CourseBackend::getInstance($server['type']); - if ($serverInstance === false) { - EventLog::warning('Cannot fetch schedule for location (' . implode(', ', $server['idlist']) . ')' - . ': Backend type ' . $server['type'] . ' unknown. Disabling location.'); - Database::exec("UPDATE locationinfo_locationconfig SET serverid = NULL WHERE locationid IN (:lid)", - array('lid' => $server['idlist'])); - continue; - } - $credentialsOk = $serverInstance->setCredentials($serverid, $server['credentials']); - - if ($credentialsOk) { - $calendarFromBackend = $serverInstance->fetchSchedule($server['idlist']); - } else { - $calendarFromBackend = array(); - } - - LocationInfo::setServerError($serverid, $serverInstance->getErrors()); - - if (is_array($calendarFromBackend)) { - foreach ($calendarFromBackend as $key => $value) { - $resultArray[] = array( - 'id' => $key, - 'calendar' => $value, - ); - } - } - } - return $resultArray; -} - -// ########## </Calendar> ########## |