From b5cbdd6b400aa1ec77c9846e9cc8d4257f437e3c Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 14 Mar 2011 16:09:03 +0100 Subject: Application in 3 Modules gesplittet, Dev = unsere entwicklungsumgebung, user = die weboberfläche fr anwender mit acl etc, fbgui = für die fbgui truppe - links in dev müssen noch angepasst werden --- .../modules/dev/controllers/PoolController.php | 176 +++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 application/modules/dev/controllers/PoolController.php (limited to 'application/modules/dev/controllers/PoolController.php') diff --git a/application/modules/dev/controllers/PoolController.php b/application/modules/dev/controllers/PoolController.php new file mode 100644 index 0000000..f27ee45 --- /dev/null +++ b/application/modules/dev/controllers/PoolController.php @@ -0,0 +1,176 @@ +view->pools = $poolMapper->fetchAll(); + + $clientmapper = new Application_Model_ClientMapper(); + $clients = $clientmapper->fetchAll(); + foreach($clients as $c){ + #$client = new Application_Model_Client($c); + $clientsArray[] = $c->toArray(); + } + $assignedclientmapper = new Application_Model_PoolEntriesMapper(); + $assignedclients = $assignedclientmapper->fetchAll(); + foreach($assignedclients as $c){ + $assignedclientsArray[] = $c->toArray(); + } + $freeclients = $this->arrayDiff($clientsArray,$assignedclientsArray); + + $this->view->freeclients = $freeclients; + + } + + public function createpoolAction() + { + if (!isset($_POST["add"])){ + $addfilterform = new Application_Form_Pool(array('buttontext' => 'Create Pool')); + $this->view->addpool = $addfilterform; + }else { + $addpoolform = new Application_Form_Pool(array('buttontext' => 'Create Pool'),$_POST); + if ($addpoolform->isValid($_POST)) { + try{ + $pool = new Application_Model_Pool($_POST); + $poolmapper = new Application_Model_PoolMapper(); + $poolmapper->save($pool); + $this->_redirect('/pool'); + return; + }catch (Zend_Exception $e) { + echo "Error message 2: " . $e->getMessage() . "\n"; + } + } + $this->view->addpool = $addfilterform; + } + } + + public function deletepoolAction() + { + $poolID = $this->_request->getParam('poolID'); + // TODO: ACL implementieren ob er den pool löschen darf + if(is_numeric($poolID)){ + $deletepool = new Application_Model_Pool(); + $deletepool->setID($poolID); + $poolmapper = new Application_Model_PoolMapper(); + $poolmapper->delete($deletepool); + } + $this->_redirect('/pool'); + } + + public function editpoolAction() + { + if (!isset($_POST["add"])){ + $poolID = $this->_request->getParam('poolID'); + + $pool = new Application_Model_Pool(); + $poolmapper = new Application_Model_PoolMapper(); + $poolmapper->find($poolID,$pool); + $poolArray = $pool->toArray(); + + $editpool = new Application_Form_Pool(array('buttontext' => 'Edit Pool')); + $editpool->populate($poolArray); + $this->view->editpoolform = $editpool; + + }else { + $editpoolform = new Application_Form_Pool(array('buttontext' => 'Edit Pool'),$_POST); + if ($editpoolform->isValid($_POST)) { + try{ + $pool = new Application_Model_Pool($_POST); + $pool->setID($this->_request->getParam('poolID')); + $poolmapper = new Application_Model_PoolMapper(); + $poolmapper->save($pool); + $this->_redirect('/pool'); + }catch (Zend_Exception $e) { + echo "Error message 2: " . $e->getMessage() . "\n"; + } + } + $this->view->editpoolform = $editpoolform; + } + } + + public function linkclientAction() + { + $clientID = $this->_request->getParam('clientID'); + $poolID = $this->_request->getParam('poolID'); + if(!isset($_POST['clientID']) && ($clientID == '')){ + $clientmapper = new Application_Model_ClientMapper(); + $clients = $clientmapper->fetchAll(); + foreach($clients as $c){ + $clientsArray[] = $c->toArray(); + } + $assignedclientmapper = new Application_Model_PoolEntriesMapper(); + $assignedclients = $assignedclientmapper->fetchAll(); + foreach($assignedclients as $c){ + $assignedclientsArray[] = $c->toArray(); + } + $freeclients = $this->arrayDiff($clientsArray,$assignedclientsArray); + + $poolclient = new Application_Form_PoolClient(array('buttontext' => 'Link Client','clients'=> $freeclients)); + $this->view->poolclient = $poolclient; + }else { + $poolclient = new Application_Form_PoolClient(array('buttontext' => 'Link Client'),$_POST); + try{ + $pool = new Application_Model_PoolEntries($_POST); + $pool->setPoolID($this->_request->getParam('poolID')); + if($pool->getClientID() == ''){ + $pool->setClientID($this->_request->getParam('clientID')); + } + $poolmapper = new Application_Model_PoolEntriesMapper(); + $poolmapper->save($pool); + $this->_redirect('/pool'); + }catch (Zend_Exception $e) { + echo "Error message 2: " . $e->getMessage() . "\n"; + } + $this->view->poolclient = $poolclient; + + } + } + private function arrayDiff($a, $b){ + foreach($a as $k1 => $i1){ + foreach($b as $k2 => $i2){ + if($i1['clientID'] == $i2['clientID']){ + unset($a[$k1]); + } + } + } + return $a; + } + + + public function unlinkclientAction() + { + $poolentriesID = $this->_request->getParam('poolentriesID'); + + // TODO: ACL implementieren ob er den filter löschen darf + if(is_numeric($poolentriesID)){ + $deletepoolentries = new Application_Model_PoolEntries(); + $deletepoolentries->setID($poolentriesID); + + $deletepoolentriesmapper = new Application_Model_PoolEntriesMapper(); + $deletepoolentriesmapper->delete($deletepoolentries); + echo "ok"; + } + $this->_redirect('/pool'); + } + + +} + + + + + + + + + + + -- cgit v1.2.3-55-g7522