diff options
author | michael pereira | 2011-03-29 11:01:35 +0200 |
---|---|---|
committer | michael pereira | 2011-03-29 11:01:35 +0200 |
commit | ecb5c8d8c31ad70bb24e0ea1cfb6110bcd0a96bb (patch) | |
tree | 4b40a4178c2dc3bd3fe21730a29dd07bb8742790 /application/models | |
parent | Preboot User Controller fertig, ACL fehlt noch (diff) | |
parent | selectmembership von auth zu person verschoben fbgui module (diff) | |
download | pbs2-ecb5c8d8c31ad70bb24e0ea1cfb6110bcd0a96bb.tar.gz pbs2-ecb5c8d8c31ad70bb24e0ea1cfb6110bcd0a96bb.tar.xz pbs2-ecb5c8d8c31ad70bb24e0ea1cfb6110bcd0a96bb.zip |
zfconf
Diffstat (limited to 'application/models')
-rw-r--r-- | application/models/DbTable/RightCategory.php | 10 | ||||
-rw-r--r-- | application/models/Right.php | 60 | ||||
-rw-r--r-- | application/models/RightCategory.php | 94 | ||||
-rw-r--r-- | application/models/RightCategoryMapper.php | 103 | ||||
-rw-r--r-- | application/models/Role.php | 60 | ||||
-rw-r--r-- | application/models/RoleMapper.php | 6 |
6 files changed, 280 insertions, 53 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..1a3d093 --- /dev/null +++ b/application/models/RightCategoryMapper.php @@ -0,0 +1,103 @@ +<?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; + } + + public function compare(Application_Model_RightCategory $v1,Application_Model_RightCategory $v2){ + $vv1 = $v1->toArray(); + $vv2 = $v2->toArray(); + return array_diff($vv1,$vv2); + } + +} + diff --git a/application/models/Role.php b/application/models/Role.php index 28f0af1..49ed377 100644 --- a/application/models/Role.php +++ b/application/models/Role.php @@ -6,6 +6,7 @@ class Application_Model_Role protected $_groupID; protected $_title; protected $_description; + protected $_inheritance; public function __construct(array $options = null) { @@ -81,39 +82,48 @@ class Application_Model_Role $this->_description = $_description; return $this; } - /** - * Returns current data as associative array using ReflectionClass - * - * @return array Returns associative array containing model data + public function getInheritance() + { + return $this->_inheritance; + } + public function setInheritance($_inheritance) + { + $this->_inheritance = $_inheritance; + 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; - } - } + */ + 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/RoleMapper.php b/application/models/RoleMapper.php index 561a7d4..4001e3e 100644 --- a/application/models/RoleMapper.php +++ b/application/models/RoleMapper.php @@ -47,7 +47,7 @@ class Application_Model_RoleMapper public function save(Application_Model_Role $role) { - $data = array('roleID'=> $role->getID() ,'groupID'=> $role->getGroupID() ,'title'=> $role->getTitle() ,'description'=> $role->getDescription() ); + $data = array('roleID'=> $role->getID() ,'groupID'=> $role->getGroupID() ,'title'=> $role->getTitle() ,'description'=> $role->getDescription(), 'inheritance' => $role->getInheritance() ); if (null === ($id = $role->getID()) ) { unset($data['roleID']); @@ -75,7 +75,7 @@ class Application_Model_RoleMapper $row = $result->current(); $role = new Application_Model_Role(); - $role->setID($row->roleID)->setGroupID($row->groupID)->setTitle($row->title)->setDescription($row->description); + $role->setID($row->roleID)->setGroupID($row->groupID)->setTitle($row->title)->setDescription($row->description)->setInheritance($row->inheritance); return $role; } @@ -86,7 +86,7 @@ class Application_Model_RoleMapper foreach ($resultSet as $row) { $entry = new Application_Model_Role(); - $entry->setID($row->roleID)->setGroupID($row->groupID)->setTitle($row->title)->setDescription($row->description); + $entry->setID($row->roleID)->setGroupID($row->groupID)->setTitle($row->title)->setDescription($row->description)->setInheritance($row->inheritance); $entries[] = $entry; } |