diff options
| author | michael pereira | 2011-03-07 17:54:01 +0100 |
|---|---|---|
| committer | michael pereira | 2011-03-07 17:54:01 +0100 |
| commit | f122bafccf6a81b87d982956f615e70ceaecfeb3 (patch) | |
| tree | 98e9960b2fda10f29765d3382d7fd92cfc100f92 /application/controllers/PoolController.php | |
| parent | BootMenuEntries fertig (diff) | |
| parent | dirty hack entfertn durch findBy-Methode (diff) | |
| download | pbs2-f122bafccf6a81b87d982956f615e70ceaecfeb3.tar.gz pbs2-f122bafccf6a81b87d982956f615e70ceaecfeb3.tar.xz pbs2-f122bafccf6a81b87d982956f615e70ceaecfeb3.zip | |
Merge branch 'master' of openslx.org:lsfks/master-teamprojekt/pbs2
Diffstat (limited to 'application/controllers/PoolController.php')
| -rw-r--r-- | application/controllers/PoolController.php | 133 |
1 files changed, 129 insertions, 4 deletions
diff --git a/application/controllers/PoolController.php b/application/controllers/PoolController.php index f9e54be..28bde8e 100644 --- a/application/controllers/PoolController.php +++ b/application/controllers/PoolController.php @@ -11,22 +11,143 @@ class PoolController extends Zend_Controller_Action public function indexAction() { $poolMapper = new Application_Model_PoolMapper(); - $this->view->pools = $poolMapper->fetchAll(); + $this->view->pools = $poolMapper->fetchAll(); + + $poolentriesMapper = new Application_Model_PoolEntriesMapper(); + #print_a($poolentriesMapper->findBy('poolID',1)); + } public function createpoolAction() { - // action body + if (!isset($_POST["add"])){ + $addfilterform = new Application_Form_Pool(); + $this->view->addpool = $addfilterform; + }else { + $addpoolform = new Application_Form_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"; + } + } + } } public function deletepoolAction() { - // action body + $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() { - // action body + 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(); + $editpool->populate($poolArray); + $this->view->editpoolform = $editpool; + + }else { + $addpoolform = new Application_Form_Pool($_POST); + if ($addpoolform->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"; + } + } + } + } + + public function linkclientAction() + { + if(!isset($_POST['clientID'])){ + print_a($_POST); + $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); + + $poolclient = new Application_Form_PoolClient(array('clients'=> $freeclients)); + $this->view->poolclient = $poolclient; + }else { + #$_POST['poolID'] = $this->_request->getParam('poolID'); + $poolclientform = new Application_Form_PoolClient($_POST); + + try{ + $pool = new Application_Model_PoolEntries($_POST); + $pool->setPoolID($this->_request->getParam('poolID')); + + $poolmapper = new Application_Model_PoolEntriesMapper(); + $poolmapper->save($pool); + $this->_redirect('/pool'); + }catch (Zend_Exception $e) { + echo "Error message 2: " . $e->getMessage() . "\n"; + } + + } + } + 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); + echo "<pre style='border:1px solid black;background-color:#F5B800'>"; + print_r($deletepoolentries); + echo "</pre>"; + + $deletepoolentriesmapper = new Application_Model_PoolEntriesMapper(); + $deletepoolentriesmapper->delete($deletepoolentries); + echo "ok"; + } +# echo "ready"; + $this->_redirect('/pool'); } @@ -38,3 +159,7 @@ class PoolController extends Zend_Controller_Action + + + + |
