diff options
Diffstat (limited to 'application/models')
-rw-r--r-- | application/models/BootIso.php | 16 | ||||
-rw-r--r-- | application/models/BootIsoMapper.php | 8 | ||||
-rw-r--r-- | application/models/DbTable/PreBootType.php | 19 | ||||
-rw-r--r-- | application/models/PreBoot.php | 17 | ||||
-rw-r--r-- | application/models/PreBootMapper.php | 8 | ||||
-rw-r--r-- | application/models/PreBootType.php | 101 | ||||
-rw-r--r-- | application/models/PreBootTypeMapper.php | 140 |
7 files changed, 293 insertions, 16 deletions
diff --git a/application/models/BootIso.php b/application/models/BootIso.php index 8041fa2..e1c9bd8 100644 --- a/application/models/BootIso.php +++ b/application/models/BootIso.php @@ -14,9 +14,9 @@ class Application_Model_BootIso { protected $_bootisoID; protected $_title; protected $_description; - protected $_prebootID; protected $_membershipID; protected $_groupID; + protected $_typeID; protected $_serialnumber; protected $_created; protected $_expires; @@ -87,22 +87,22 @@ class Application_Model_BootIso { $this->_title = $_title; return $this; } - public function getPrebootID() { - return $this->_prebootID; + + public function getTypeID() { + return $this->_typeID; } - public function setPrebootID($_prebootID) { - $this->_prebootID = $_prebootID; - return $this; + public function setTypeID($_typeID) { + $this->_typeID = $_typeID; + return $this; } + public function getSerialnumber() { return $this->_serialnumber; } - public function setSerialnumber($_serialnumber) { $this->_serialnumber = $_serialnumber; return $this; } - public function getCreated() { return $this->_created; } diff --git a/application/models/BootIsoMapper.php b/application/models/BootIsoMapper.php index 35a66d0..dbe1685 100644 --- a/application/models/BootIsoMapper.php +++ b/application/models/BootIsoMapper.php @@ -77,7 +77,7 @@ class Application_Model_BootIsoMapper { public function save(Application_Model_BootIso $botiso) { - $data = array('bootisoID' => $botiso->getID() , 'membershipID' => $botiso->getMembershipID() , 'title' => $botiso->getTitle(), 'prebootID' => $botiso->getPrebootID() , 'groupID' => $botiso->getGroupID() , 'serialnumber' => $botiso->getSerialnumber() , 'created' => $botiso->getCreated() , 'expires' => $botiso->getExpires() , 'public' => $botiso->getPublic(), 'description' => $botiso->getDescription() ); + $data = array('bootisoID' => $botiso->getID() , 'membershipID' => $botiso->getMembershipID() , 'title' => $botiso->getTitle() , 'groupID' => $botiso->getGroupID() , 'typeID' => $botiso->getTypeID(), 'serialnumber' => $botiso->getSerialnumber() , 'created' => $botiso->getCreated() , 'expires' => $botiso->getExpires() , 'public' => $botiso->getPublic(), 'description' => $botiso->getDescription() ); if (null === ($id = $botiso->getID()) ) { unset($data['bootisoID']); @@ -105,10 +105,10 @@ class Application_Model_BootIsoMapper { if($botiso == null) { $botiso = new Application_Model_BootIso(); - $botiso->setID($row->bootisoID)->setMembershipID($row->membershipID)->setTitle($row->title)->setPrebootID($row->prebootID)->setGroupID($row->groupID)->setSerialnumber($row->serialnumber)->setCreated($row->created)->setExpires($row->expires)->setPublic($row->public)->setDescription($row->description); + $botiso->setID($row->bootisoID)->setMembershipID($row->membershipID)->setTitle($row->title)->setGroupID($row->groupID)->setTypeID($row->typeID)->setSerialnumber($row->serialnumber)->setCreated($row->created)->setExpires($row->expires)->setPublic($row->public)->setDescription($row->description); return $botiso; } else { - $botiso->setID($row->bootisoID)->setMembershipID($row->membershipID)->setTitle($row->title)->setPrebootID($row->prebootID)->setGroupID($row->groupID)->setSerialnumber($row->serialnumber)->setCreated($row->created)->setExpires($row->expires)->setPublic($row->public)->setDescription($row->description); + $botiso->setID($row->bootisoID)->setMembershipID($row->membershipID)->setTitle($row->title)->setGroupID($row->groupID)->setTypeID($row->typeID)->setSerialnumber($row->serialnumber)->setCreated($row->created)->setExpires($row->expires)->setPublic($row->public)->setDescription($row->description); } } @@ -118,7 +118,7 @@ class Application_Model_BootIsoMapper { foreach ($resultSet as $row) { $entry = new Application_Model_BootIso(); - $entry->setID($row->bootisoID)->setMembershipID($row->membershipID)->setTitle($row->title)->setPrebootID($row->prebootID)->setGroupID($row->groupID)->setSerialnumber($row->serialnumber)->setCreated($row->created)->setExpires($row->expires)->setPublic($row->public)->setDescription($row->description); + $entry->setID($row->bootisoID)->setMembershipID($row->membershipID)->setTitle($row->title)->setGroupID($row->groupID)->setTypeID($row->typeID)->setSerialnumber($row->serialnumber)->setCreated($row->created)->setExpires($row->expires)->setPublic($row->public)->setDescription($row->description); $entries[] = $entry; } diff --git a/application/models/DbTable/PreBootType.php b/application/models/DbTable/PreBootType.php new file mode 100644 index 0000000..f4157a3 --- /dev/null +++ b/application/models/DbTable/PreBootType.php @@ -0,0 +1,19 @@ +<?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_PreBootType extends Zend_Db_Table_Abstract { + + protected $_name = 'pbs_preboottype'; + + +} + diff --git a/application/models/PreBoot.php b/application/models/PreBoot.php index 8381c84..61cdf93 100644 --- a/application/models/PreBoot.php +++ b/application/models/PreBoot.php @@ -15,6 +15,8 @@ class Application_Model_PreBoot { protected $_title; protected $_membershipID; protected $_groupID; + protected $_typeID; + protected $_serialnumber; protected $_source; protected $_created; protected $_description; @@ -79,6 +81,21 @@ class Application_Model_PreBoot { $this->_groupID = $_groupID; return $this; } + public function getTypeID() { + return $this->_typeID; + } + + public function setTypeID($_typeID) { + $this->_typeID = $_typeID; + return $this; + } + public function getSerialnumber() { + return $this->_serialnumber; + } + public function setSerialnumber($_serialnumber) { + $this->_serialnumber = $_serialnumber; + return $this; + } public function getTitle() { return $this->_title; } diff --git a/application/models/PreBootMapper.php b/application/models/PreBootMapper.php index 4a9b039..f0bba2a 100644 --- a/application/models/PreBootMapper.php +++ b/application/models/PreBootMapper.php @@ -81,7 +81,7 @@ class Application_Model_PreBootMapper { public function save(Application_Model_PreBoot $preboot) { - $data = array('prebootID' => $preboot->getID() , 'membershipID' => $preboot->getMembershipID() , 'title' => $preboot->getTitle() , 'groupID' => $preboot->getGroupID(), 'created' => $preboot->getCreated(), 'source' => $preboot->getSource(), 'description' => $preboot->getDescription()); + $data = array('prebootID' => $preboot->getID() , 'membershipID' => $preboot->getMembershipID() , 'title' => $preboot->getTitle() , 'groupID' => $preboot->getGroupID(), 'typeID' => $preboot->getTypeID(), 'serialnumber' => $preboot->getSerialnumber(), 'created' => $preboot->getCreated(), 'source' => $preboot->getSource(), 'description' => $preboot->getDescription()); if (null === ($id = $preboot->getID()) ) { unset($data['prebootID']); @@ -110,10 +110,10 @@ class Application_Model_PreBootMapper { if($preboot == null) { $preboot = new Application_Model_PreBoot(); - $preboot->setID($row->prebootID)->setMembershipID($row->membershipID)->setTitle($row->title)->setGroupID($row->groupID)->setSource($row->source)->setCreated($row->created)->setDescription($row->description); + $preboot->setID($row->prebootID)->setMembershipID($row->membershipID)->setTitle($row->title)->setGroupID($row->groupID)->setTypeID($row->typeID)->setSerialnumber($row->serialnumber)->setSource($row->source)->setCreated($row->created)->setDescription($row->description); return $preboot; } else { - $preboot->setID($row->prebootID)->setMembershipID($row->membershipID)->setTitle($row->title)->setGroupID($row->groupID)->setSource($row->source)->setCreated($row->created)->setDescription($row->description); + $preboot->setID($row->prebootID)->setMembershipID($row->membershipID)->setTitle($row->title)->setGroupID($row->groupID)->setTypeID($row->typeID)->setSerialnumber($row->serialnumber)->setSource($row->source)->setCreated($row->created)->setDescription($row->description); } } @@ -123,7 +123,7 @@ class Application_Model_PreBootMapper { foreach ($resultSet as $row) { $entry = new Application_Model_PreBoot(); - $entry->setID($row->prebootID)->setMembershipID($row->membershipID)->setTitle($row->title)->setGroupID($row->groupID)->setSource($row->source)->setCreated($row->created)->setDescription($row->description); + $entry->setID($row->prebootID)->setMembershipID($row->membershipID)->setTitle($row->title)->setGroupID($row->groupID)->setTypeID($row->typeID)->setSerialnumber($row->serialnumber)->setSource($row->source)->setCreated($row->created)->setDescription($row->description); $entries[] = $entry; } diff --git a/application/models/PreBootType.php b/application/models/PreBootType.php new file mode 100644 index 0000000..3d376d1 --- /dev/null +++ b/application/models/PreBootType.php @@ -0,0 +1,101 @@ +<?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_PreBootType { + protected $_preboottypeID; + 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 PreBootType property'); + } + $this->$method($value); + } + + public function __get($name) { + $method = 'get' . $name; + if (('mapper' == $name) || !method_exists($this, $method)) { + throw new Exception('Invalid PreBootType 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->_preboottypeID; + } + public function setID($_preboottypeID) { + $this->_preboottypeID = $_preboottypeID; + 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/PreBootTypeMapper.php b/application/models/PreBootTypeMapper.php new file mode 100644 index 0000000..03bed3b --- /dev/null +++ b/application/models/PreBootTypeMapper.php @@ -0,0 +1,140 @@ +<?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_PreBootTypeMapper { + + 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_PreBootType($row); + $entry->setID($row['preboottypeID']); + $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_PreBootType'); + } + + return $this->_dbTable; + } + + public function save(Application_Model_PreBootType $preboottype) { + + $data = array('preboottypeID' => $preboottype->getID() , 'name' => $preboottype->getName() ); + + if (null === ($id = $preboottype->getID()) ) { + unset($data['preboottypeID']); + $this->getDbTable()->insert($data); + } else { + $this->getDbTable()->update($data, array('preboottypeID = ?' => $id)); + } + } + + public function delete(Application_Model_PreBootType $preboottype) { + if (null === ($id = $preboottype->getID()) ) { + return; + } else { + $this->getDbTable()->delete(array('preboottypeID = ?' => $id)); + } + } + + public function find($id, Application_Model_PreBootType $preboottype = null) { + $result = $this->getDbTable()->find($id); + if (0 == count($result)) { + return; + } + + $row = $result->current(); + + if($preboottype == null) { + $preboottype = new Application_Model_PreBootType(); + $preboottype->setID($row->preboottypeID)->setName($row->name); + return $preboottype; + } else { + $preboottype->setID($row->preboottypeID)->setName($row->name); + } + + } + + public function fetchAll() { + $resultSet = $this->getDbTable()->fetchAll(); + $entries = array(); + foreach ($resultSet as $row) { + $entry = new Application_Model_PreBootType(); + + $entry->setID($row->preboottypeID) + ->setName($row->name); + + $entries[] = $entry; + } + return $entries; + } + + public function compare(Application_Model_PreBootType $v1, Application_Model_PreBootType $v2) { + $vv1 = $v1->toArray(); + $vv2 = $v2->toArray(); + return array_diff($vv1, $vv2); + } + + + +} + |