summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjörn Geiger2011-08-19 00:45:34 +0200
committerBjörn Geiger2011-08-19 00:45:34 +0200
commit74d2e51da636f8ec981a0b004efb7e1f04b08e08 (patch)
treec62968896bfc4fb4cb6715b17894c58bdfba9418
parentmore ps-logic (diff)
downloadpoolctrl-74d2e51da636f8ec981a0b004efb7e1f04b08e08.tar.gz
poolctrl-74d2e51da636f8ec981a0b004efb7e1f04b08e08.tar.xz
poolctrl-74d2e51da636f8ec981a0b004efb7e1f04b08e08.zip
verschiedene Datenbankänderungen
-rw-r--r--application/models/DbTable/Reporttype.php20
-rw-r--r--application/models/Event.php12
-rw-r--r--application/models/EventMapper.php8
-rw-r--r--application/models/Eventreport.php12
-rw-r--r--application/models/EventreportMapper.php10
-rw-r--r--application/models/Reporttype.php111
-rw-r--r--application/models/ReporttypeMapper.php148
-rw-r--r--setup/poolctrl.sql23
-rw-r--r--setup/poolctrl_data.sql13
9 files changed, 339 insertions, 18 deletions
diff --git a/application/models/DbTable/Reporttype.php b/application/models/DbTable/Reporttype.php
new file mode 100644
index 0000000..fe62330
--- /dev/null
+++ b/application/models/DbTable/Reporttype.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_Reporttype extends Zend_Db_Table_Abstract
+{
+
+ protected $_name = 'poolctrl_reporttype';
+
+
+}
+
diff --git a/application/models/Event.php b/application/models/Event.php
index b69412e..33a470e 100644
--- a/application/models/Event.php
+++ b/application/models/Event.php
@@ -26,6 +26,7 @@ class Application_Model_Event
protected $_pbs_filterID;
protected $_repeat;
protected $_immediate;
+ protected $_running;
protected $_note;
public function __construct(array $options = null)
@@ -264,5 +265,16 @@ class Application_Model_Event
$this->_pbs_filterID = $_pbs_filterID;
return $this;
}
+
+ public function getRunning()
+ {
+ return $this->_running;
+ }
+
+ public function setRunning($_running)
+ {
+ $this->_running = $_running;
+ return $this;
+ }
}
diff --git a/application/models/EventMapper.php b/application/models/EventMapper.php
index 394fea2..a2648a0 100644
--- a/application/models/EventMapper.php
+++ b/application/models/EventMapper.php
@@ -85,7 +85,7 @@ class Application_Model_EventMapper
public function save(Application_Model_Event $event)
{
- $data = array('eventID'=> $event->getID() ,'category'=> $event->getCategory() ,'title'=> $event->getTitle(), 'pbs_membershipID'=> $event->getPbs_membershipID(),'end'=> $event->getEnd() ,'immediate'=> $event->getImmediate() ,'note'=> $event->getNote() ,'participants'=> $event->getParticipants() ,'pbs_bootosID'=> $event->getPbs_bootosID(),'pbs_poolID'=> $event->getPbs_poolID(),'repeat'=> $event->getRepeat(),'start'=> $event->getStart(),'pbs_bootmenuID'=> $event->getPbs_bootmenuID(),'pbs_filterID'=> $event->getPbs_filterID() );
+ $data = array('eventID'=> $event->getID() ,'category'=> $event->getCategory() ,'title'=> $event->getTitle(), 'pbs_membershipID'=> $event->getPbs_membershipID(),'end'=> $event->getEnd() ,'immediate'=> $event->getImmediate() ,'note'=> $event->getNote() ,'participants'=> $event->getParticipants() ,'pbs_bootosID'=> $event->getPbs_bootosID(),'pbs_poolID'=> $event->getPbs_poolID(),'repeat'=> $event->getRepeat(),'start'=> $event->getStart(),'pbs_bootmenuID'=> $event->getPbs_bootmenuID(),'pbs_filterID'=> $event->getPbs_filterID(), 'running' => $event->getRunning() );
if (null === ($id = $event->getID()) ) {
unset($data['eventID']);
return $this->getDbTable()->insert($data);
@@ -130,7 +130,8 @@ class Application_Model_EventMapper
->setPbs_filterID($row->pbs_filterID)
->setPbs_bootmenuID($row->pbs_bootmenuID)
->setRepeat($row->repeat)
- ->setStart($row->start);
+ ->setStart($row->start)
+ ->setRunning($row->running);
}
public function fetchAll()
@@ -155,7 +156,8 @@ class Application_Model_EventMapper
->setPbs_filterID($row->pbs_filterID)
->setPbs_bootmenuID($row->pbs_bootmenuID)
->setRepeat($row->repeat)
- ->setStart($row->start);
+ ->setStart($row->start)
+ ->setRunning($row->running);
$entries[$row->eventID] = $entry;
}
diff --git a/application/models/Eventreport.php b/application/models/Eventreport.php
index 3b9d11d..7b72ab0 100644
--- a/application/models/Eventreport.php
+++ b/application/models/Eventreport.php
@@ -14,6 +14,7 @@ class Application_Model_Eventreport
{
protected $_reportID;
protected $_report;
+ protected $_type;
protected $_eventID;
public function __construct(array $options = null)
@@ -119,5 +120,16 @@ class Application_Model_Eventreport
$this->_eventID = $_eventID;
return $this;
}
+
+ public function geType()
+ {
+ return $this->_type;
+ }
+
+ public function setType($_type)
+ {
+ $this->_type = $_type;
+ return $this;
+ }
}
diff --git a/application/models/EventreportMapper.php b/application/models/EventreportMapper.php
index 8ea9a28..19b2977 100644
--- a/application/models/EventreportMapper.php
+++ b/application/models/EventreportMapper.php
@@ -39,7 +39,7 @@ class Application_Model_EventreportMapper
$stmt = $select->query();
$result = $stmt->fetchAll();
- if(!$array){
+ if(!$array){
$entries = array();
if(count($result) > 0) {
foreach ($result as $row) {
@@ -84,7 +84,7 @@ class Application_Model_EventreportMapper
public function save(Application_Model_Eventreport $eventreport)
{
- $data = array('reportID'=> $eventreport->getID() ,'eventID'=> $eventreport->getEventID() ,'report'=> $eventreport->getReport() );
+ $data = array('reportID'=> $eventreport->getID() ,'eventID'=> $eventreport->getEventID() ,'report'=> $eventreport->getReport(), 'type' => $eventreport->geType() );
if (null === ($id = $eventreport->getID()) ) {
unset($data['reportID']);
return $this->getDbTable()->insert($data);
@@ -118,7 +118,8 @@ class Application_Model_EventreportMapper
$eventreport
->setID($row->reportID)
->setEventID($row->eventID)
- ->setReport($row->report);
+ ->setReport($row->report)
+ ->setType($row->type);
}
public function fetchAll()
@@ -131,7 +132,8 @@ class Application_Model_EventreportMapper
$entry
->setID($row->reportID)
->setEventID($row->eventID)
- ->setReport($row->report);
+ ->setReport($row->report)
+ ->setType($row->type);
$entries[$row->reportID] = $entry;
}
diff --git a/application/models/Reporttype.php b/application/models/Reporttype.php
new file mode 100644
index 0000000..794e3f4
--- /dev/null
+++ b/application/models/Reporttype.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_Reporttype
+{
+ protected $_reporttypeID;
+ 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 reporttype property');
+ }
+ $this->$method($value);
+ }
+
+ public function __get($name)
+ {
+ $method = 'get' . $name;
+ if (('mapper' == $name) || !method_exists($this, $method)) {
+ throw new Exception('Invalid reporttype 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->_reporttypeID;
+ }
+ public function setID($_reporttypeID)
+ {
+ $this->reporttypeID = $_reporttypeID;
+ return $this;
+ }
+
+ public function getTitle()
+ {
+ return $this->_title;
+ }
+
+ public function setTitle($_title)
+ {
+ $this->_title = $_title;
+ return $this;
+ }
+}
+
diff --git a/application/models/ReporttypeMapper.php b/application/models/ReporttypeMapper.php
new file mode 100644
index 0000000..fbbd95a
--- /dev/null
+++ b/application/models/ReporttypeMapper.php
@@ -0,0 +1,148 @@
+<?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_ReporttypeMapper
+{
+
+ 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();
+ if(count($result) > 0) {
+ foreach ($result as $row) {
+ $entry = new Application_Model_Event($row);
+ $entry->setID($row['reporttypeID']);
+ $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_Reporttype');
+ }
+
+ return $this->_dbTable;
+ }
+
+ public function save(Application_Model_Reporttype $reporttype)
+ {
+ $data = array('reporttypeID'=> $reporttype->getID() ,'title'=> $reporttype->getTitle() );
+ if (null === ($id = $reporttype->getID()) ) {
+ unset($data['reporttypeID']);
+ return $this->getDbTable(F)->insert($data);
+ } else {
+ $this->getDbTable()->update($data, array('reporttypeID = ?' => $id));
+ }
+ }
+
+ public function delete(Application_Model_Reporttype $reporttype)
+ {
+ if (null === ($id = $reporttype->getID()) ) {
+ return;
+ } else {
+ $this->getDbTable()->delete(array('reporttypeID = ?' => $id));
+ }
+ }
+
+ public function find($id, Application_Model_Reporttype $reporttype = null)
+ {
+ $result = $this->getDbTable()->find($id);
+ if (0 == count($result)) {
+ return;
+ }
+
+ $row = $result->current();
+
+ if($reporttype == null){
+ $reporttype = new Application_Model_Reporttype();
+ }
+
+ $reporttype
+ ->setID($row->reporttypeID)
+ ->setTitle($row->title);
+ }
+
+ public function fetchAll()
+ {
+ $resultSet = $this->getDbTable()->fetchAll();
+ $entries = array();
+ foreach ($resultSet as $row) {
+ $entry = new Application_Model_Reporttype();
+
+ $entry
+ ->setID($row->reporttypeID)
+ ->setTitle($row->title);
+
+ $entries[$row->reporttypeID] = $entry;
+ }
+ return $entries;
+ }
+
+ public function compare(Application_Model_Reporttype $v1,Application_Model_Reporttype $v2){
+ $vv1 = $v1->toArray();
+ $vv2 = $v2->toArray();
+ return array_diff($vv1,$vv2);
+ }
+
+
+
+} \ No newline at end of file
diff --git a/setup/poolctrl.sql b/setup/poolctrl.sql
index e1badbd..96db9d7 100644
--- a/setup/poolctrl.sql
+++ b/setup/poolctrl.sql
@@ -10,6 +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 NULL,
`participants` int(4) NOT NULL DEFAULT 50 CHECK (participants > 0),
+ `note` varchar(140) COLLATE utf8_unicode_ci DEFAULT NULL,
`category` int(11) NOT NULL,
`pbs_poolID` int(11) NOT NULL,
`pbs_membershipID` int(11) NOT NULL,
@@ -18,7 +19,7 @@ CREATE TABLE IF NOT EXISTS `poolctrl_event` (
`pbs_filterID` int(11) NOT NULL,
`repeat` bool NOT NULL DEFAULT false,
`immediate` bool NOT NULL DEFAULT false,
- `note` varchar(140) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `running` bool NOT NULL DEFAULT false,
PRIMARY KEY (`eventID`),
KEY `pbs_poolID` (`pbs_poolID`),
KEY `pbs_membershipID` (`pbs_membershipID`),
@@ -28,22 +29,29 @@ CREATE TABLE IF NOT EXISTS `poolctrl_event` (
KEY `category` (`category`)
) 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;
+
CREATE TABLE IF NOT EXISTS `poolctrl_eventreport` (
`reportID` int(11) NOT NULL AUTO_INCREMENT,
`report` varchar(140) COLLATE utf8_unicode_ci DEFAULT 'success',
+ `type` int(11) NOT NULL,
`eventID` int(11) NOT NULL,
`timestamp` timestamp COLLATE utf8_unicode_ci NOT NULL DEFAULT CURRENT_TIMESTAMP(),
PRIMARY KEY (`reportID`),
- KEY `eventID` (`eventID`)
+ KEY `eventID` (`eventID`),
+ KEY `type` (`type`)
) 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,
+CREATE TABLE IF NOT EXISTS `poolctrl_reporttype` (
+ `reporttypeID` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(30) COLLATE utf8_unicode_ci NOT NULL UNIQUE,
- PRIMARY KEY (`eventcategoryID`)
+ PRIMARY KEY (`reporttypeID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;
-
-- PBS2 Tabellen
-- TO DO: Tabellen an dieser Stelle nicht per Hand erzeugen sondern von der PBS2-Datenbank kopieren, sodass diese auf dem neusten Stand sind
CREATE TABLE IF NOT EXISTS `pbs_bootos` (
@@ -177,7 +185,8 @@ ALTER TABLE `pbs_membership`
ADD CONSTRAINT `pbs_membership_ibfk_2` FOREIGN KEY (`personID`) REFERENCES `pbs_person` (`personID`) ON DELETE CASCADE;
ALTER TABLE `poolctrl_eventreport`
- ADD CONSTRAINT `pbs_eventreport_eventidC` FOREIGN KEY (`eventID`) REFERENCES `poolctrl_event` (`eventID`) ON DELETE CASCADE;
+ ADD CONSTRAINT `pbs_eventreport_eventidC` FOREIGN KEY (`eventID`) REFERENCES `poolctrl_event` (`eventID`) ON DELETE CASCADE,
+ ADD CONSTRAINT `pbs_eventreport_typeidC` FOREIGN KEY (`type`) REFERENCES `poolctrl_reporttype` (`reporttypeID`) ON DELETE CASCADE;
ALTER TABLE `poolctrl_event`
ADD CONSTRAINT `poolctrl_event_poolidC` FOREIGN KEY (`pbs_poolID`) REFERENCES `pbs_pool` (`poolID`) ON DELETE CASCADE,
diff --git a/setup/poolctrl_data.sql b/setup/poolctrl_data.sql
index b699a14..87ed4ab 100644
--- a/setup/poolctrl_data.sql
+++ b/setup/poolctrl_data.sql
@@ -97,7 +97,12 @@ INSERT INTO `poolctrl_event` (`eventID`, `title`, `start`, `end`, `category`, `p
(3, 'Systeme III', '2011-06-24 16:10:00', '2011-06-24 18:00:00', '1', 1, 1, 1, 'Systeme III Vorlesung', 1, 1);
-- Adding eventreports
-INSERT INTO `poolctrl_eventreport` (`reportID`, `report`, `eventID`) VALUES
-(1, DEFAULT, 1),
-(2, DEFAULT, 2),
-(3, 'wake-on-lan failed', 3);
+INSERT INTO `poolctrl_eventreport` (`reportID`, `report`, `type`, `eventID`) VALUES
+(1, DEFAULT, 1, 1),
+(2, DEFAULT, 1, 2),
+(3, 'wake-on-lan failed', 1, 3);
+
+-- Adding reporttypes
+INSERT INTO `poolctrl_reporttype` (`reporttypeID`, `title`) VALUES
+(1, 'Boot'),
+(2, 'Shutdown');