From df2518c0d6dde4fa621f880e098f9ce56067817d Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 19 Apr 2017 23:57:43 +0200 Subject: [locationinfo] CourseBackend: Rename some methods to be more descriptive --- .../locationinfo/inc/coursebackend.inc.php | 12 +++++----- .../coursebackend/coursebackend_davinci.inc.php | 6 ++--- .../inc/coursebackend/coursebackend_dummy.inc.php | 2 +- .../coursebackend/coursebackend_hisinone.inc.php | 28 +++++++++++----------- modules-available/locationinfo/page.inc.php | 4 ++-- 5 files changed, 26 insertions(+), 26 deletions(-) (limited to 'modules-available/locationinfo') diff --git a/modules-available/locationinfo/inc/coursebackend.inc.php b/modules-available/locationinfo/inc/coursebackend.inc.php index 0d84b0fb..0ce9424d 100644 --- a/modules-available/locationinfo/inc/coursebackend.inc.php +++ b/modules-available/locationinfo/inc/coursebackend.inc.php @@ -94,7 +94,7 @@ abstract class CourseBackend /** * @returns \BackendProperty[] list of properties that need to be set */ - public abstract function getCredentials(); + public abstract function getCredentialDefinitions(); /** * @return boolean true if the connection works, false otherwise @@ -210,7 +210,7 @@ abstract class CourseBackend public final function setCredentials($serverId, $data) { - foreach ($this->getCredentials() as $prop) { + foreach ($this->getCredentialDefinitions() as $prop) { if (!isset($data[$prop->property])) { $data[$prop->property] = $prop->default; } @@ -242,7 +242,7 @@ abstract class CourseBackend * and leaf nodes. The result is always an array on success, or * false if not found. */ - protected function getAttributes($array, $path) + protected function getArrayPath($array, $path) { if (!is_array($path)) { // Convert 'path/syntax/foo/wanteditem' to array for further processing and recursive calls @@ -279,7 +279,7 @@ abstract class CourseBackend // wrapped in a plain array - recurse into each one of them and merge the results $return = []; foreach ($array[$element] as $item) { - $test = $this->getAttributes($item, $path); + $test = $this->getArrayPath($item, $path); If (gettype($test) == "array") { $return = array_merge($return, $test); } @@ -288,14 +288,14 @@ abstract class CourseBackend return $return; } // Unique non-leaf node - simple recursion - return $this->getAttributes($array[$element], $path); + return $this->getArrayPath($array[$element], $path); } /** * @param string $response xml document to convert * @return bool|array array representation of the xml if possible, false otherwise */ - protected function toArray($response) + protected function xmlStringToArray($response) { $cleanresponse = preg_replace('/(<\/?)(\w+):([^>]*>)/', '$1$2$3', $response); try { diff --git a/modules-available/locationinfo/inc/coursebackend/coursebackend_davinci.inc.php b/modules-available/locationinfo/inc/coursebackend/coursebackend_davinci.inc.php index 77928b39..2f60249e 100644 --- a/modules-available/locationinfo/inc/coursebackend/coursebackend_davinci.inc.php +++ b/modules-available/locationinfo/inc/coursebackend/coursebackend_davinci.inc.php @@ -30,7 +30,7 @@ class CourseBackend_Davinci extends CourseBackend return $this->error === false; } - public function getCredentials() + public function getCredentialDefinitions() { return [ new BackendProperty('baseUrl', 'string') @@ -93,11 +93,11 @@ class CourseBackend_Davinci extends CourseBackend if ($return === false) { continue; } - $return = $this->toArray($return); + $return = $this->xmlStringToArray($return); if ($return === false) { continue; } - $lessons = $this->getAttributes($return, '/Lessons/Lesson'); + $lessons = $this->getArrayPath($return, '/Lessons/Lesson'); if ($lessons === false) { $this->error = "Cannot find /Lessons/Lesson in XML"; continue; diff --git a/modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php b/modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php index b8329196..0e5d654e 100644 --- a/modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php +++ b/modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php @@ -44,7 +44,7 @@ class CourseBackend_Dummy extends CourseBackend /** * @returns array with parameter name as key and and an array with type, help text and mask as value */ - public function getCredentials() + public function getCredentialDefinitions() { $options = ["opt1", "opt2", "opt3", "opt4", "opt5", "opt6", "opt7", "opt8"]; return [ diff --git a/modules-available/locationinfo/inc/coursebackend/coursebackend_hisinone.inc.php b/modules-available/locationinfo/inc/coursebackend/coursebackend_hisinone.inc.php index b01146a8..cc1d243a 100644 --- a/modules-available/locationinfo/inc/coursebackend/coursebackend_hisinone.inc.php +++ b/modules-available/locationinfo/inc/coursebackend/coursebackend_hisinone.inc.php @@ -42,7 +42,7 @@ class CourseBackend_HisInOne extends CourseBackend return true; } - public function getCredentials() + public function getCredentialDefinitions() { return [ new BackendProperty('baseUrl', 'string'), @@ -105,11 +105,11 @@ class CourseBackend_HisInOne extends CourseBackend $findUnit->appendChild($doc->createElement('ns1:roomId', $roomId)); $soap_request = $doc->saveXML(); - $response1 = $this->__doRequest($soap_request, "findUnit"); + $response1 = $this->postToServer($soap_request, "findUnit"); if ($this->error !== false) { return false; } - $response2 = $this->toArray($response1); + $response2 = $this->xmlStringToArray($response1); if (!is_array($response2)) { if ($this->error === false) { $this->error = 'Cannot convert XML response to array'; @@ -133,7 +133,7 @@ class CourseBackend_HisInOne extends CourseBackend } else { $path = '/soapenvBody/hisfindUnitResponse/hisunitIds/hisid'; } - $id = $this->getAttributes($response2, $path); + $id = $this->getArrayPath($response2, $path); if ($id === false) { $this->error = 'Cannot find ' . $path; } @@ -169,7 +169,7 @@ class CourseBackend_HisInOne extends CourseBackend * @param $action string with the name of the SOAP action * @return bool|string if successful the answer xml from the SOAP server */ - private function __doRequest($request, $action) + private function postToServer($request, $action) { $header = array( "Content-type: text/xml;charset=\"utf-8\"", @@ -261,7 +261,7 @@ class CourseBackend_HisInOne extends CourseBackend '/hisshorttext', '/hisshortcomment', '/hisplanelements/hisplanelement/hisdefaulttext') as $path) { - $name = $this->getAttributes($event, $path); + $name = $this->getArrayPath($event, $path); if (!empty($name) && !empty($name[0])) break; $name = false; @@ -269,18 +269,18 @@ class CourseBackend_HisInOne extends CourseBackend if ($name === false) { $name = ['???']; } - $unitPlannedDates = $this->getAttributes($event, + $unitPlannedDates = $this->getArrayPath($event, '/hisplanelements/hisplanelement/hisplannedDates/hisplannedDate/hisindividualDates/hisindividualDate'); if ($unitPlannedDates === false) { $this->error = 'Cannot find ./hisplanelements/hisplanelement/hisplannedDates/hisplannedDate/hisindividualDates/hisindividualDate'; return false; } foreach ($unitPlannedDates as $plannedDate) { - $eventRoomId = $this->getAttributes($plannedDate, '/hisroomId')[0]; - $eventDate = $this->getAttributes($plannedDate, '/hisexecutiondate')[0]; + $eventRoomId = $this->getArrayPath($plannedDate, '/hisroomId')[0]; + $eventDate = $this->getArrayPath($plannedDate, '/hisexecutiondate')[0]; if (in_array($eventRoomId, $requestedRoomIds) && in_array($eventDate, $currentWeek)) { - $startTime = $this->getAttributes($plannedDate, '/hisstarttime')[0]; - $endTime = $this->getAttributes($plannedDate, '/hisendtime')[0]; + $startTime = $this->getArrayPath($plannedDate, '/hisstarttime')[0]; + $endTime = $this->getArrayPath($plannedDate, '/hisendtime')[0]; $tTables[$eventRoomId][] = array( 'title' => $name[0], 'start' => $eventDate . " " . $startTime, @@ -318,11 +318,11 @@ class CourseBackend_HisInOne extends CourseBackend $readUnit->appendChild($doc->createElement('ns1:unitId', $unit)); $soap_request = $doc->saveXML(); - $response1 = $this->__doRequest($soap_request, "readUnit"); + $response1 = $this->postToServer($soap_request, "readUnit"); if ($response1 === false) { return false; } - $response2 = $this->toArray($response1); + $response2 = $this->xmlStringToArray($response1); if ($response2 === false) return false; if (!isset($response2['soapenvBody'])) { @@ -333,7 +333,7 @@ class CourseBackend_HisInOne extends CourseBackend $this->error = 'SOAP-Fault' . $response2['soapenvBody']['soapenvFault']['faultcode'] . " " . $response2['soapenvBody']['soapenvFault']['faultstring']; return false; } - return $this->getAttributes($response2, '/soapenvBody/hisreadUnitResponse/hisunit'); + return $this->getArrayPath($response2, '/soapenvBody/hisreadUnitResponse/hisunit'); } /** diff --git a/modules-available/locationinfo/page.inc.php b/modules-available/locationinfo/page.inc.php index a5d220ab..bec605ce 100644 --- a/modules-available/locationinfo/page.inc.php +++ b/modules-available/locationinfo/page.inc.php @@ -114,7 +114,7 @@ class Page_LocationInfo extends Page Util::redirect('?do=locationinfo'); } - $tmptypeArray = $backend->getCredentials(); + $tmptypeArray = $backend->getCredentialDefinitions(); $credentialsJson = array(); $counter = 0; @@ -457,7 +457,7 @@ class Page_LocationInfo extends Page $backend['active'] = false; } - $credentials = $backendInstance->getCredentials(); + $credentials = $backendInstance->getCredentialDefinitions(); $backend['credentials'] = array(); $counter = 0; -- cgit v1.2.3-55-g7522