summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--application/models/DbTable/Eventcategory.php20
-rw-r--r--application/models/Eventcategory.php111
-rw-r--r--application/models/EventcategoryMapper.php147
-rw-r--r--application/models/EventreportMapper.php3
-rw-r--r--setup/poolctrl.sql14
-rw-r--r--setup/poolctrl_data.sql13
6 files changed, 299 insertions, 9 deletions
diff --git a/application/models/DbTable/Eventcategory.php b/application/models/DbTable/Eventcategory.php
new file mode 100644
index 0000000..3423a0d
--- /dev/null
+++ b/application/models/DbTable/Eventcategory.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_Eventcategory extends Zend_Db_Table_Abstract
+{
+
+ protected $_name = 'poolctrl_eventcategory';
+
+
+}
+
diff --git a/application/models/Eventcategory.php b/application/models/Eventcategory.php
new file mode 100644
index 0000000..cbb5916
--- /dev/null
+++ b/application/models/Eventcategory.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_Eventcategory
+{
+ protected $_eventcategory;
+ 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 eventcategory property');
+ }
+ $this->$method($value);
+ }
+
+ public function __get($name)
+ {
+ $method = 'get' . $name;
+ if (('mapper' == $name) || !method_exists($this, $method)) {
+ throw new Exception('Invalid eventcategory 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->_eventcategoryID;
+ }
+ public function setID($_eventcategoryID)
+ {
+ $this->_eventcategoryID = $_eventcategoryID;
+ return $this;
+ }
+
+ public function getTitle()
+ {
+ return $this->_title;
+ }
+
+ public function setTitle($_title)
+ {
+ $this->_title = $_title;
+ return $this;
+ }
+}
+
diff --git a/application/models/EventcategoryMapper.php b/application/models/EventcategoryMapper.php
new file mode 100644
index 0000000..f0b7ff6
--- /dev/null
+++ b/application/models/EventcategoryMapper.php
@@ -0,0 +1,147 @@
+<?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_EventcategoryMapper
+{
+
+ 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_Eventcategory($row);
+ $entry->setID($row['eventcategoryID']);
+ $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_Eventcategory');
+ }
+
+ return $this->_dbTable;
+ }
+
+ public function save(Application_Model_Eventcategory $eventcategory)
+ {
+ $data = array('eventcategoryID'=> $eventcategory->getID() ,'title'=> $eventcategory->getTitle() );
+ if (null === ($id = $eventcategory->getID()) ) {
+ unset($data['eventcategoryID']);
+ return $this->getDbTable(F)->insert($data);
+ } else {
+ $this->getDbTable()->update($data, array('eventcategoryID = ?' => $id));
+ }
+ }
+
+ public function delete(Application_Model_Eventcategory $eventcategory)
+ {
+ if (null === ($id = $eventcategory->getID()) ) {
+ return;
+ } else {
+ $this->getDbTable()->delete(array('eventcategoryID = ?' => $id));
+ }
+ }
+
+ public function find($id, Application_Model_Eventcategory $eventcategory = null)
+ {
+ $result = $this->getDbTable()->find($id);
+ if (0 == count($result)) {
+ return;
+ }
+
+ $row = $result->current();
+
+ if($eventcategory == null){
+ $eventcategory = new Application_Model_Eventcategory();
+ }
+
+ $eventcategory
+ ->setID($row->eventcategoryID)
+ ->setTitle($row->title);
+ }
+
+ public function fetchAll()
+ {
+ $resultSet = $this->getDbTable()->fetchAll();
+ $entries = array();
+ foreach ($resultSet as $row) {
+ $entry = new Application_Model_Eventcategory();
+
+ $entry
+ ->setID($row->eventcategoryID)
+ ->setTitle($row->title);
+
+ $entries[$row->eventcategoryID] = $entry;
+ }
+ return $entries;
+ }
+
+ public function compare(Application_Model_Eventcategory $v1,Application_Model_Eventcategory $v2){
+ $vv1 = $v1->toArray();
+ $vv2 = $v2->toArray();
+ return array_diff($vv1,$vv2);
+ }
+
+
+
+}
+
diff --git a/application/models/EventreportMapper.php b/application/models/EventreportMapper.php
index 41b31e8..9da6487 100644
--- a/application/models/EventreportMapper.php
+++ b/application/models/EventreportMapper.php
@@ -12,7 +12,6 @@
class Application_Model_EventreportMapper
{
-
protected $_dbTable;
public function findBy($where, $array=false, $order=false)
@@ -43,7 +42,7 @@ class Application_Model_EventreportMapper
if(!$array){
$entries = array();
foreach ($result as $row) {
- $entry = new Application_Model_Eventreportreport($row);
+ $entry = new Application_Model_Eventreport($row);
$entry->setID($row['reportID']);
$entries[] = $entry;
}
diff --git a/setup/poolctrl.sql b/setup/poolctrl.sql
index c861bdf..9be8e3e 100644
--- a/setup/poolctrl.sql
+++ b/setup/poolctrl.sql
@@ -10,7 +10,7 @@ CREATE TABLE IF NOT EXISTS `poolctrl_event` (
`start` timestamp COLLATE utf8_unicode_ci NOT NULL DEFAULT CURRENT_TIMESTAMP(),
`end` timestamp COLLATE utf8_unicode_ci NOT NULL,
`participants` int(4) NOT NULL DEFAULT 50 CHECK (participants > 0),
- `category` varchar(30) COLLATE utf8_unicode_ci,
+ `category` int(11) NOT NULL,
`pbs_poolID` int(11) NOT NULL,
`pbs_membershipID` int(11) NOT NULL,
`pbs_bootosID` int(11) NOT NULL,
@@ -25,9 +25,14 @@ CREATE TABLE IF NOT EXISTS `poolctrl_eventreport` (
`report` varchar(140) COLLATE utf8_unicode_ci DEFAULT 'success',
`eventID` int(11) NOT NULL,
`timestamp` timestamp COLLATE utf8_unicode_ci NOT NULL DEFAULT CURRENT_TIMESTAMP(),
- PRIMARY KEY (`reportID`),
- FOREIGN KEY (`eventID`) references poolctrl_event(eventID)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=5;
+ PRIMARY KEY (`reportID`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;
+
+CREATE TABLE IF NOT EXISTS `poolctrl_eventcategory` (
+ `eventcategoryID` int(11) NOT NULL AUTO_INCREMENT,
+ `title` varchar(30) COLLATE utf8_unicode_ci NOT NULL UNIQUE,
+ PRIMARY KEY (`eventcategoryID`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;
-- PBS2 Tabellen
@@ -174,5 +179,6 @@ ALTER TABLE `poolctrl_event`
ADD CONSTRAINT `poolctrl_event_poolidC` FOREIGN KEY (`pbs_poolID`) REFERENCES `pbs_pool` (`poolID`) ON DELETE CASCADE,
ADD CONSTRAINT `poolctrl_event_membershipC` FOREIGN KEY (`pbs_membershipID`) REFERENCES `pbs_membership` (`membershipID`) ON DELETE CASCADE,
ADD CONSTRAINT `poolctrl_event_boolisoidC` FOREIGN KEY (`pbs_bootosID`) REFERENCES `pbs_bootos` (`bootosID`) ON DELETE CASCADE,
+ ADD CONSTRAINT `poolctrl_event_categoryC` FOREIGN KEY (`category`) REFERENCES `poolctrl_eventcategory` (`eventcategoryID`) ON DELETE CASCADE,
ADD CONSTRAINT `poolctrl_event_startC` CHECK (start > CURRENT_TIMESTAMP()),
ADD CONSTRAINT `poolctrl_event_endC` CHECK (end > start);
diff --git a/setup/poolctrl_data.sql b/setup/poolctrl_data.sql
index 9967aee..dd08c97 100644
--- a/setup/poolctrl_data.sql
+++ b/setup/poolctrl_data.sql
@@ -99,11 +99,18 @@ INSERT INTO `pbs_poolentries` (`poolentriesID`, `poolID`, `clientID`) VALUES
(9, 4, 9),
(10, 4, 10);
+-- Adding eventcategories
+INSERT INTO `poolctrl_eventcategory` (`eventcategoryID`, `title`) VALUES
+(1, 'Lecture'),
+(2, 'Private'),
+(3, 'Public'),
+(4, 'Maintenance');
+
-- Adding events
INSERT INTO `poolctrl_event` (`eventID`, `title`, `start`, `end`, `category`, `pbs_poolID`, `pbs_membershipID`, `pbs_bootosID`, `note`) VALUES
-(1, 'Systeme I', '2011-06-24 12:10:00', '2011-06-24 14:00:00', 'Vorlesung', 1, 1, 1, 'Systeme I Vorlesung'),
-(2, 'Systeme II', '2011-06-24 14:10:00', '2011-06-24 16:00:00', 'Vorlesung', 1, 1, 1, 'Systeme II Vorlesung'),
-(3, 'Systeme III', '2011-06-24 16:10:00', '2011-06-24 18:00:00', 'Vorlesung', 1, 1, 1, 'Systeme III Vorlesung');
+(1, 'Systeme I', '2011-06-24 12:10:00', '2011-06-24 14:00:00', '1', 1, 1, 1, 'Systeme I Vorlesung'),
+(2, 'Systeme II', '2011-06-24 14:10:00', '2011-06-24 16:00:00', '1', 1, 1, 1, 'Systeme II Vorlesung'),
+(3, 'Systeme III', '2011-06-24 16:10:00', '2011-06-24 18:00:00', '1', 1, 1, 1, 'Systeme III Vorlesung');
-- Adding eventreport
INSERT INTO `poolctrl_eventreport` (`reportID`, `report`, `eventID`) VALUES