summaryrefslogtreecommitdiffstats
path: root/application/models
diff options
context:
space:
mode:
authorSimon2011-04-20 17:29:21 +0200
committerSimon2011-04-20 17:29:21 +0200
commit50dcd70ac9ab6b5b67edcf76bb9dd368d814d7ae (patch)
tree7d92c725988438abacd49b035d71ead85f167f1e /application/models
parentSchreibfehler im Installer-Script (diff)
downloadpbs2-50dcd70ac9ab6b5b67edcf76bb9dd368d814d7ae.tar.gz
pbs2-50dcd70ac9ab6b5b67edcf76bb9dd368d814d7ae.tar.xz
pbs2-50dcd70ac9ab6b5b67edcf76bb9dd368d814d7ae.zip
BootOsUser und HomeType Models hinzugefügt
Diffstat (limited to 'application/models')
-rw-r--r--application/models/BootOsUser.php154
-rw-r--r--application/models/DbTable/BootOsUser.php20
-rw-r--r--application/models/DbTable/HomeType.php20
-rw-r--r--application/models/HomeType.php111
-rw-r--r--application/models/HomeTypeMapper.php142
5 files changed, 447 insertions, 0 deletions
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/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);
+ }
+
+
+
+}
+