summaryrefslogtreecommitdiffstats
path: root/application
diff options
context:
space:
mode:
Diffstat (limited to 'application')
-rw-r--r--application/models/DbTable/RightCategory.php10
-rw-r--r--application/models/Right.php60
-rw-r--r--application/models/RightCategory.php94
-rw-r--r--application/models/RightCategoryMapper.php99
4 files changed, 238 insertions, 25 deletions
diff --git a/application/models/DbTable/RightCategory.php b/application/models/DbTable/RightCategory.php
new file mode 100644
index 0000000..65150ba
--- /dev/null
+++ b/application/models/DbTable/RightCategory.php
@@ -0,0 +1,10 @@
+<?php
+
+class Application_Model_DbTable_RightCategory extends Zend_Db_Table_Abstract
+{
+
+ protected $_name = 'pbs_rightcategory';
+
+
+}
+
diff --git a/application/models/Right.php b/application/models/Right.php
index c0df29c..874453c 100644
--- a/application/models/Right.php
+++ b/application/models/Right.php
@@ -3,6 +3,7 @@
class Application_Model_Right
{
protected $_rightID;
+ protected $_rightcategoryID;
protected $_title;
protected $_description;
@@ -53,6 +54,15 @@ class Application_Model_Right
$this->_rightID = $_rightID;
return $this;
}
+ public function getRightcategoryID()
+ {
+ return $this->_rightcategoryID;
+ }
+ public function setRightcategoryID($_rightcategoryID)
+ {
+ $this->_rightID = $_rightcategoryID;
+ return $this;
+ }
public function getTitle()
{
return $this->_title;
@@ -71,39 +81,39 @@ class Application_Model_Right
$this->_description = $_description;
return $this;
}
- /**
- * Returns current data as associative array using ReflectionClass
- *
- * @return array Returns associative array containing model data
+ /**
+ * 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;
- }
- }
+ */
+ 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);
+ $method = 'get' . ucfirst($key);
if ($reflectionClass->hasMethod($method)) {
$result[$key] = $this->$method();
}else{
$result[$key] = $this->getID();
}
-
+
}
- }
- return $result;
- }
+ }
+ return $result;
+ }
}
diff --git a/application/models/RightCategory.php b/application/models/RightCategory.php
new file mode 100644
index 0000000..42bcbb8
--- /dev/null
+++ b/application/models/RightCategory.php
@@ -0,0 +1,94 @@
+<?php
+
+class Application_Model_RightCategory
+{
+ protected $_rightcategoryID;
+ 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 rightcategory property');
+ }
+ $this->$method($value);
+ }
+
+ public function __get($name)
+ {
+ $method = 'get' . $name;
+ if (('mapper' == $name) || !method_exists($this, $method)) {
+ throw new Exception('Invalid rightcategory 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->_rightcategoryID;
+ }
+ public function setID($_rightcategoryID)
+ {
+ $this->_rightID = $_rightcategoryID;
+ return $this;
+ }
+ public function getTitle()
+ {
+ return $this->_title;
+ }
+ public function setTitle($_title)
+ {
+ $this->_title = $_title;
+ return $this;
+ }
+
+ 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/RightCategoryMapper.php b/application/models/RightCategoryMapper.php
new file mode 100644
index 0000000..e0e324d
--- /dev/null
+++ b/application/models/RightCategoryMapper.php
@@ -0,0 +1,99 @@
+<?php
+
+class Application_Model_RightCategoryMapper
+{
+
+ protected $_dbTable;
+
+ public function findBy($criteria, $value)
+ {
+ try{
+ $db = Zend_Db_Table::getDefaultAdapter();
+ $select = $this->getDbTable()->select()
+ ->from($this->_dbTable)
+ ->where($criteria . ' = ?', $value);
+ $stmt = $select->query();
+ $result = $stmt->fetchAll();
+ 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_RightCategory');
+ }
+
+ return $this->_dbTable;
+ }
+
+ public function save(Application_Model_RightCategory $rightCategory)
+ {
+
+ $data = array('rightcategoryID'=> $rightCategory->getID() ,'title'=> $rightCategory->getTitle() );
+
+ if (null === ($id = $rightCategory->getID()) ) {
+ unset($data['rightcategoryID']);
+ $this->getDbTable()->insert($data);
+ } else {
+ $this->getDbTable()->update($data, array('rightcategoryID = ?' => $id));
+ }
+ }
+
+ public function delete(Application_Model_RightCategory $rightCategory)
+ {
+ if (null === ($id = $rightCategory->getID()) ) {
+ return;
+ } else {
+ $this->getDbTable()->delete(array('rightcategoryID = ?' => $id));
+ }
+ }
+
+ public function find($id)
+ {
+ $result = $this->getDbTable()->find($id);
+ if (0 == count($result)) {
+ return;
+ }
+
+ $row = $result->current();
+
+ $rightCategory = new Application_Model_RightCategory();
+ $rightCategory->setID($row->rightcategoryID)->setTitle($row->title);
+ return $rightCategory;
+ }
+
+ public function fetchAll()
+ {
+ $resultSet = $this->getDbTable()->fetchAll();
+ $entries = array();
+ foreach ($resultSet as $row) {
+ $entry = new Application_Model_RightCategory();
+
+ $entry->setID($row->rightcategoryID)->setTitle($row->title);
+ $entries[] = $entry;
+ }
+ return $entries;
+ }
+
+
+
+}
+