summaryrefslogtreecommitdiffstats
path: root/application/modules/dev/controllers/PoolController.php
diff options
context:
space:
mode:
authorSimon2011-03-14 16:09:03 +0100
committerSimon2011-03-14 16:09:03 +0100
commitb5cbdd6b400aa1ec77c9846e9cc8d4257f437e3c (patch)
treefcef50ad1ddf831f457d6aecd83e7fdc63297a1c /application/modules/dev/controllers/PoolController.php
parentfooter bleibt am fensterbottom (diff)
downloadpbs2-b5cbdd6b400aa1ec77c9846e9cc8d4257f437e3c.tar.gz
pbs2-b5cbdd6b400aa1ec77c9846e9cc8d4257f437e3c.tar.xz
pbs2-b5cbdd6b400aa1ec77c9846e9cc8d4257f437e3c.zip
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
Diffstat (limited to 'application/modules/dev/controllers/PoolController.php')
-rw-r--r--application/modules/dev/controllers/PoolController.php176
1 files changed, 176 insertions, 0 deletions
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 @@
+<?php
+
+class PoolController extends Zend_Controller_Action
+{
+
+ public function init()
+ {
+ /* Initialize action controller here */
+ }
+
+ public function indexAction()
+ {
+ $poolMapper = new Application_Model_PoolMapper();
+ $this->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');
+ }
+
+
+}
+
+
+
+
+
+
+
+
+
+
+