From 07e3636f3ef4a666db0fefbc1663bf6c1e10b996 Mon Sep 17 00:00:00 2001 From: michael pereira Date: Tue, 8 Feb 2011 13:18:06 +0100 Subject: MapperScript & Mapper angelegt (alle die einen Primärschlüssel besitzen) --- application/configs/application.ini | 26 ++++++ application/controllers/AuthController.php | 2 +- application/models/BootMenuMapper.php | 67 +++++++++++++++ application/models/ClientMapper.php | 132 +++++++++++++++-------------- application/models/ConfigMapper.php | 67 +++++++++++++++ application/models/FilterMapper.php | 67 +++++++++++++++ application/models/FilterTypeMapper.php | 67 +++++++++++++++ application/models/GroupGroupsMapper.php | 67 +++++++++++++++ application/models/GroupMapper.php | 67 +++++++++++++++ application/models/GroupRequestMapper.php | 67 +++++++++++++++ application/models/MembershipMapper.php | 67 +++++++++++++++ application/models/PersonMapper.php | 46 +--------- application/models/PoolMapper.php | 67 +++++++++++++++ application/models/RightMapper.php | 67 +++++++++++++++ application/models/RoleMapper.php | 67 +++++++++++++++ application/models/SessionMapper.php | 67 +++++++++++++++ createDefaultMapper/mapper.sh | 35 ++++++++ createDefaultMapper/mappertemplate | 75 ++++++++++++++++ 18 files changed, 1013 insertions(+), 107 deletions(-) create mode 100644 application/configs/application.ini create mode 100644 createDefaultMapper/mapper.sh create mode 100644 createDefaultMapper/mappertemplate diff --git a/application/configs/application.ini b/application/configs/application.ini new file mode 100644 index 0000000..6970da3 --- /dev/null +++ b/application/configs/application.ini @@ -0,0 +1,26 @@ +[production] +phpSettings.display_startup_errors = 0 +phpSettings.display_errors = 0 +includePaths.library = APPLICATION_PATH "/../library" +bootstrap.path = APPLICATION_PATH "/Bootstrap.php" +bootstrap.class = "Bootstrap" +appnamespace = "Application" +resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers" +resources.frontController.params.displayExceptions = 0 +resources.db.adapter = PDO_MYSQL +resources.db.params.host = localhost +resources.db.params.username = root +resources.db.params.password = lsfks +resources.db.params.dbname = pbs +resources.db.isDefaultTableAdapter = true + +[staging : production] + +[testing : production] +phpSettings.display_startup_errors = 1 +phpSettings.display_errors = 1 + +[development : production] +phpSettings.display_startup_errors = 1 +phpSettings.display_errors = 1 +resources.frontController.params.displayExceptions = 1 diff --git a/application/controllers/AuthController.php b/application/controllers/AuthController.php index 588ffe3..4264e7b 100644 --- a/application/controllers/AuthController.php +++ b/application/controllers/AuthController.php @@ -59,7 +59,7 @@ class AuthController extends Zend_Controller_Action $person = new Application_Model_Person($_POST); if ($person != null) { echo "Erfolgreich registriert"; - # var_dump($person); + var_dump($person); //$this->_redirect('/auth/login'); return; } else { diff --git a/application/models/BootMenuMapper.php b/application/models/BootMenuMapper.php index 92be857..a55bce4 100644 --- a/application/models/BootMenuMapper.php +++ b/application/models/BootMenuMapper.php @@ -2,7 +2,74 @@ class Application_Model_BootMenuMapper { + + protected $_dbTable; + public function setDbTable($dbTable) + { + if (is_string($dbTable)) { + $dbTable = new $dbTable(); + } + if (!$dbTable instanceof Zend_Db_Table_Abstract) { + throw new Exception('Invalid table data gateway provided'); + } + + $this->_dbTable = $dbTable; + + return $this; + } + + public function getDbTable() + { + if (null === $this->_dbTable) { + $this->setDbTable('Application_Model_DbTable_Person'); + } + + return $this->_dbTable; + } + + public function save(Application_Model_BootMenu $bootmenu) + { + + $data = array('bootmenuID'=> $bootmenu->getID() ,'membershipID'=> $bootmenu->getMembershipID() ,'title'=> $bootmenu->getTitle() ,'time'=> $bootmenu->getTime() ); + + if (null === ($id = $bootmenu->getID()) ) { + unset($data['id']); + $this->getDbTable()->insert($data); + } else { + $this->getDbTable()->update($data, array('id = ?' => $id)); + } + } + + public function find($id, Application_Model_BootMenu $bootmenu) + { + $result = $this->getDbTable()->find($id); + if (0 == count($result)) { + return; + } + + $row = $result->current(); + + $bootmenu->setID($row->bootmenuID)->setMembershipID($row->membershipID)->setTitle($row->title)->setTime($row->time); + } + + public function fetchAll() + { + $resultSet = $this->getDbTable()->fetchAll(); + $entries = array(); + foreach ($resultSet as $row) { + $entry = new Application_Model_BootMenu(); + + $entry->setID($row->bootmenuID)->setMembershipID($row->membershipID)->setTitle($row->title)->setTime($row->time); + + $entries[] = $entry; + } + + return $entries; + } + + + } diff --git a/application/models/ClientMapper.php b/application/models/ClientMapper.php index f1e5852..17c4d4d 100644 --- a/application/models/ClientMapper.php +++ b/application/models/ClientMapper.php @@ -2,70 +2,74 @@ class Application_Model_ClientMapper { - + protected $_dbTable; - - public function setDbTable($dbTable) - { - if (is_string($dbTable)) { - $dbTable = new $dbTable(); - } - if (!$dbTable instanceof Zend_Db_Table_Abstract) { - throw new Exception('Invalid table data gateway provided'); - } - $this->_dbTable = $dbTable; - return $this; - } - - public function getDbTable() - { - if (null === $this->_dbTable) { - $this->setDbTable('Application_Model_DbTable_Guestbook'); - } - return $this->_dbTable; - } - - public function save(Application_Model_Client $client) - { - $data = array( - 'clientID' => $client->getID(), - 'macadress' => $client->getMacadress(), - 'hardwarehash' => $client->getHardwarehash, - ); - - if (null === ($clientID = $client->getId())) { - unset($data['clientID']); - $this->getDbTable()->insert($data); - } else { - $this->getDbTable()->update($data, array('clientID = ?' => $clientID)); - } - } - - public function find($clientID, Application_Model_Client $client) - { - $result = $this->getDbTable()->find($clientID); - if (0 == count($result)) { - return; - } - $row = $result->current(); - $guestbook->setID($row->clientID) - ->setMacadress($row->macadress) - ->setHardwarehash($row->hardwarehash); - } - - public function fetchAll() - { - $resultSet = $this->getDbTable()->fetchAll(); - $entries = array(); - foreach ($resultSet as $row) { - $entry = new Application_Model_Client(); - $entry->setId($row->clientID) - ->setMacadress($row->macadress) - ->setHardwarehash($row->hardwarehash); - $entries[] = $entry; - } - return $entries; - } -} + public function setDbTable($dbTable) + { + if (is_string($dbTable)) { + $dbTable = new $dbTable(); + } + + if (!$dbTable instanceof Zend_Db_Table_Abstract) { + throw new Exception('Invalid table data gateway provided'); + } + + $this->_dbTable = $dbTable; + + return $this; + } + + public function getDbTable() + { + if (null === $this->_dbTable) { + $this->setDbTable('Application_Model_DbTable_Person'); + } + + return $this->_dbTable; + } + + public function save(Application_Model_Client $client) + { + + $data = array('clientID'=> $client->getID() ,'macadress'=> $client->getMacadress() ,'hardwarehash'=> $client->getHardwarehash() ); + + if (null === ($id = $client->getID()) ) { + unset($data['id']); + $this->getDbTable()->insert($data); + } else { + $this->getDbTable()->update($data, array('id = ?' => $id)); + } + } + + public function find($id, Application_Model_Client $client) + { + $result = $this->getDbTable()->find($id); + if (0 == count($result)) { + return; + } + + $row = $result->current(); + + $client->setID($row->clientID)->setMacadress($row->macadress)->setHardwarehash($row->hardwarehash); + } + + public function fetchAll() + { + $resultSet = $this->getDbTable()->fetchAll(); + $entries = array(); + foreach ($resultSet as $row) { + $entry = new Application_Model_Client(); + + $entry->setID($row->clientID)->setMacadress($row->macadress)->setHardwarehash($row->hardwarehash); + + $entries[] = $entry; + } + + return $entries; + } + + + +} diff --git a/application/models/ConfigMapper.php b/application/models/ConfigMapper.php index 3933aaf..64c82f8 100644 --- a/application/models/ConfigMapper.php +++ b/application/models/ConfigMapper.php @@ -2,7 +2,74 @@ class Application_Model_ConfigMapper { + + protected $_dbTable; + public function setDbTable($dbTable) + { + if (is_string($dbTable)) { + $dbTable = new $dbTable(); + } + if (!$dbTable instanceof Zend_Db_Table_Abstract) { + throw new Exception('Invalid table data gateway provided'); + } + + $this->_dbTable = $dbTable; + + return $this; + } + + public function getDbTable() + { + if (null === $this->_dbTable) { + $this->setDbTable('Application_Model_DbTable_Person'); + } + + return $this->_dbTable; + } + + public function save(Application_Model_Config $config) + { + + $data = array('configID'=> $config->getID() ,'membershipID'=> $config->getMembershipID() ,'shellscript'=> $config->getShellscript() ); + + if (null === ($id = $config->getID()) ) { + unset($data['id']); + $this->getDbTable()->insert($data); + } else { + $this->getDbTable()->update($data, array('id = ?' => $id)); + } + } + + public function find($id, Application_Model_Config $config) + { + $result = $this->getDbTable()->find($id); + if (0 == count($result)) { + return; + } + + $row = $result->current(); + + $config->setID($row->configID)->setMembershipID($row->membershipID)->setShellscript($row->shellscript); + } + + public function fetchAll() + { + $resultSet = $this->getDbTable()->fetchAll(); + $entries = array(); + foreach ($resultSet as $row) { + $entry = new Application_Model_Config(); + + $entry->setID($row->configID)->setMembershipID($row->membershipID)->setShellscript($row->shellscript); + + $entries[] = $entry; + } + + return $entries; + } + + + } diff --git a/application/models/FilterMapper.php b/application/models/FilterMapper.php index 8a2e1b3..c418404 100644 --- a/application/models/FilterMapper.php +++ b/application/models/FilterMapper.php @@ -2,7 +2,74 @@ class Application_Model_FilterMapper { + + protected $_dbTable; + public function setDbTable($dbTable) + { + if (is_string($dbTable)) { + $dbTable = new $dbTable(); + } + if (!$dbTable instanceof Zend_Db_Table_Abstract) { + throw new Exception('Invalid table data gateway provided'); + } + + $this->_dbTable = $dbTable; + + return $this; + } + + public function getDbTable() + { + if (null === $this->_dbTable) { + $this->setDbTable('Application_Model_DbTable_Person'); + } + + return $this->_dbTable; + } + + public function save(Application_Model_Filter $filter) + { + + $data = array('filterID'=> $filter->getID() ,'membershipID'=> $filter->getMembershipID() ,'groupID'=> $filter->getGroupID() ,'bootmenuID'=> $filter->getBootmenuID() ,'title'=> $filter->getTitle() ,'description'=> $filter->getDescription() ,'created'=> $filter->getCreated() ,'priority'=> $filter->getPriority() ); + + if (null === ($id = $filter->getID()) ) { + unset($data['id']); + $this->getDbTable()->insert($data); + } else { + $this->getDbTable()->update($data, array('id = ?' => $id)); + } + } + + public function find($id, Application_Model_Filter $filter) + { + $result = $this->getDbTable()->find($id); + if (0 == count($result)) { + return; + } + + $row = $result->current(); + + $filter->setID($row->filterID)->setMembershipID($row->membershipID)->setGroupID($row->groupID)->setBootmenuID($row->bootmenuID)->setTitle($row->title)->setDescription($row->description)->setCreated($row->created)->setPriority($row->priority); + } + + public function fetchAll() + { + $resultSet = $this->getDbTable()->fetchAll(); + $entries = array(); + foreach ($resultSet as $row) { + $entry = new Application_Model_Filter(); + + $entry->setID($row->filterID)->setMembershipID($row->membershipID)->setGroupID($row->groupID)->setBootmenuID($row->bootmenuID)->setTitle($row->title)->setDescription($row->description)->setCreated($row->created)->setPriority($row->priority); + + $entries[] = $entry; + } + + return $entries; + } + + + } diff --git a/application/models/FilterTypeMapper.php b/application/models/FilterTypeMapper.php index e8d673b..61f3422 100644 --- a/application/models/FilterTypeMapper.php +++ b/application/models/FilterTypeMapper.php @@ -2,7 +2,74 @@ class Application_Model_FilterTypeMapper { + + protected $_dbTable; + public function setDbTable($dbTable) + { + if (is_string($dbTable)) { + $dbTable = new $dbTable(); + } + if (!$dbTable instanceof Zend_Db_Table_Abstract) { + throw new Exception('Invalid table data gateway provided'); + } + + $this->_dbTable = $dbTable; + + return $this; + } + + public function getDbTable() + { + if (null === $this->_dbTable) { + $this->setDbTable('Application_Model_DbTable_Person'); + } + + return $this->_dbTable; + } + + public function save(Application_Model_FilterType $filtertype) + { + + $data = array('filtertypeID'=> $filtertype->getID() ,'filtertypename'=> $filtertype->getFiltertypename() ); + + if (null === ($id = $filtertype->getID()) ) { + unset($data['id']); + $this->getDbTable()->insert($data); + } else { + $this->getDbTable()->update($data, array('id = ?' => $id)); + } + } + + public function find($id, Application_Model_FilterType $filtertype) + { + $result = $this->getDbTable()->find($id); + if (0 == count($result)) { + return; + } + + $row = $result->current(); + + $filtertype->setID($row->filtertypeID)->setFiltertypename($row->filtertypename); + } + + public function fetchAll() + { + $resultSet = $this->getDbTable()->fetchAll(); + $entries = array(); + foreach ($resultSet as $row) { + $entry = new Application_Model_FilterType(); + + $entry->setID($row->filtertypeID)->setFiltertypename($row->filtertypename); + + $entries[] = $entry; + } + + return $entries; + } + + + } diff --git a/application/models/GroupGroupsMapper.php b/application/models/GroupGroupsMapper.php index 44d5777..bf0361c 100644 --- a/application/models/GroupGroupsMapper.php +++ b/application/models/GroupGroupsMapper.php @@ -2,7 +2,74 @@ class Application_Model_GroupGroupsMapper { + + protected $_dbTable; + public function setDbTable($dbTable) + { + if (is_string($dbTable)) { + $dbTable = new $dbTable(); + } + if (!$dbTable instanceof Zend_Db_Table_Abstract) { + throw new Exception('Invalid table data gateway provided'); + } + + $this->_dbTable = $dbTable; + + return $this; + } + + public function getDbTable() + { + if (null === $this->_dbTable) { + $this->setDbTable('Application_Model_DbTable_Person'); + } + + return $this->_dbTable; + } + + public function save(Application_Model_GroupGroups $groupgroups) + { + + $data = array(); + + if (null === ($id = $groupgroups->getID()) ) { + unset($data['id']); + $this->getDbTable()->insert($data); + } else { + $this->getDbTable()->update($data, array('id = ?' => $id)); + } + } + + public function find($id, Application_Model_GroupGroups $groupgroups) + { + $result = $this->getDbTable()->find($id); + if (0 == count($result)) { + return; + } + + $row = $result->current(); + + $groupgroups; + } + + public function fetchAll() + { + $resultSet = $this->getDbTable()->fetchAll(); + $entries = array(); + foreach ($resultSet as $row) { + $entry = new Application_Model_GroupGroups(); + + $entry; + + $entries[] = $entry; + } + + return $entries; + } + + + } diff --git a/application/models/GroupMapper.php b/application/models/GroupMapper.php index d15f0b9..85a2878 100644 --- a/application/models/GroupMapper.php +++ b/application/models/GroupMapper.php @@ -2,7 +2,74 @@ class Application_Model_GroupMapper { + + protected $_dbTable; + public function setDbTable($dbTable) + { + if (is_string($dbTable)) { + $dbTable = new $dbTable(); + } + if (!$dbTable instanceof Zend_Db_Table_Abstract) { + throw new Exception('Invalid table data gateway provided'); + } + + $this->_dbTable = $dbTable; + + return $this; + } + + public function getDbTable() + { + if (null === $this->_dbTable) { + $this->setDbTable('Application_Model_DbTable_Person'); + } + + return $this->_dbTable; + } + + public function save(Application_Model_Group $group) + { + + $data = array('groupID'=> $group->getID() ,'title'=> $group->getTitle() ,'description'=> $group->getDescription() ); + + if (null === ($id = $group->getID()) ) { + unset($data['id']); + $this->getDbTable()->insert($data); + } else { + $this->getDbTable()->update($data, array('id = ?' => $id)); + } + } + + public function find($id, Application_Model_Group $group) + { + $result = $this->getDbTable()->find($id); + if (0 == count($result)) { + return; + } + + $row = $result->current(); + + $group->setID($row->groupID)->setTitle($row->title)->setDescription($row->description); + } + + public function fetchAll() + { + $resultSet = $this->getDbTable()->fetchAll(); + $entries = array(); + foreach ($resultSet as $row) { + $entry = new Application_Model_Group(); + + $entry->setID($row->groupID)->setTitle($row->title)->setDescription($row->description); + + $entries[] = $entry; + } + + return $entries; + } + + + } diff --git a/application/models/GroupRequestMapper.php b/application/models/GroupRequestMapper.php index c74604e..952e36a 100644 --- a/application/models/GroupRequestMapper.php +++ b/application/models/GroupRequestMapper.php @@ -2,7 +2,74 @@ class Application_Model_GroupRequestMapper { + + protected $_dbTable; + public function setDbTable($dbTable) + { + if (is_string($dbTable)) { + $dbTable = new $dbTable(); + } + if (!$dbTable instanceof Zend_Db_Table_Abstract) { + throw new Exception('Invalid table data gateway provided'); + } + + $this->_dbTable = $dbTable; + + return $this; + } + + public function getDbTable() + { + if (null === $this->_dbTable) { + $this->setDbTable('Application_Model_DbTable_Person'); + } + + return $this->_dbTable; + } + + public function save(Application_Model_GroupRequest $grouprequest) + { + + $data = array('grouprequestID'=> $grouprequest->getID() ,'groupID'=> $grouprequest->getGroupID() ,'personID'=> $grouprequest->getPersonID() ,'time'=> $grouprequest->getTime() ); + + if (null === ($id = $grouprequest->getID()) ) { + unset($data['id']); + $this->getDbTable()->insert($data); + } else { + $this->getDbTable()->update($data, array('id = ?' => $id)); + } + } + + public function find($id, Application_Model_GroupRequest $grouprequest) + { + $result = $this->getDbTable()->find($id); + if (0 == count($result)) { + return; + } + + $row = $result->current(); + + $grouprequest->setID($row->grouprequestID)->setGroupID($row->groupID)->setPersonID($row->personID)->setTime($row->time); + } + + public function fetchAll() + { + $resultSet = $this->getDbTable()->fetchAll(); + $entries = array(); + foreach ($resultSet as $row) { + $entry = new Application_Model_GroupRequest(); + + $entry->setID($row->grouprequestID)->setGroupID($row->groupID)->setPersonID($row->personID)->setTime($row->time); + + $entries[] = $entry; + } + + return $entries; + } + + + } diff --git a/application/models/MembershipMapper.php b/application/models/MembershipMapper.php index 7452b80..fd471c0 100644 --- a/application/models/MembershipMapper.php +++ b/application/models/MembershipMapper.php @@ -2,7 +2,74 @@ class Application_Model_MembershipMapper { + + protected $_dbTable; + public function setDbTable($dbTable) + { + if (is_string($dbTable)) { + $dbTable = new $dbTable(); + } + if (!$dbTable instanceof Zend_Db_Table_Abstract) { + throw new Exception('Invalid table data gateway provided'); + } + + $this->_dbTable = $dbTable; + + return $this; + } + + public function getDbTable() + { + if (null === $this->_dbTable) { + $this->setDbTable('Application_Model_DbTable_Person'); + } + + return $this->_dbTable; + } + + public function save(Application_Model_Membership $membership) + { + + $data = array('membershipID'=> $membership->getID() ,'groupID'=> $membership->getGroupID() ,'roleID'=> $membership->getRoleID() ,'personID'=> $membership->getPersonID() ); + + if (null === ($id = $membership->getID()) ) { + unset($data['id']); + $this->getDbTable()->insert($data); + } else { + $this->getDbTable()->update($data, array('id = ?' => $id)); + } + } + + public function find($id, Application_Model_Membership $membership) + { + $result = $this->getDbTable()->find($id); + if (0 == count($result)) { + return; + } + + $row = $result->current(); + + $membership->setID($row->membershipID)->setGroupID($row->groupID)->setRoleID($row->roleID)->setPersonID($row->personID); + } + + public function fetchAll() + { + $resultSet = $this->getDbTable()->fetchAll(); + $entries = array(); + foreach ($resultSet as $row) { + $entry = new Application_Model_Membership(); + + $entry->setID($row->membershipID)->setGroupID($row->groupID)->setRoleID($row->roleID)->setPersonID($row->personID); + + $entries[] = $entry; + } + + return $entries; + } + + + } diff --git a/application/models/PersonMapper.php b/application/models/PersonMapper.php index 632c3ee..b00c457 100644 --- a/application/models/PersonMapper.php +++ b/application/models/PersonMapper.php @@ -32,21 +32,7 @@ class Application_Model_PersonMapper public function save(Application_Model_Person $person) { - $data = array( - 'personID' => $tablenamevar->getID(), - 'title' => $tablenamevar->getTitle(), - 'name' => $tablenamevar->getName(), - 'firstname' => $tablenamevar->getFirstname(), - 'street' => $tablenamevar->getStreet(), - 'housenumber' => $tablenamevar->getHousenumber(), - 'city' => $tablenamevar->getCity(), - 'postalcode' => $tablenamevar->getPostalcode(), - 'logindate' => $tablenamevar->getLogindate(), - 'registerdate' => $tablenamevar->getRegisterdate(), - 'email' => $tablenamevar->getEmail(), - 'login' => $tablenamevar->getLogin(), - 'password' => $tablenamevar->getPassword() - ); + $data = array('personID'=> $person->getID() ,'title'=> $person->getTitle() ,'name'=> $person->getName() ,'firstname'=> $person->getFirstname() ,'street'=> $person->getStreet() ,'housenumber'=> $person->getHousenumber() ,'city'=> $person->getCity() ,'postalcode'=> $person->getPostalcode() ,'logindate'=> $person->getLogindate() ,'registerdate'=> $person->getRegisterdate() ,'email'=> $person->getEmail() ,'login'=> $person->getLogin() ,'password'=> $person->getPassword() ); if (null === ($id = $person->getID()) ) { unset($data['id']); @@ -65,19 +51,7 @@ class Application_Model_PersonMapper $row = $result->current(); - $tablenamevar->setID($row->personID) - ->setTitle($row->title) - ->setName($row->name) - ->setFirstname($row->firstname) - ->setStreet($row->street) - ->setHousenumber($row->housenumber) - ->setCity($row->city) - ->setPostalcode($row->postalcode) - ->setLogindate($row->logindate) - ->setRegisterdate($row->registerdate) - ->setEmail($row->email) - ->setLogin($row->login) - ->setPassword($row->password); + $person->setID($row->personID)->setTitle($row->title)->setName($row->name)->setFirstname($row->firstname)->setStreet($row->street)->setHousenumber($row->housenumber)->setCity($row->city)->setPostalcode($row->postalcode)->setLogindate($row->logindate)->setRegisterdate($row->registerdate)->setEmail($row->email)->setLogin($row->login)->setPassword($row->password); } public function fetchAll() @@ -87,20 +61,8 @@ class Application_Model_PersonMapper foreach ($resultSet as $row) { $entry = new Application_Model_Person(); - $entry->setID($row->personID) - ->setTitle($row->title) - ->setName($row->name) - ->setFirstname($row->firstname) - ->setStreet($row->street) - ->setHousenumber($row->housenumber) - ->setCity($row->city) - ->setPostalcode($row->postalcode) - ->setLogindate($row->logindate) - ->setRegisterdate($row->registerdate) - ->setEmail($row->email) - ->setLogin($row->login) - ->setPassword($row->password); - + $entry->setID($row->personID)->setTitle($row->title)->setName($row->name)->setFirstname($row->firstname)->setStreet($row->street)->setHousenumber($row->housenumber)->setCity($row->city)->setPostalcode($row->postalcode)->setLogindate($row->logindate)->setRegisterdate($row->registerdate)->setEmail($row->email)->setLogin($row->login)->setPassword($row->password); + $entries[] = $entry; } diff --git a/application/models/PoolMapper.php b/application/models/PoolMapper.php index 099aa1e..c788a18 100644 --- a/application/models/PoolMapper.php +++ b/application/models/PoolMapper.php @@ -2,7 +2,74 @@ class Application_Model_PoolMapper { + + protected $_dbTable; + public function setDbTable($dbTable) + { + if (is_string($dbTable)) { + $dbTable = new $dbTable(); + } + if (!$dbTable instanceof Zend_Db_Table_Abstract) { + throw new Exception('Invalid table data gateway provided'); + } + + $this->_dbTable = $dbTable; + + return $this; + } + + public function getDbTable() + { + if (null === $this->_dbTable) { + $this->setDbTable('Application_Model_DbTable_Person'); + } + + return $this->_dbTable; + } + + public function save(Application_Model_Pool $pol) + { + + $data = array('poolID'=> $pol->getID() ,'title'=> $pol->getTitle() ,'description'=> $pol->getDescription() ,'location'=> $pol->getLocation() ); + + if (null === ($id = $pol->getID()) ) { + unset($data['id']); + $this->getDbTable()->insert($data); + } else { + $this->getDbTable()->update($data, array('id = ?' => $id)); + } + } + + public function find($id, Application_Model_Pool $pol) + { + $result = $this->getDbTable()->find($id); + if (0 == count($result)) { + return; + } + + $row = $result->current(); + + $pol->setID($row->poolID)->setTitle($row->title)->setDescription($row->description)->setLocation($row->location); + } + + public function fetchAll() + { + $resultSet = $this->getDbTable()->fetchAll(); + $entries = array(); + foreach ($resultSet as $row) { + $entry = new Application_Model_Pool(); + + $entry->setID($row->poolID)->setTitle($row->title)->setDescription($row->description)->setLocation($row->location); + + $entries[] = $entry; + } + + return $entries; + } + + + } diff --git a/application/models/RightMapper.php b/application/models/RightMapper.php index 738db0e..cc98d24 100644 --- a/application/models/RightMapper.php +++ b/application/models/RightMapper.php @@ -2,7 +2,74 @@ class Application_Model_RightMapper { + + protected $_dbTable; + public function setDbTable($dbTable) + { + if (is_string($dbTable)) { + $dbTable = new $dbTable(); + } + if (!$dbTable instanceof Zend_Db_Table_Abstract) { + throw new Exception('Invalid table data gateway provided'); + } + + $this->_dbTable = $dbTable; + + return $this; + } + + public function getDbTable() + { + if (null === $this->_dbTable) { + $this->setDbTable('Application_Model_DbTable_Person'); + } + + return $this->_dbTable; + } + + public function save(Application_Model_Right $right) + { + + $data = array('rightID'=> $right->getID() ,'title'=> $right->getTitle() ,'description'=> $right->getDescription() ); + + if (null === ($id = $right->getID()) ) { + unset($data['id']); + $this->getDbTable()->insert($data); + } else { + $this->getDbTable()->update($data, array('id = ?' => $id)); + } + } + + public function find($id, Application_Model_Right $right) + { + $result = $this->getDbTable()->find($id); + if (0 == count($result)) { + return; + } + + $row = $result->current(); + + $right->setID($row->rightID)->setTitle($row->title)->setDescription($row->description); + } + + public function fetchAll() + { + $resultSet = $this->getDbTable()->fetchAll(); + $entries = array(); + foreach ($resultSet as $row) { + $entry = new Application_Model_Right(); + + $entry->setID($row->rightID)->setTitle($row->title)->setDescription($row->description); + + $entries[] = $entry; + } + + return $entries; + } + + + } diff --git a/application/models/RoleMapper.php b/application/models/RoleMapper.php index 020fcca..6ea7079 100644 --- a/application/models/RoleMapper.php +++ b/application/models/RoleMapper.php @@ -2,7 +2,74 @@ class Application_Model_RoleMapper { + + protected $_dbTable; + public function setDbTable($dbTable) + { + if (is_string($dbTable)) { + $dbTable = new $dbTable(); + } + if (!$dbTable instanceof Zend_Db_Table_Abstract) { + throw new Exception('Invalid table data gateway provided'); + } + + $this->_dbTable = $dbTable; + + return $this; + } + + public function getDbTable() + { + if (null === $this->_dbTable) { + $this->setDbTable('Application_Model_DbTable_Person'); + } + + return $this->_dbTable; + } + + public function save(Application_Model_Role $role) + { + + $data = array('roleID'=> $role->getID() ,'groupID'=> $role->getGroupID() ,'title'=> $role->getTitle() ,'description'=> $role->getDescription() ); + + if (null === ($id = $role->getID()) ) { + unset($data['id']); + $this->getDbTable()->insert($data); + } else { + $this->getDbTable()->update($data, array('id = ?' => $id)); + } + } + + public function find($id, Application_Model_Role $role) + { + $result = $this->getDbTable()->find($id); + if (0 == count($result)) { + return; + } + + $row = $result->current(); + + $role->setID($row->roleID)->setGroupID($row->groupID)->setTitle($row->title)->setDescription($row->description); + } + + public function fetchAll() + { + $resultSet = $this->getDbTable()->fetchAll(); + $entries = array(); + foreach ($resultSet as $row) { + $entry = new Application_Model_Role(); + + $entry->setID($row->roleID)->setGroupID($row->groupID)->setTitle($row->title)->setDescription($row->description); + + $entries[] = $entry; + } + + return $entries; + } + + + } diff --git a/application/models/SessionMapper.php b/application/models/SessionMapper.php index aa1e365..02fba66 100644 --- a/application/models/SessionMapper.php +++ b/application/models/SessionMapper.php @@ -2,7 +2,74 @@ class Application_Model_SessionMapper { + + protected $_dbTable; + public function setDbTable($dbTable) + { + if (is_string($dbTable)) { + $dbTable = new $dbTable(); + } + if (!$dbTable instanceof Zend_Db_Table_Abstract) { + throw new Exception('Invalid table data gateway provided'); + } + + $this->_dbTable = $dbTable; + + return $this; + } + + public function getDbTable() + { + if (null === $this->_dbTable) { + $this->setDbTable('Application_Model_DbTable_Person'); + } + + return $this->_dbTable; + } + + public function save(Application_Model_Session $sesion) + { + + $data = array('sessionID'=> $sesion->getID() ,'clientID'=> $sesion->getClientID() ,'bootosID'=> $sesion->getBootosID() ,'time'=> $sesion->getTime() ,'ip'=> $sesion->getIp() ,'ip6'=> $sesion->getIp6() ); + + if (null === ($id = $sesion->getID()) ) { + unset($data['id']); + $this->getDbTable()->insert($data); + } else { + $this->getDbTable()->update($data, array('id = ?' => $id)); + } + } + + public function find($id, Application_Model_Session $sesion) + { + $result = $this->getDbTable()->find($id); + if (0 == count($result)) { + return; + } + + $row = $result->current(); + + $sesion->setID($row->sessionID)->setClientID($row->clientID)->setBootosID($row->bootosID)->setTime($row->time)->setIp($row->ip)->setIp6($row->ip6); + } + + public function fetchAll() + { + $resultSet = $this->getDbTable()->fetchAll(); + $entries = array(); + foreach ($resultSet as $row) { + $entry = new Application_Model_Session(); + + $entry->setID($row->sessionID)->setClientID($row->clientID)->setBootosID($row->bootosID)->setTime($row->time)->setIp($row->ip)->setIp6($row->ip6); + + $entries[] = $entry; + } + + return $entries; + } + + + } diff --git a/createDefaultMapper/mapper.sh b/createDefaultMapper/mapper.sh new file mode 100644 index 0000000..6d98bc3 --- /dev/null +++ b/createDefaultMapper/mapper.sh @@ -0,0 +1,35 @@ +#!/bin/sh +id=$(grep -c "getID" $1) +if [ $id -eq 0 ]; then +echo "$1 enthält keinen Primärschlüssel" +exit +fi + +modelname=$(basename $1 .php) +modelmapper=${modelname}Mapper +modelmapperfile=$(dirname $1)/${modelmapper}.php +modelvar=$(echo "$modelname" | tr -s '[A-Z]' '[a-z]') +getID="get${modelname}ID" +setID="set${modelname}ID" +cp mappertemplate ${modelmapperfile} + +savedata=$(grep "protected" $1 | awk -v SQ="\'" -F '_|;' '{ + printf "," SQ $2 SQ "=> $MVAR->get"; + split($2,a,""); a[1]=toupper(a[1]); + for(i=1; i<=length($2); i++){printf a[i]}; + printf "() "}') + +find=$(grep "protected" $1 | awk -F '_|;' '{ + printf "->set"; split($2,a,""); + a[1]=toupper(a[1]); + for(i=1; i<=length($2); i++){printf a[i]}; + printf "($row->%s)", $2}') + +sed -i "s/SAVEDATA/${savedata}/g" ${modelmapperfile} +sed -i "s/FIND/${find}/g" ${modelmapperfile} +sed -i "s/${getID}/getID/g" ${modelmapperfile} +sed -i "s/${setID}/setID/g" ${modelmapperfile} +sed -i "s/array(,/array(/g" ${modelmapperfile} +sed -i "s/MODEL/${modelname}/g" ${modelmapperfile} +sed -i "s/MVAR/${modelvar}/g" ${modelmapperfile} +sed -i "s/MAPPER/${modelmapper}/g" ${modelmapperfile} diff --git a/createDefaultMapper/mappertemplate b/createDefaultMapper/mappertemplate new file mode 100644 index 0000000..f994184 --- /dev/null +++ b/createDefaultMapper/mappertemplate @@ -0,0 +1,75 @@ +_dbTable = $dbTable; + + return $this; + } + + public function getDbTable() + { + if (null === $this->_dbTable) { + $this->setDbTable('Application_Model_DbTable_Person'); + } + + return $this->_dbTable; + } + + public function save(Application_Model_MODEL $MVAR) + { + + $data = array(SAVEDATA); + + if (null === ($id = $MVAR->getID()) ) { + unset($data['id']); + $this->getDbTable()->insert($data); + } else { + $this->getDbTable()->update($data, array('id = ?' => $id)); + } + } + + public function find($id, Application_Model_MODEL $MVAR) + { + $result = $this->getDbTable()->find($id); + if (0 == count($result)) { + return; + } + + $row = $result->current(); + + $MVARFIND; + } + + public function fetchAll() + { + $resultSet = $this->getDbTable()->fetchAll(); + $entries = array(); + foreach ($resultSet as $row) { + $entry = new Application_Model_MODEL(); + + $entryFIND; + + $entries[] = $entry; + } + + return $entries; + } + + + +} + -- cgit v1.2.3-55-g7522