summaryrefslogtreecommitdiffstats
path: root/application
diff options
context:
space:
mode:
authorSebastian Wagner2011-08-22 12:44:31 +0200
committerSebastian Wagner2011-08-22 12:44:31 +0200
commit470de8e236029aab49ef705a1b75f50e7f83c280 (patch)
tree585401703d3c8589e002eecb4ff96878844a5e2f /application
parentevents are now displayed in the calendar (diff)
parentkleine Korrekutr (diff)
downloadpoolctrl-470de8e236029aab49ef705a1b75f50e7f83c280.tar.gz
poolctrl-470de8e236029aab49ef705a1b75f50e7f83c280.tar.xz
poolctrl-470de8e236029aab49ef705a1b75f50e7f83c280.zip
Merge branch 'master' of git.openslx.org:lsfks/projekte/poolctrl
Diffstat (limited to 'application')
-rw-r--r--application/configs/application.ini.dist9
-rw-r--r--application/controllers/EventController.php118
-rw-r--r--application/controllers/GearmanController.php39
-rw-r--r--application/layouts/default.phtml2
-rw-r--r--application/models/DbTable/Eventtype.php20
-rw-r--r--application/models/Event.php24
-rw-r--r--application/models/EventMapper.php10
-rw-r--r--application/models/Eventreport.php34
-rw-r--r--application/models/EventreportMapper.php10
-rw-r--r--application/models/Eventtype.php111
-rw-r--r--application/models/EventtypeMapper.php142
11 files changed, 488 insertions, 31 deletions
diff --git a/application/configs/application.ini.dist b/application/configs/application.ini.dist
index 92cb0cf..6176733 100644
--- a/application/configs/application.ini.dist
+++ b/application/configs/application.ini.dist
@@ -16,6 +16,8 @@ resources.db.isDefaultTableAdapter = true
resources.db.params.driver_options.1002 = "SET NAMES UTF8;"
resources.view[] = ""
resources.modules = ""
+resources.layout.layout = "default"
+resources.layout.layoutPath = APPLICATION_PATH "/layouts"
pbs2.host =
pbs2.login = /resource/login/
pbs2.checkright = /resource/checkright/apikey
@@ -30,9 +32,10 @@ pbs2.getperson = /resource/getperson/apikey/
pbs2.getmembership = /resource/getmembership/apikey/
pbs2.getgroup = /resource/getgroup/apikey/
pbs2.getrole = /resource/getrole/apikey/
-
-resources.layout.layout = "default"
-resources.layout.layoutPath = APPLICATION_PATH "/layouts"
+gearman.server.host =
+gearman.server.port =
+gearman.worker.waitTime = 120
+gearman.worker.updateRate = 1
[staging : production]
diff --git a/application/controllers/EventController.php b/application/controllers/EventController.php
index 5a53714..46529b8 100644
--- a/application/controllers/EventController.php
+++ b/application/controllers/EventController.php
@@ -18,9 +18,15 @@ class EventController extends Zend_Controller_Action
protected $pbs2host;
protected $userIDsNamespace;
protected $acl;
+ protected $gearmanClient;
+ protected $gearmanServerHost;
+ protected $gearmanServerPort;
+ protected $gearmanWorkerUpdateRate;
+ protected $gearmanWorkerWaitTime;
public function init()
{
+ $actionName = $this->getRequest()->getActionName();
if (Zend_Auth::getInstance()->hasIdentity()) {
$bootstrap = $this->getInvokeArg('bootstrap');
$this->config = $bootstrap->getOptions();
@@ -36,6 +42,61 @@ class EventController extends Zend_Controller_Action
$this->_helper->redirector('selectmembership', 'person');
return;
}
+ } else if($actionName == "report" || $actionName == "run") {
+ $this->userIDsNamespace = Zend_Session::namespaceGet('userIDs');
+ if(isset($this->userIDsNamespace['apikey'])) {
+ $apikey = $this->userIDsNamespace['apikey'];
+ } else {
+ $apikey = $this->_request->getParam('apikey');
+ }
+ if($apikey == ""){
+ $email = $this->_request->getParam('email');
+ $password = $this->_request->getParam('password');
+ if(!isset($email)) {
+ header('HTTP/1.0 401 No email is set');
+ die();
+ }
+ if(!isset($password)) {
+ header('HTTP/1.0 401 No password is set');
+ die();
+ }
+ $loginquery = "email=" . $email . "&password=" . $password;
+ $loginApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['login'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $loginquery);
+ $loginXMLString = $loginApiResult['http-body'];
+ if(strlen($loginXMLString) > 0) {
+ $loginXML = new SimpleXMLElement($loginXMLString);
+ $login = $loginXML->login;
+ $success = sprintf("%s", $login->success);
+ if ($success === "true") {
+ $bootstrap = $this->getInvokeArg('bootstrap');
+ $this->config = $bootstrap->getOptions();
+ $this->pbs2host = $this->config['pbs2']['host'];
+ $this->gearmanServerHost = $this->config['gearman']['server']['host'];
+ $this->gearmanServerPort = $this->config['gearman']['server']['port'];
+ $this->gearmanWorkerWaitTime = $this->config['gearman']['worker']['waitTime'];
+ $this->gearmanWorkerUpdateRate = $this->config['gearman']['worker']['updateRate'];
+ $this->gearmanClient = new GearmanClient();
+ $this->gearmanClient->addServer($this->gearmanServerHost);
+ $this->eventMapper = new Application_Model_EventMapper();
+ $this->eventcategoryMapper = new Application_Model_EventcategoryMapper();
+ } else {
+ header('HTTP/1.0 401 Wrong email or password');
+ die();
+ }
+ }
+ } else {
+ $bootstrap = $this->getInvokeArg('bootstrap');
+ $this->config = $bootstrap->getOptions();
+ $this->pbs2host = $this->config['pbs2']['host'];
+ $this->gearmanServerHost = $this->config['gearman']['server']['host'];
+ $this->gearmanServerPort = $this->config['gearman']['server']['port'];
+ $this->gearmanWorkerWaitTime = $this->config['gearman']['worker']['waitTime'];
+ $this->gearmanWorkerUpdateRate = $this->config['gearman']['worker']['updateRate'];
+ $this->gearmanClient = new GearmanClient();
+ $this->gearmanClient->addServer($this->gearmanServerHost);
+ $this->eventMapper = new Application_Model_EventMapper();
+ $this->eventcategoryMapper = new Application_Model_EventcategoryMapper();
+ }
} else {
$this->_helper->redirector('login', 'auth');
return;
@@ -456,4 +517,61 @@ class EventController extends Zend_Controller_Action
}
echo json_encode($events);
}
+
+ public function runAction() {
+ $this->_helper->layout->disableLayout();
+ $this->_helper->viewRenderer->setNoRender();
+
+ $events = $this->eventMapper->findBy(array());
+ }
+
+ public function reportAction() {
+ $this->_helper->layout->disableLayout();
+ $this->_helper->viewRenderer->setNoRender();
+
+ $events = $this->eventMapper->findBy(array('running' => 1));
+ $runningtypeMapper = new Application_Model_RunningtypeMapper();
+ $runningtypeBoot = $runningtypeMapper->findBy(array("title" => "boot"));
+ $runningtypeShutdown = $runningtypeMapper->findBy(array("title" => "shutdown"));
+ $eventBootNames = array();
+ $eventShutdownNames = array();
+
+ foreach($events as $event) {
+ if($event->getRunningtype() == $runningtypeBoot[0]->getID()) {
+ $eventBootNames[] = $event->getTitle();
+ } else if($event->getRunningtype() == $runningtypeShutdown[0]->getID()) {
+ $eventShutdownNames[] = $event->getTitle();
+ }
+ }
+
+ if(count($eventBootNames) > 0) {
+ $data = array(
+ 'type' => 'boot',
+ 'events' => $eventBootNames,
+ );
+
+ $dataString = json_encode($data);
+ $bootResult = $this->gearmanClient->do("status", $dataString, 'bootStatus');
+ if (! $this->gearmanClient->runTasks())
+ {
+ echo "ERROR " . $gmc->error() . "\n";
+ exit;
+ }
+ }
+
+ if(count($eventShutdownNames) > 0) {
+ $data = array(
+ 'type' => 'shutdown',
+ 'events' => $eventShutdownNames,
+ );
+
+ $dataString = json_encode($data);
+ $shutdownResult = $this->gearmanClient->do("status", $dataString, 'shutdownStatus');
+ if (! $this->gearmanClient->runTasks())
+ {
+ echo "ERROR " . $gmc->error() . "\n";
+ exit;
+ }
+ }
+ }
} \ No newline at end of file
diff --git a/application/controllers/GearmanController.php b/application/controllers/GearmanController.php
index 7ca673d..a0de744 100644
--- a/application/controllers/GearmanController.php
+++ b/application/controllers/GearmanController.php
@@ -2,11 +2,15 @@
class GearmanController extends Zend_Controller_Action
{
- protected $gearmanClient;
protected $config;
protected $pbs2host;
protected $userIDsNamespace;
protected $acl;
+ protected $gearmanClient;
+ protected $gearmanServerHost;
+ protected $gearmanServerPort;
+ protected $gearmanWorkerUpdateRate;
+ protected $gearmanWorkerWaitTime;
public function init()
{
@@ -18,12 +22,17 @@ class GearmanController extends Zend_Controller_Action
if(isset($this->userIDsNamespace['apikey'])) {
$this->acl = new Poolctrl_Acl($this->pbs2host, $this->config['pbs2']['checkright'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
}
+ $this->gearmanServerHost = $this->config['gearman']['server']['host'];
+ $this->gearmanServerPort = $this->config['gearman']['server']['port'];
+ $this->gearmanWorkerWaitTime = $this->config['gearman']['worker']['waitTime'];
+ $this->gearmanWorkerUpdateRate = $this->config['gearman']['worker']['updateRate'];
$this->gearmanClient = new GearmanClient();
- $this->gearmanClient->addServer('127.0.0.1');
+ $this->gearmanClient->addServer($this->gearmanServerHost);
} else {
$this->_helper->redirector('login', 'auth');
return;
}
+
}
public function indexAction()
@@ -91,13 +100,13 @@ class GearmanController extends Zend_Controller_Action
public function bootAction() {
$eventName = 'bootTest';
$eventOS = 'testOS';
- $updateRate = 1;
- $waitTime = 120;
$clients = array(
'eventName' => $eventName,
'eventOS' => $eventOS,
- 'updateRate' => $updateRate,
- 'waitTime' => $waitTime,
+ 'updateRate' => $this->gearmanWorkerUpdateRate,
+ 'waitTime' => $this->gearmanWorkerWaitTime,
+ 'host' => $this->gearmanServerHost,
+ 'port' => $this->gearmanServerPort,
'clients' => array(
0 => array('id' => '1', 'ip' =>'132.230.4.24', 'mac' =>'00:13:72:C7:FD:A1'),
),
@@ -115,12 +124,12 @@ class GearmanController extends Zend_Controller_Action
public function shutdownAction() {
$eventName = 'shutdownTest';
- $updateRate = 1;
- $waitTime = 120;
$clients = array(
'eventName' => $eventName,
- 'updateRate' => $updateRate,
- 'waitTime' => $waitTime,
+ 'updateRate' => $this->gearmanWorkerUpdateRate,
+ 'waitTime' => $this->gearmanWorkerWaitTime,
+ 'host' => $this->gearmanServerHost,
+ 'port' => $this->gearmanServerPort,
'clients' => array(
0 => array('id' => '1', 'ip' =>'132.230.4.24', 'mac' =>'00:13:72:C7:FD:A1'),
),
@@ -135,15 +144,15 @@ class GearmanController extends Zend_Controller_Action
}
$this->view->result = $result;
}
-
+
public function maintenanceAction() {
$eventName = 'maintenance_pool-113'; //maintenance of pool-113
- $updateRate = 1;
- $waitTime = 120;
$clients = array(
'eventName' => $eventName,
- 'updateRate' => $updateRate,
- 'waitTime' => $waitTime,
+ 'updateRate' => $this->gearmanWorkerUpdateRate,
+ 'waitTime' => $this->gearmanWorkerWaitTime,
+ 'host' => $this->gearmanServerHost,
+ 'port' => $this->gearmanServerPort,
'clients' => array(
0 => array('id' => '1', 'ip' =>'132.230.4.121', 'mac' =>'00:1e:0b:a6:f8:19'),
0 => array('id' => '2', 'ip' =>'132.230.4.122', 'mac' =>'00:1e:0b:a6:d5:de'),
diff --git a/application/layouts/default.phtml b/application/layouts/default.phtml
index a408551..0c48782 100644
--- a/application/layouts/default.phtml
+++ b/application/layouts/default.phtml
@@ -38,7 +38,7 @@ echo $this->headScript()."\n";
<li class='navTreeItem'><a href='/'>Home</a></li>
<?php if(Zend_Auth::getInstance()->hasIdentity()) { ?>
<li class='navTreeItem'><a href='/person/'>Own Details</a></li>
- <?php if(count(Zend_Session::namespaceGet('userIDs')) > 0) { ?>
+ <?php if(count(Zend_Session::namespaceGet('userIDs')) > 1) { ?>
<li class='navTreeItem'><a href='/event'>Event</a></li>
<li class='navTreeItem'><a href='/person/changemembership'>Change
Membership</a></li>
diff --git a/application/models/DbTable/Eventtype.php b/application/models/DbTable/Eventtype.php
new file mode 100644
index 0000000..6c54913
--- /dev/null
+++ b/application/models/DbTable/Eventtype.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_Eventtype extends Zend_Db_Table_Abstract
+{
+
+ protected $_name = 'poolctrl_eventtype';
+
+
+}
+
diff --git a/application/models/Event.php b/application/models/Event.php
index b69412e..9033824 100644
--- a/application/models/Event.php
+++ b/application/models/Event.php
@@ -26,6 +26,8 @@ class Application_Model_Event
protected $_pbs_filterID;
protected $_repeat;
protected $_immediate;
+ protected $_running;
+ protected $_runningtype;
protected $_note;
public function __construct(array $options = null)
@@ -264,5 +266,27 @@ 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;
+ }
+
+ public function getRunningtype()
+ {
+ return $this->_runningtype;
+ }
+
+ public function setRunningtype($_runningtype)
+ {
+ $this->_runningtype = $_runningtype;
+ return $this;
+ }
}
diff --git a/application/models/EventMapper.php b/application/models/EventMapper.php
index 394fea2..98e6c14 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(), 'runningtype' => $event->getRunningtype() );
if (null === ($id = $event->getID()) ) {
unset($data['eventID']);
return $this->getDbTable()->insert($data);
@@ -130,7 +130,9 @@ 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)
+ ->setRunningtype($row->runningtype);
}
public function fetchAll()
@@ -155,7 +157,9 @@ 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)
+ ->setRunningtype($row->runningtype);
$entries[$row->eventID] = $entry;
}
diff --git a/application/models/Eventreport.php b/application/models/Eventreport.php
index 3b9d11d..ff94a09 100644
--- a/application/models/Eventreport.php
+++ b/application/models/Eventreport.php
@@ -13,7 +13,9 @@
class Application_Model_Eventreport
{
protected $_reportID;
- protected $_report;
+ protected $_result;
+ protected $_errors;
+ protected $_type;
protected $_eventID;
public function __construct(array $options = null)
@@ -98,14 +100,25 @@ class Application_Model_Eventreport
return $this;
}
- public function getReport()
+ public function getResult()
{
- return $this->_report;
+ return $this->_result;
}
- public function setReport($_report)
+ public function setResult($_result)
{
- $this->_report = $_report;
+ $this->_result = $_result;
+ return $this;
+ }
+
+ public function getErrors()
+ {
+ return $this->_errors;
+ }
+
+ public function setErrors($_errors)
+ {
+ $this->_errors = $_errors;
return $this;
}
@@ -119,5 +132,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/Eventtype.php b/application/models/Eventtype.php
new file mode 100644
index 0000000..fe21eeb
--- /dev/null
+++ b/application/models/Eventtype.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_Eventtype
+{
+ protected $_eventtypeID;
+ 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 eventtype property');
+ }
+ $this->$method($value);
+ }
+
+ public function __get($name)
+ {
+ $method = 'get' . $name;
+ if (('mapper' == $name) || !method_exists($this, $method)) {
+ throw new Exception('Invalid eventtype 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->_eventtypeID;
+ }
+ public function setID($_eventtypeID)
+ {
+ $this->_eventtypeID = $_eventtypeID;
+ return $this;
+ }
+
+ public function getTitle()
+ {
+ return $this->_title;
+ }
+
+ public function setTitle($_title)
+ {
+ $this->_title = $_title;
+ return $this;
+ }
+}
+
diff --git a/application/models/EventtypeMapper.php b/application/models/EventtypeMapper.php
new file mode 100644
index 0000000..c6b8572
--- /dev/null
+++ b/application/models/EventtypeMapper.php
@@ -0,0 +1,142 @@
+<?php
+
+class Application_Model_EventtypeMapper
+{
+ 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_Eventtype($row);
+ $entry->setID($row['eventtypeID']);
+ $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_Eventtype');
+ }
+
+ return $this->_dbTable;
+ }
+
+ public function save(Application_Model_Eventtype $eventtype)
+ {
+
+ $data = array('eventtypeID'=> $eventtype->getID() ,'title'=> $eventtype->getTitle() );
+
+ if (null === ($id = $eventtype->getID()) ) {
+ unset($data['eventtypeID']);
+ $this->getDbTable()->insert($data);
+ } else {
+ $this->getDbTable()->update($data, array('eventtypeID = ?' => $id));
+ }
+ }
+
+ public function delete(Application_Model_Eventtype $eventtype)
+ {
+ if (null === ($id = $eventtype->getID()) ) {
+ return;
+ } else {
+ $this->getDbTable()->delete(array('eventtypeID = ?' => $id));
+ }
+ }
+
+ public function find($id, Application_Model_Eventtype $eventtype)
+ {
+ $result = $this->getDbTable()->find($id);
+ if (0 == count($result)) {
+ return;
+ }
+
+ if($eventtype == null) {
+ $return = true;
+ }
+
+ $row = $result->current();
+
+ if($return) {
+ $eventtype = new Application_Model_Eventtype();
+ $eventtype
+ ->setID($row->eventtypeID)
+ ->setTitle($row->title);
+ return $eventtype;
+ } else {
+ $eventtype
+ ->setID($row->eventtypeID)
+ ->setTitle($row->title);
+ }
+ }
+
+ public function fetchAll()
+ {
+ $resultSet = $this->getDbTable()->fetchAll();
+ $entries = array();
+ foreach ($resultSet as $row) {
+ $entry = new Application_Model_Eventtype();
+
+ $entry
+ ->setID($row->eventtypeID)
+ ->setTitle($row->title);
+
+ $entries[] = $entry;
+ }
+ return $entries;
+ }
+
+
+
+}
+