summaryrefslogtreecommitdiffstats
path: root/application/models
diff options
context:
space:
mode:
authorBjörn Geiger2011-08-19 12:00:34 +0200
committerBjörn Geiger2011-08-19 12:00:34 +0200
commit216b0e0636bcc78759776a0a028cc8b113a9ebfb (patch)
tree8bd961b5f063470a1587226ca7868f3dd1e266f2 /application/models
parentverschiedene Korrekturen und Datenbankänderung (diff)
downloadpoolctrl-216b0e0636bcc78759776a0a028cc8b113a9ebfb.tar.gz
poolctrl-216b0e0636bcc78759776a0a028cc8b113a9ebfb.tar.xz
poolctrl-216b0e0636bcc78759776a0a028cc8b113a9ebfb.zip
Datenbankänderungen
Diffstat (limited to 'application/models')
-rw-r--r--application/models/Runningtype.php111
-rw-r--r--application/models/RunningtypeMapper.php87
2 files changed, 198 insertions, 0 deletions
diff --git a/application/models/Runningtype.php b/application/models/Runningtype.php
new file mode 100644
index 0000000..8a83a87
--- /dev/null
+++ b/application/models/Runningtype.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_Runningtype
+{
+ protected $_runningtypeID;
+ protected $_title;
+
+ 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 runningtype property');
+ }
+ $this->$method($value);
+ }
+
+ public function __get($name)
+ {
+ $method = 'get' . $name;
+ if (('mapper' == $name) || !method_exists($this, $method)) {
+ throw new Exception('Invalid runningtype 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;
+ }
+
+ /**
+ * 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;
+ }
+
+ public function getID()
+ {
+ return $this->_runningtypeID;
+ }
+ public function setID($_runningtypeID)
+ {
+ $this->reporttypeID = $_runningtypeID;
+ return $this;
+ }
+
+ public function getTitle()
+ {
+ return $this->_title;
+ }
+
+ public function setTitle($_title)
+ {
+ $this->_title = $_title;
+ return $this;
+ }
+}
+
diff --git a/application/models/RunningtypeMapper.php b/application/models/RunningtypeMapper.php
new file mode 100644
index 0000000..b73d943
--- /dev/null
+++ b/application/models/RunningtypeMapper.php
@@ -0,0 +1,87 @@
+<?php
+
+class Application_Model_RunningtypeMapper
+{
+
+ 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_Runningtype');
+ }
+
+ return $this->_dbTable;
+ }
+
+ public function save(Application_Model_Runningtype $runningtype)
+ {
+
+ $data = array('runningtypeID'=> $runningtype->getRunningtypeID() ,'title'=> $runningtype->getTitle() );
+
+ if (null === ($id = $runningtype->getID()) ) {
+ unset($data['runningtypeID']);
+ $this->getDbTable()->insert($data);
+ } else {
+ $this->getDbTable()->update($data, array('runningtypeID = ?' => $id));
+ }
+ }
+
+ public function delete(Application_Model_Runningtype $runningtype)
+ {
+ if (null === ($id = $runningtype->getID()) ) {
+ return;
+ } else {
+ $this->getDbTable()->delete(array('runningtypeID = ?' => $id));
+ }
+ }
+
+ public function find($id, Application_Model_Runningtype $runningtype)
+ {
+ $result = $this->getDbTable()->find($id);
+ if (0 == count($result)) {
+ return;
+ }
+
+ $row = $result->current();
+
+ $runningtype
+ ->setRunningtypeID($row->runningtypeID)
+ ->setTitle($row->title);
+ }
+
+ public function fetchAll()
+ {
+ $resultSet = $this->getDbTable()->fetchAll();
+ $entries = array();
+ foreach ($resultSet as $row) {
+ $entry = new Application_Model_Runningtype();
+
+ $entry
+ ->setRunningtypeID($row->runningtypeID)
+ ->setTitle($row->title);
+
+ $entries[] = $entry;
+ }
+ return $entries;
+ }
+
+
+
+}
+