From 90daca1a5ec239dfb7f44e54f1c22cf299181143 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 8 Mar 2011 16:40:30 +0100 Subject: create, edit, delete session - fehlt noch mit selectboxen && sql-data abgeändert --- application/controllers/SessionController.php | 74 ++++++++++++++++++++-- application/forms/Session.php | 70 ++++++++++++++++++++ application/models/Session.php | 10 +++ application/models/SessionMapper.php | 24 ++++--- .../views/scripts/session/createsession.phtml | 6 +- .../views/scripts/session/editsession.phtml | 6 +- application/views/scripts/session/index.phtml | 49 +++++++++++++- 7 files changed, 223 insertions(+), 16 deletions(-) create mode 100644 application/forms/Session.php (limited to 'application') diff --git a/application/controllers/SessionController.php b/application/controllers/SessionController.php index 382e68e..fc3b962 100644 --- a/application/controllers/SessionController.php +++ b/application/controllers/SessionController.php @@ -10,22 +10,88 @@ class SessionController extends Zend_Controller_Action public function indexAction() { - // action body + $mapper = new Application_Model_SessionMapper(); + $this->view->sessions = $mapper->fetchAll(); } public function createsessionAction() { - // action body + if (!isset($_POST["add"])){ + $createsession = new Application_Form_Session(); + $this->view->createsession = $createsession; + }else { + $createsession = new Application_Form_Session($_POST); + print_a($_POST); + if ($createsession->isValid($_POST)) { + try{ + $session = new Application_Model_Session($_POST); + $sessionmapper = new Application_Model_SessionMapper(); + $sessionmapper->save($session); + + $this->_redirect('/session'); + + }catch (Zend_Exception $e) { + echo "Error message 2: " . $e->getMessage() . "\n"; + } + print_a('saved'); + $this->_redirect('/session'); + } + else{ + print_a('not saved'); + } + } } public function editsessionAction() { - // action body + if (!isset($_POST["add"])){ + // TODO: ACL implementieren ob er editieren darf + $sessionID = $this->_request->getParam('sessionID'); + $session = new Application_Model_Session(); + + + $sessionmapper = new Application_Model_SessionMapper(); + $sessionmapper->find($sessionID,$session); + $session2 = $session->toArray(); + + $editsession = new Application_Form_Session(); + $editsession->populate($session2); + $this->view->editsession = $editsession; + + } else{ + try{ + $sessionID = $this->_request->getParam('sessionID'); + + $editsession = new Application_Form_Session($_POST); + + if ($editsession->isValid($_POST)) { + $session = new Application_Model_Session($_POST); + $session->setID($this->_request->getParam('sessionID')); + $sessionmapper = new Application_Model_SessionMapper(); + $sessionmapper->save($session); + echo 'valid'; + } + else + { + echo 'not valid'; + } + }catch (Zend_Exception $e) { + echo "Error message 2: " . $e->getMessage() . "\n"; + } + $this->_redirect('/session'); + } } public function deletesessionAction() { - // action body + $sessionID = $this->_request->getParam('sessionID'); + if(is_numeric($sessionID)){ + $deletesession = new Application_Model_Session(); + $deletesession->setID($sessionID); + $sessionmapper = new Application_Model_SessionMapper(); + $sessionmapper->delete($deletesession); + } + $this->_redirect('/session'); } diff --git a/application/forms/Session.php b/application/forms/Session.php new file mode 100644 index 0000000..f094676 --- /dev/null +++ b/application/forms/Session.php @@ -0,0 +1,70 @@ +setName("session"); + $this->setMethod('post'); + + $this->addElement('text', 'clientID', array( + 'filters' => array('StringTrim'), + 'validators' => array( + array('StringLength', false, array(0, 50)), + ), + 'required' => true, + 'label' => 'clientID:', + )); + + $this->addElement('text', 'bootosID', array( + 'filters' => array('StringTrim'), + 'validators' => array( + array('StringLength', false, array(0, 50)), + ), + 'required' => true, + 'label' => 'bootosID:', + )); +$this->addElement('text', 'bootisoID', array( + 'filters' => array('StringTrim'), + 'validators' => array( + array('StringLength', false, array(0, 50)), + ), + 'required' => true, + 'label' => 'bootisoID:', + )); +$this->addElement('text', 'time', array( + 'filters' => array('StringTrim'), + 'validators' => array( + array('StringLength', false, array(0, 50)), + ), + 'required' => true, + 'label' => 'time:', + )); +$this->addElement('text', 'ip', array( + 'filters' => array('StringTrim'), + 'validators' => array( + array('StringLength', false, array(0, 50)), + ), + 'required' => false, + 'label' => 'ip:', + )); +$this->addElement('text', 'ip6', array( + 'filters' => array('StringTrim'), + 'validators' => array( + array('StringLength', false, array(0, 50)), + ), + 'required' => false, + 'label' => 'ip6:', + )); + + $this->addElement('submit', 'add', array( + 'required' => false, + 'ignore' => true, + 'label' => 'Save', + )); + } + + +} + diff --git a/application/models/Session.php b/application/models/Session.php index b042c17..ca07ccb 100644 --- a/application/models/Session.php +++ b/application/models/Session.php @@ -5,6 +5,7 @@ class Application_Model_Session protected $_sessionID; protected $_clientID; protected $_bootosID; + protected $_bootisoID; protected $_time; protected $_ip; protected $_ip6; @@ -74,6 +75,15 @@ class Application_Model_Session $this->_bootosID = $_bootosID; return $this; } + public function getBootisoID() + { + return $this->_bootisoID; + } + public function setBootisoID($_bootisoID) + { + $this->_bootisoID = $_bootisoID; + return $this; + } public function getTime() { return $this->_time; diff --git a/application/models/SessionMapper.php b/application/models/SessionMapper.php index 57b2fdf..f836643 100644 --- a/application/models/SessionMapper.php +++ b/application/models/SessionMapper.php @@ -44,16 +44,22 @@ class Application_Model_SessionMapper return $this->_dbTable; } - public function save(Application_Model_Session $sesion) + public function save(Application_Model_Session $session) { - $data = array('sessionID'=> $sesion->getSessionID() ,'clientID'=> $sesion->getClientID() ,'bootosID'=> $sesion->getBootosID() ,'time'=> $sesion->getTime() ,'ip'=> $sesion->getIp() ,'ip6'=> $sesion->getIp6() ); - - if (null === ($id = $sesion->getID()) ) { - unset($data['sesionID']); + $data = array( 'sessionID'=> $session->getID() , + 'clientID'=> $session->getClientID() , + 'bootosID'=> $session->getBootosID() , + 'bootisoID'=> $session->getBootisoID() , + 'time'=> $session->getTime() , + 'ip'=> $session->getIp() , + 'ip6'=> $session->getIp6() ); + print_a($data); + if (null === ($id = $session->getID()) ) { + unset($data['sessionID']); $this->getDbTable()->insert($data); } else { - $this->getDbTable()->update($data, array('sesionID = ?' => $id)); + $this->getDbTable()->update($data, array('sessionID = ?' => $id)); } } @@ -62,7 +68,7 @@ class Application_Model_SessionMapper if (null === ($id = $sesion->getID()) ) { return; } else { - $this->getDbTable()->delete(array('sesionID = ?' => $id)); + $this->getDbTable()->delete(array('sessionID = ?' => $id)); } } @@ -75,7 +81,7 @@ class Application_Model_SessionMapper $row = $result->current(); - $sesion->setSessionID($row->sessionID)->setClientID($row->clientID)->setBootosID($row->bootosID)->setTime($row->time)->setIp($row->ip)->setIp6($row->ip6); + $sesion->setID($row->sessionID)->setClientID($row->clientID)->setBootosID($row->bootosID)->setBootisoID($row->bootisoID)->setTime($row->time)->setIp($row->ip)->setIp6($row->ip6); } public function fetchAll() @@ -85,7 +91,7 @@ class Application_Model_SessionMapper foreach ($resultSet as $row) { $entry = new Application_Model_Session(); - $entry->setSessionID($row->sessionID)->setClientID($row->clientID)->setBootosID($row->bootosID)->setTime($row->time)->setIp($row->ip)->setIp6($row->ip6); + $entry->setID($row->sessionID)->setClientID($row->clientID)->setBootosID($row->bootosID)->setBootisoID($row->bootisoID)->setTime($row->time)->setIp($row->ip)->setIp6($row->ip6); $entries[] = $entry; } diff --git a/application/views/scripts/session/createsession.phtml b/application/views/scripts/session/createsession.phtml index 81c476e..11fe7ce 100644 --- a/application/views/scripts/session/createsession.phtml +++ b/application/views/scripts/session/createsession.phtml @@ -1 +1,5 @@ -

View script for controller Session and script/action name createsession
\ No newline at end of file +

create session

+ +createsession; +?> diff --git a/application/views/scripts/session/editsession.phtml b/application/views/scripts/session/editsession.phtml index 987a332..88fb273 100644 --- a/application/views/scripts/session/editsession.phtml +++ b/application/views/scripts/session/editsession.phtml @@ -1 +1,5 @@ -

View script for controller Session and script/action name editsession
\ No newline at end of file +

edit session

+ +editsession; +?> diff --git a/application/views/scripts/session/index.phtml b/application/views/scripts/session/index.phtml index fe3c2d4..d26e818 100644 --- a/application/views/scripts/session/index.phtml +++ b/application/views/scripts/session/index.phtml @@ -1 +1,48 @@ -

View script for controller Session and script/action name index
\ No newline at end of file +

Session

+ +

create new session

+ + + + + + + + + + + +sessions as $session): ?> + + + + + + + + + + + + +
SessionIDClientIDBootosIDBootIsoIDTimeIPIPv6
escape($session->getID()) ?>escape($session->getClientID()) ?>escape($session->getBootosID()) ?>escape($session->getBootisoID()) ?>escape($session->getTime()) ?>escape($session->getIp()) ?>escape($session->getIp6()) ?>edit filterdelete filter
-- cgit v1.2.3-55-g7522