From 145695a16c62abbd99df4aed80a60e54d09d369b Mon Sep 17 00:00:00 2001 From: Björn Geiger Date: Tue, 15 Nov 2011 15:05:03 +0100 Subject: Code Cleaning und verschiedene kleine Korrekturen --- library/Poolctrl/Pbs2Api.php | 113 +++++++++++++++++++++++-------------------- 1 file changed, 61 insertions(+), 52 deletions(-) (limited to 'library') diff --git a/library/Poolctrl/Pbs2Api.php b/library/Poolctrl/Pbs2Api.php index be868a3..4291182 100644 --- a/library/Poolctrl/Pbs2Api.php +++ b/library/Poolctrl/Pbs2Api.php @@ -22,33 +22,41 @@ class Poolctrl_Pbs2Api { if(isset($this->userIDsNamespace['apikey'])) { $this->acl = new Poolctrl_Acl($this->pbs2host, $this->config['pbs2']['checkright'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); } - if(!$this->userIDsNamespace['membershipID'] !='') { - $this->_helper->redirector('selectmembership', 'person'); - return; - } } - private function runApi($host, $path, $data = null) { - if($data) { - $apiResult = PostToHost($host, $path . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $data); + private function runApi($host, $path, $data = null, $apikey = null) { + if(!isset($apikey) && isset($this->userIDsNamespace['apikey'])) { + $apikey = $this->userIDsNamespace['apikey']; + } + if(isset($apikey)) { + if($data) { + $apiResult = PostToHost($host, $path . $apikey, 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $data); + } else { + $apiResult = PostToHost($host, $path . $apikey, 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', ''); + } } else { - $apiResult = PostToHost($host, $path . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', ''); + if($data) { + $apiResult = PostToHost($host, $path, 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $data); + } else { + $apiResult = PostToHost($host, $path, 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', ''); + } } - $xmlString = $bootOsApiResult['http-body']; + $xmlString = $apiResult['http-body']; if(strlen($xmlString) > 0) { $xml = new SimpleXMLElement($xmlString); return $xml; } else { - return new SimpleXMLElement(); + return null; } } - public function getPool(&$poolist, $poolID = null) { + public function getPool(&$poollist, $poolID = null) { if(isset($poolID)) { $poolRequest = "poolid=" . $poolID; $poolXML = $this->runApi($this->pbs2host, $this->config['pbs2']['getpools'], $poolRequest); } else { $poolXML = $this->runApi($this->pbs2host, $this->config['pbs2']['getpools']); + } if(isset($poolXML)) { foreach($poolXML->poollist->pool as $pool) { @@ -135,25 +143,30 @@ class Poolctrl_Pbs2Api { } } - public function getGroup(&$groupSession, $groupID) { + public function getGroup(&$groupSession, $groupID, $apikey = null) { $grouprequest = "groupid=" . $groupID; - $groupApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['getgroup'] . $membership->getApikey(), 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $grouprequest); - $groupXMLString = $groupApiResult['http-body']; - if(strlen($groupXMLString) > 0) { - $groupXML = new SimpleXMLElement($groupXMLString); + if(isset($apikey)) { + $groupXML = $this->runApi($this->pbs2host, $this->config['pbs2']['getgroup'], $grouprequest, $apikey); + } else { + $groupXML = $this->runApi($this->pbs2host, $this->config['pbs2']['getgroup'], $grouprequest); + } + if(isset($groupXML)) { $group = new Application_Model_Group(); $group->setID(sprintf("%s", $groupXML->group->id)); $group->setTitle(sprintf("%s", $groupXML->group->title)); $group->setDescription(sprintf("%s", $groupXML->group->description)); $groupSession->$groupID = $group; + return $group; } } - public function getRole(&$roleSession, $roleID) { - $roleApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['getrole'] . $membership->getApikey(), 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', ''); - $roleXMLString = $roleApiResult['http-body']; - if(strlen($roleXMLString) > 0) { - $roleXML = new SimpleXMLElement($roleXMLString); + public function getRole(&$roleSession, $roleID, $apikey = null) { + if(isset($apikey)) { + $roleXML = $this->runApi($this->pbs2host, $this->config['pbs2']['getrole'], null, $apikey); + } else { + $roleXML = $this->runApi($this->pbs2host, $this->config['pbs2']['getrole']); + } + if(isset($roleXML)) { $role = new Application_Model_Role(); $role->setID(sprintf("%s", $roleXML->role->id)); $role->setGroupID(sprintf("%s", $roleXML->role->groupid)); @@ -161,14 +174,17 @@ class Poolctrl_Pbs2Api { $role->setDescription(sprintf("%s", $roleXML->role->description)); $role->setInheritance(sprintf("%s", $roleXML->role->inheritance)); $roleSession->$roleID = $role; + return $role; } } - public function getPerson(&$personSession) { - $personApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['getperson'] . $apikey, 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', ''); - $personXMLString = $personApiResult['http-body']; - if(strlen($personXMLString) > 0) { - $personXML = new SimpleXMLElement($personXMLString); + public function getPerson(&$personSession, $apikey) { + if(isset($apikey)) { + $personXML = $this->runApi($this->pbs2host, $this->config['pbs2']['getperson'], null, $apikey); + } else { + $personXML = $this->runApi($this->pbs2host, $this->config['pbs2']['getperson']); + } + if(isset($personXML)) { $person = new Application_Model_Person(); $person->setID(sprintf("%s", $personXML->person->id)); $person->setCity(sprintf("%s", $personXML->person->city)); @@ -183,21 +199,19 @@ class Poolctrl_Pbs2Api { $person->setStreet(sprintf("%s", $personXML->person->street)); $person->setSuspend(sprintf("%s", $personXML->person->suspend)); $person->setTitle(sprintf("%s", $personXML->person->title)); - $personName = sprintf("%s", $login->personid); + $personName = sprintf("%s", $personXML->person->id); $personSession->$personName = $person; } - } - public function login($email, $password, &$membershipSession) { + public function login($email, $password, &$membershipSession, &$error, &$personID, &$apikey) { $loginquery = "email=" . $email . "&password=" . $password; - $loginApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['login'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $loginquery); - $loginXMLString = $loginApiResult['http-body']; - if(strlen($loginXMLString) > 0) { - $loginXML = new SimpleXMLElement($loginXMLString); + $loginXML = $this->runApi($this->pbs2host, $this->config['pbs2']['login'], $loginquery); + if(isset($loginXML)) { $login = $loginXML->login; $success = sprintf("%s", $login->success); if ($success === "true") { + $personID = sprintf("%s", $login->personid); $count = 0; foreach($login->membershiplist->membership as $membershipXML) { @@ -217,6 +231,7 @@ class Poolctrl_Pbs2Api { } return true; } else { + $error = sprintf("%s", $login->error); return false; } } else { @@ -229,9 +244,7 @@ class Poolctrl_Pbs2Api { if(isset($configID)) { $bootmenuquery .= "&configID=" . $configID; } - $bootmenuApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['addbootmenu'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $bootmenuquery); - $bootmenuXMLString = $bootmenuApiResult['http-body']; - $bootmenuXML = new SimpleXMLElement($bootmenuXMLString); + $bootmenuXML = $this->runApi($this->pbs2host, $this->config['pbs2']['addbootmenu'], $bootmenuquery); $bootmenuID = sprintf("%s", $bootmenuXML->bootmenu->id); return $bootmenuID; } @@ -241,20 +254,18 @@ class Poolctrl_Pbs2Api { if(isset($configID)) { $bootmenuquery .= "&configID=" . $configID; } - $bootmenuApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['changebootmenu'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $bootmenuquery); - return $bootmenuApiResult; + $bootmenuXML = $this->runApi($this->pbs2host, $this->config['pbs2']['changebootmenu'], $bootmenuquery); + return $bootmenuXML; } public function deleteBootmenu($bootmenuID) { - $bootmenuApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['deletebootmenu'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', "bootmenuid=" . $bootmenuID); - return $bootmenuApiResult; + $bootmenuXML = $this->runApi($this->pbs2host, $this->config['pbs2']['deletebootmenu'], "bootmenuid=" . $bootmenuID); + return $bootmenuXML; } public function addFilter($eventTitle, $bootmenuID) { $filterquery = "bootmenuID=" . $bootmenuID . "&title=Poolctrl-Filter for " . $event->getTitle() . "&description=This Filter was automatically created by the Poolctrl for Event " . $eventTitle . "&created= " . time() . "&priority=100"; - $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['addfilter'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterquery); - $filterXMLString = $filterApiResult['http-body']; - $filterXML = new SimpleXMLElement($filterXMLString); + $filterXML = $this->runApi($this->pbs2host, $this->config['pbs2']['addfilter'], $filterquery); $filterID = sprintf("%s", $filterXML->filter->id); return $filterID; } @@ -264,26 +275,24 @@ class Poolctrl_Pbs2Api { if(isset($bootmenuID)) { "&bootmenuID=" . $bootmenuID; } - $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['changefilter'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterQuerie); - return $filterApiResult; + $filterXML = $this->runApi($this->pbs2host, $this->config['pbs2']['changefilter'], $filterQuerie); + return $filterXML; } public function deleteFilter($filterID) { - $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['deletefilter'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', "bootmenuid=" . $filterID); - return $filterApiResult; + $filterXML = $this->runApi($this->pbs2host, $this->config['pbs2']['deletefilter'], "bootmenuid=" . $filterID); + return $filterXML; } public function addFilterentry($filterID, $filterType, $filterValue1, $filterValue2) { - $filterentriesApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery); - $filterentriesXMLString = $filterentriesApiResult['http-body']; - $filterentriesXML = new SimpleXMLElement($filterentriesXMLString); + $filterentriesXML = $this->runApi($this->pbs2host, $this->config['pbs2']['addfilterentry'], $filterentriesquery); $filterentriesID = sprintf("%s", $filterentriesXML->filterentry->id); return $filterentriesID; } public function changeFilterentry($oldValue1, $oldValue2, $newValue1, $newValue2) { $filterentriesQuerie = "filterid=" . $event->getPbs_filterID() . "&oldvalue1=" . $oldValue1 . "&oldvalue2=" . $oldValue2 . "&value1=" . $newValue1 . "&value2=" . $newValue2; - $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['changefilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesQuerie); - return $filterApiResult; + $filterentriesXML = $this->runApi($this->pbs2host, $this->config['pbs2']['changefilterentry'], $filterentriesQuerie); + return $filterentriesXML; } } \ No newline at end of file -- cgit v1.2.3-55-g7522