diff options
author | michael pereira | 2011-04-20 18:49:49 +0200 |
---|---|---|
committer | michael pereira | 2011-04-20 18:49:49 +0200 |
commit | cc3660add480ac1dc217d7f853b325db7d6ec7d0 (patch) | |
tree | 8056c87777d806c613a607c3f479ce07475b5db6 /application/models | |
parent | API + Fixes (diff) | |
parent | Url für Config gekürzt (diff) | |
download | pbs2-cc3660add480ac1dc217d7f853b325db7d6ec7d0.tar.gz pbs2-cc3660add480ac1dc217d7f853b325db7d6ec7d0.tar.xz pbs2-cc3660add480ac1dc217d7f853b325db7d6ec7d0.zip |
merges
Diffstat (limited to 'application/models')
-rw-r--r-- | application/models/BootMenu.php | 10 | ||||
-rw-r--r-- | application/models/BootMenuMapper.php | 26 | ||||
-rw-r--r-- | application/models/BootOsUser.php | 154 | ||||
-rw-r--r-- | application/models/Client.php | 10 | ||||
-rw-r--r-- | application/models/ClientMapper.php | 15 | ||||
-rw-r--r-- | application/models/DbTable/BootOsUser.php | 20 | ||||
-rw-r--r-- | application/models/DbTable/HomeType.php | 20 | ||||
-rw-r--r-- | application/models/HomeType.php | 111 | ||||
-rw-r--r-- | application/models/HomeTypeMapper.php | 142 |
9 files changed, 501 insertions, 7 deletions
diff --git a/application/models/BootMenu.php b/application/models/BootMenu.php index 82e771a..dae3776 100644 --- a/application/models/BootMenu.php +++ b/application/models/BootMenu.php @@ -16,6 +16,7 @@ class Application_Model_BootMenu protected $_membershipID; protected $_groupID; protected $_title; + protected $_startcounter; protected $_created; protected $_defaultbootmenu; @@ -96,6 +97,15 @@ class Application_Model_BootMenu { return $this->_created; } + public function setStartcounter($_startcounter) + { + $this->_startcounter = $_startcounter; + return $this; + } + public function getStartcounter() + { + return $this->_startcounter; + } public function setCreated($_created) { $this->_created = $_created; diff --git a/application/models/BootMenuMapper.php b/application/models/BootMenuMapper.php index 8b39a5a..6ba72bd 100644 --- a/application/models/BootMenuMapper.php +++ b/application/models/BootMenuMapper.php @@ -84,7 +84,13 @@ class Application_Model_BootMenuMapper public function save(Application_Model_BootMenu $botmenu) { - $data = array('bootmenuID'=> $botmenu->getID() ,'membershipID'=> $botmenu->getMembershipID(), 'groupID'=> $botmenu->getGroupID() ,'title'=> $botmenu->getTitle() ,'created'=> $botmenu->getCreated(), 'defaultbootmenu' => $botmenu->getDefaultbootmenu()); + $data = array('bootmenuID'=> $botmenu->getID() , + 'membershipID'=> $botmenu->getMembershipID(), + 'groupID'=> $botmenu->getGroupID() , + 'title'=> $botmenu->getTitle() , + 'startcounter'=> $botmenu->getStartcounter() , + 'created'=> $botmenu->getCreated(), + 'defaultbootmenu' => $botmenu->getDefaultbootmenu()); if (null === ($id = $botmenu->getID()) ) { unset($data['bootmenuID']); @@ -113,10 +119,22 @@ class Application_Model_BootMenuMapper if($botmenu == null){ $botmenu = new Application_Model_BootMenu(); - $botmenu->setID($row->bootmenuID)->setMembershipID($row->membershipID)->setGroupID($row->groupID)->setTitle($row->title)->setCreated($row->created)->setDefaultbootmenu($row->defaultbootmenu); + $botmenu->setID($row->bootmenuID) + ->setMembershipID($row->membershipID) + ->setGroupID($row->groupID) + ->setTitle($row->title) + ->setStartcounter($row->startcounter) + ->setCreated($row->created) + ->setDefaultbootmenu($row->defaultbootmenu); return $botmenu; }else{ - $botmenu->setID($row->bootmenuID)->setMembershipID($row->membershipID)->setGroupID($row->groupID)->setTitle($row->title)->setCreated($row->created)->setDefaultbootmenu($row->defaultbootmenu); + $botmenu->setID($row->bootmenuID) + ->setMembershipID($row->membershipID) + ->setGroupID($row->groupID) + ->setTitle($row->title) + ->setStartcounter($row->startcounter) + ->setCreated($row->created) + ->setDefaultbootmenu($row->defaultbootmenu); } @@ -129,7 +147,7 @@ class Application_Model_BootMenuMapper foreach ($resultSet as $row) { $entry = new Application_Model_BootMenu(); - $entry->setID($row->bootmenuID)->setMembershipID($row->membershipID)->setGroupID($row->groupID)->setTitle($row->title)->setCreated($row->created)->setDefault($row->default); + $entry->setID($row->bootmenuID)->setMembershipID($row->membershipID)->setGroupID($row->groupID)->setTitle($row->title)->setStartcounter($row->startcounter)->setCreated($row->created)->setDefault($row->default); $entries[] = $entry; } diff --git a/application/models/BootOsUser.php b/application/models/BootOsUser.php new file mode 100644 index 0000000..aefd311 --- /dev/null +++ b/application/models/BootOsUser.php @@ -0,0 +1,154 @@ +<?php +/* + * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg + * This program is free software distributed under the GPL version 2. + * See http://gpl.openslx.org/ + * + * If you have any feedback please consult http://feedback.openslx.org/ and + * send your suggestions, praise, or complaints to feedback@openslx.org + * + * General information about OpenSLX can be found at http://openslx.org/ + */ + +class Application_Model_BootOsUser +{ + protected $_bootosuserID; + protected $_configID; + protected $_login; + protected $_password; + protected $_homepath; + protected $_hometypeID; + + public function __construct(array $options = null) + { + if (is_array($options)) { + $this->setOptions($options); + } + } + + public function __set($name, $value) + { + $method = 'set' . $name; + if (('mapper' == $name) || !method_exists($this, $method)) { + throw new Exception('Invalid BootOsUser property'); + } + $this->$method($value); + } + + public function __get($name) + { + $method = 'get' . $name; + if (('mapper' == $name) || !method_exists($this, $method)) { + throw new Exception('Invalid BootOsUser property'); + } + return $this->$method(); + } + + public function setOptions(array $options) + { + $methods = get_class_methods($this); + foreach ($options as $key => $value) { + $method = 'set' . ucfirst($key); + if (in_array($method, $methods)) { + $this->$method($value); + } + } + return $this; + } + + public function getID() + { + return $this->_bootosuserID; + } + public function setID($_bootosuserID) + { + $this->_bootosuserID = $_bootosuserID; + return $this; + } + + public function getConfigID() + { + return $this->_configID; + } + + public function setConfigID($_configID) + { + $this->_configID = $_configID; + return $this; + } + + public function getLogin() + { + return $this->_login; + } + + public function setLogin($_login) + { + $this->_login = $_login; + return $this; + } + public function getPassword() + { + return $this->_password; + } + + public function setPassword($_password) + { + $this->_password = $_password; + return $this; + } + + public function getHomepath() + { + return $this->_homepath; + } + public function setHomepath($_homepath) + { + $this->_homepath = $_homepath; + return $this; + } + public function getHometypeID() + { + return $this->_hometypeID; + } + public function setHometypeID($_hometypeID) + { + $this->_hometypeID = $_hometypeID; + return $this; + } + /** + * Returns current data as associative array using ReflectionClass + * + * @return array Returns associative array containing model data + * If "get"-method not available (our primary keys) the function getID() is called + */ + public function toArray() + { + $reflectionClass = new ReflectionClass($this); + $properties = $reflectionClass->getProperties(); + $result = array(); + foreach ($properties as $property) { + $key = $property->name; + if (substr($key, 0, 1) != '_' && $this->$key !== null) { + $method = 'get' . ucfirst($key); + if ($reflectionClass->hasMethod($method)) { + $result[$key] = $this->$method(); + } else { + $result[$key] = $this->$key; + } + } + elseif(substr($key, 0, 1) == '_' && $this->$key !== null) { + $key = substr($key, 1); + $method = 'get' . ucfirst($key); + if ($reflectionClass->hasMethod($method)) { + $result[$key] = $this->$method(); + }else{ + $result[$key] = $this->getID(); + } + + } + } + return $result; + } +} + diff --git a/application/models/Client.php b/application/models/Client.php index a63e8ba..e8108ef 100644 --- a/application/models/Client.php +++ b/application/models/Client.php @@ -16,6 +16,7 @@ class Application_Model_Client protected $_groupID; protected $_macadress; protected $_hardwarehash; + protected $_created; public function __construct(array $options = null) { @@ -91,6 +92,15 @@ class Application_Model_Client $this->_hardwarehash = $_hardwarehash; return $this; } + public function getCreated() + { + return $this->_created; + } + public function setCreated($_created) + { + $this->_created = $_created; + return $this; + } /** * Returns current data as associative array using ReflectionClass * diff --git a/application/models/ClientMapper.php b/application/models/ClientMapper.php index d727352..bcb3286 100644 --- a/application/models/ClientMapper.php +++ b/application/models/ClientMapper.php @@ -87,7 +87,8 @@ class Application_Model_ClientMapper $data = array('clientID'=> $client->getID() , 'groupID' => $client->getGroupID(), 'macadress'=> $client->getMacadress() , - 'hardwarehash'=> $client->getHardwarehash() + 'hardwarehash'=> $client->getHardwarehash(), + 'created'=> $client->getCreated() ); if (null === ($id = $client->getID()) ) { @@ -116,7 +117,11 @@ class Application_Model_ClientMapper $row = $result->current(); - $client->setID($row->clientID)->setGroupID($row->groupID)->setMacadress($row->macadress)->setHardwarehash($row->hardwarehash); + $client->setID($row->clientID) + ->setGroupID($row->groupID) + ->setMacadress($row->macadress) + ->setHardwarehash($row->hardwarehash) + ->setCreated($row->created); } public function fetchAll() @@ -126,7 +131,11 @@ class Application_Model_ClientMapper foreach ($resultSet as $row) { $entry = new Application_Model_Client(); - $entry->setID($row->clientID)->setGroupID($row->groupID)->setMacadress($row->macadress)->setHardwarehash($row->hardwarehash); + $entry->setID($row->clientID) + ->setGroupID($row->groupID) + ->setMacadress($row->macadress) + ->setHardwarehash($row->hardwarehash) + ->setCreated($row->created); $entries[] = $entry; } diff --git a/application/models/DbTable/BootOsUser.php b/application/models/DbTable/BootOsUser.php new file mode 100644 index 0000000..976e21a --- /dev/null +++ b/application/models/DbTable/BootOsUser.php @@ -0,0 +1,20 @@ +<?php +/* + * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg + * This program is free software distributed under the GPL version 2. + * See http://gpl.openslx.org/ + * + * If you have any feedback please consult http://feedback.openslx.org/ and + * send your suggestions, praise, or complaints to feedback@openslx.org + * + * General information about OpenSLX can be found at http://openslx.org/ + */ + +class Application_Model_DbTable_BootOsUser extends Zend_Db_Table_Abstract +{ + + protected $_name = 'pbs_bootosuser'; + + +} + diff --git a/application/models/DbTable/HomeType.php b/application/models/DbTable/HomeType.php new file mode 100644 index 0000000..2bd484f --- /dev/null +++ b/application/models/DbTable/HomeType.php @@ -0,0 +1,20 @@ +<?php +/* + * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg + * This program is free software distributed under the GPL version 2. + * See http://gpl.openslx.org/ + * + * If you have any feedback please consult http://feedback.openslx.org/ and + * send your suggestions, praise, or complaints to feedback@openslx.org + * + * General information about OpenSLX can be found at http://openslx.org/ + */ + +class Application_Model_DbTable_HomeType extends Zend_Db_Table_Abstract +{ + + protected $_name = 'pbs_hometype'; + + +} + diff --git a/application/models/HomeType.php b/application/models/HomeType.php new file mode 100644 index 0000000..afdf6ca --- /dev/null +++ b/application/models/HomeType.php @@ -0,0 +1,111 @@ +<?php +/* + * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg + * This program is free software distributed under the GPL version 2. + * See http://gpl.openslx.org/ + * + * If you have any feedback please consult http://feedback.openslx.org/ and + * send your suggestions, praise, or complaints to feedback@openslx.org + * + * General information about OpenSLX can be found at http://openslx.org/ + */ + +class Application_Model_HomeType +{ + protected $_hometypeID; + protected $_name; + + public function __construct(array $options = null) + { + if (is_array($options)) { + $this->setOptions($options); + } + } + + public function __set($name, $value) + { + $method = 'set' . $name; + if (('mapper' == $name) || !method_exists($this, $method)) { + throw new Exception('Invalid HomeType property'); + } + $this->$method($value); + } + + public function __get($name) + { + $method = 'get' . $name; + if (('mapper' == $name) || !method_exists($this, $method)) { + throw new Exception('Invalid HomeType property'); + } + return $this->$method(); + } + + public function setOptions(array $options) + { + $methods = get_class_methods($this); + foreach ($options as $key => $value) { + $method = 'set' . ucfirst($key); + if (in_array($method, $methods)) { + $this->$method($value); + } + } + return $this; + } + + public function getID() + { + return $this->_hometypeID; + } + public function setID($_hometypeID) + { + $this->_hometypeID = $_hometypeID; + return $this; + } + + public function getName() + { + return $this->_name; + } + + public function setName($_name) + { + $this->_name = $_name; + return $this; + } + + /** + * Returns current data as associative array using ReflectionClass + * + * @return array Returns associative array containing model data + * If "get"-method not available (our primary keys) the function getID() is called + */ + public function toArray() + { + $reflectionClass = new ReflectionClass($this); + $properties = $reflectionClass->getProperties(); + $result = array(); + foreach ($properties as $property) { + $key = $property->name; + if (substr($key, 0, 1) != '_' && $this->$key !== null) { + $method = 'get' . ucfirst($key); + if ($reflectionClass->hasMethod($method)) { + $result[$key] = $this->$method(); + } else { + $result[$key] = $this->$key; + } + } + elseif(substr($key, 0, 1) == '_' && $this->$key !== null) { + $key = substr($key, 1); + $method = 'get' . ucfirst($key); + if ($reflectionClass->hasMethod($method)) { + $result[$key] = $this->$method(); + }else{ + $result[$key] = $this->getID(); + } + + } + } + return $result; + } +} + diff --git a/application/models/HomeTypeMapper.php b/application/models/HomeTypeMapper.php new file mode 100644 index 0000000..6bccceb --- /dev/null +++ b/application/models/HomeTypeMapper.php @@ -0,0 +1,142 @@ +<?php +/* + * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg + * This program is free software distributed under the GPL version 2. + * See http://gpl.openslx.org/ + * + * If you have any feedback please consult http://feedback.openslx.org/ and + * send your suggestions, praise, or complaints to feedback@openslx.org + * + * General information about OpenSLX can be found at http://openslx.org/ + */ + +class Application_Model_HomeTypeMapper +{ + + protected $_dbTable; + + public function findBy($where, $array=false, $order=false) + { + foreach($where as $k => $v){ + if($v != null) + $where2[] = "$k = '$v'"; + else + $where2[] = "$k IS NULL"; + } + $where = implode(" AND " ,$where2); + + try{ + $db = Zend_Db_Table::getDefaultAdapter(); + $select = $this->getDbTable()->select() + ->from($this->_dbTable) + ->where($where); + + if(is_array($order)){ + foreach ($order as $k => $v) + $a[] = "$k $v"; + $select->order($a); + } + + $stmt = $select->query(); + $result = $stmt->fetchAll(); + + if(!$array){ + $entries = array(); + foreach ($result as $row) { + $entry = new Application_Model_HomeType($row); + $entry->setID($row['hometypeID']); + $entries[] = $entry; + } + return $entries; + }else{ + return $result; + } + + }catch (Zend_Exception $e) { + echo "Error message 2: " . $e->getMessage() . "\n"; + } + } + 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_HomeType'); + } + + return $this->_dbTable; + } + + public function save(Application_Model_HomeType $hometype) + { + + $data = array('hometypeID'=> $hometype->getID() ,'name'=> $hometype->getName() ); + + if (null === ($id = $hometype->getID()) ) { + unset($data['hometypeID']); + $this->getDbTable()->insert($data); + } else { + $this->getDbTable()->update($data, array('hometypeID = ?' => $id)); + } + } + + public function delete(Application_Model_HomeType $hometype) + { + if (null === ($id = $hometype->getID()) ) { + return; + } else { + $this->getDbTable()->delete(array('hometypeID = ?' => $id)); + } + } + + public function find($id, Application_Model_HomeType $hometype) + { + $result = $this->getDbTable()->find($id); + if (0 == count($result)) { + return; + } + + $row = $result->current(); + + $hometype->setID($row->hometypeID) + ->setName($row->name); + } + + public function fetchAll() + { + $resultSet = $this->getDbTable()->fetchAll(); + $entries = array(); + foreach ($resultSet as $row) { + $entry = new Application_Model_HomeType(); + + $entry->setID($row->hometypeID) + ->setName($row->name); + + $entries[] = $entry; + } + return $entries; + } + + public function compare(Application_Model_HomeType $v1,Application_Model_HomeType $v2){ + $vv1 = $v1->toArray(); + $vv2 = $v2->toArray(); + return array_diff($vv1,$vv2); + } + + + +} + |