From b4d972ba8884a7ad02399d6cad3004f18ed85459 Mon Sep 17 00:00:00 2001 From: Björn Geiger Date: Mon, 10 Oct 2011 14:58:37 +0200 Subject: Edit Event geändert, noch nicht vollständig --- application/configs/application.ini.dist | 3 +- application/controllers/EventController.php | 129 +++++++++++++++++----------- install.sh | 6 +- 3 files changed, 83 insertions(+), 55 deletions(-) diff --git a/application/configs/application.ini.dist b/application/configs/application.ini.dist index 3453ad4..f4dde68 100755 --- a/application/configs/application.ini.dist +++ b/application/configs/application.ini.dist @@ -26,8 +26,9 @@ pbs2.getpools = /resource/getpool/apikey/ pbs2.addbootmenu = /resource/addbootmenu/apikey/ pbs2.deletebootmenu = /resource/deletebootmenu/apikey/ pbs2.addfilter = /resource/addfilter/apikey/ -pbs2.addfilterentry = /resource/addfilterentry/apikey/ +pbs2.changefilter = /resource/changefilter/apikey/ pbs2.deletefilter = /resource/deletefilter/apikey/ +pbs2.addfilterentry = /resource/addfilterentry/apikey/ pbs2.changefilterentry = /resource/changefilterentry/apikey/ pbs2.getperson = /resource/getperson/apikey/ pbs2.getmembership = /resource/getmembership/apikey/ diff --git a/application/controllers/EventController.php b/application/controllers/EventController.php index b2ff1ae..d1b4ab7 100755 --- a/application/controllers/EventController.php +++ b/application/controllers/EventController.php @@ -346,6 +346,8 @@ class EventController extends Zend_Controller_Action } else { $event = new Application_Model_Event(); $this->eventMapper->find($eventID, $event); + $oldEvent = new Application_Model_Event(); + $this->eventMapper->find($eventID, $oldEvent); if($event->getImmediate()) { $this->_redirect('/event/'); exit; @@ -448,66 +450,72 @@ class EventController extends Zend_Controller_Action if(!isset($params['repeatings'])) { unset($params['repeatings']); } - if($event->getPbs_bootmenuID()) { + $params['immediate'] = 0; + $event->setOptions($params); + $event->setID($eventID); + $diff = $this->eventMapper->compare($oldEvent, $event); + if(isset($diff['pbs_bootosID']) || isset($diff['title']) || isset($diff['pbs_configID'])) { $bootmenuApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['deletebootmenu'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', "bootmenuid=" . $event->getPbs_bootmenuID()); unset($bootmenuApiResult); + $bootmenuquery = "bootosID=" . $event->getPbs_bootosID() . "&startcounter=0&title=Poolctrl-Bootmenu for " . $event->getTitle() . "&defaultbootmenu=0&order=0&kcl=0"; + if($event->getPbs_configID()) { + $bootmenuquery .= "&configID=" . $event->getPbs_configID(); + } + $bootmenuApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['addbootmenu'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $bootmenuquery); + $bootmenuXMLString = $bootmenuApiResult['http-body']; + $bootmenuXML = new SimpleXMLElement($bootmenuXMLString); + $bootmenuID = sprintf("%s", $bootmenuXML->bootmenu->id); + $event->setPbs_bootmenuID($bootmenuID); + $filterQuerie = "filterid=" . $event->getPbs_filterID() . "&bootmenuID = " . $bootmenuID; + $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['changefilter'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterQuerie); + unset($filterApiResult); } - if($event->getPbs_filterID()) { + if(isset($diff['start']) || isset($diff['end']) || isset($diff['pbs_poolID'])) { $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['deletefilter'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', "filterid=" . $event->getPbs_filterID()); unset($filterApiResult); - } - $params['immediate'] = 0; - if($event->getRepeat() && isset($params['wdh'])) { - $this->deleteRepeatEvents($event); - } - $event->setOptions($params); - $event->setID($eventID); - $bootmenuquery = "bootosID=" . $event->getPbs_bootosID() . "&startcounter=0&title=Poolctrl-Bootmenu for " . $event->getTitle() . "&defaultbootmenu=0&order=0&kcl=0"; - if($event->getPbs_configID()) { - $bootmenuquery .= "&configID=" . $event->getPbs_configID(); - } - $bootmenuApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['addbootmenu'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $bootmenuquery); - $bootmenuXMLString = $bootmenuApiResult['http-body']; - $bootmenuXML = new SimpleXMLElement($bootmenuXMLString); - $bootmenuID = sprintf("%s", $bootmenuXML->bootmenu->id); - $event->setPbs_bootmenuID($bootmenuID); - $filterquery = "bootmenuID=" . $event->getPbs_bootmenuID() . "&title=Poolctrl-Filter for " . $event->getTitle() . "&description=This Filter was automatically created by the Poolctrl for Event " . $event->getTitle() . "&created= " . time() . "&priority=100"; - $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['addfilter'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterquery); - $filterXMLString = $filterApiResult['http-body']; - $filterXML = new SimpleXMLElement($filterXMLString); - $filterID = sprintf("%s", $filterXML->filter->id); - $event->setPbs_filterID($filterID); - $startTime = date('H:i', strtotime($event->getStart())); - if($event->getEnd()) { - $endTime = date('H:i', strtotime($event->getEnd())); + $newFilter = true; } else { - $endTime = date('H:i', strtotime($event->getStart()) + 900); + $newFilter = false; } - $filterentriesquery1 = "filterID=" . $event->getPbs_filterID() . "&filtertypeID=7&filtervalue=" . $startTime . "&filtervalue2=" . $endTime; - $filterentriesApiResult1 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery1); - $filterentriesXMLString1 = $filterentriesApiResult1['http-body']; - $filterentriesXML1 = new SimpleXMLElement($filterentriesXMLString1); - $filterentriesID1 = sprintf("%s", $filterentriesXML1->filterentry->id); - $filterentriesquery2 = "filterID=" . $event->getPbs_filterID() . "&filtertypeID=3&filtervalue=" . $event->getPbs_poolID(); - $filterentriesApiResult2 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery2); - $filterentriesXMLString2 = $filterentriesApiResult2['http-body']; - $filterentriesXML2 = new SimpleXMLElement($filterentriesXMLString2); - $filterentriesID2 = sprintf("%s", $filterentriesXML2->filterentry->id); - if(!$event->getRepeat()) { - $startDate = date('d.m.Y', strtotime($event->getStart())); + if($newFilter) { + $filterquery = "bootmenuID=" . $event->getPbs_bootmenuID() . "&title=Poolctrl-Filter for " . $event->getTitle() . "&description=This Filter was automatically created by the Poolctrl for Event " . $event->getTitle() . "&created= " . time() . "&priority=100"; + $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['addfilter'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterquery); + $filterXMLString = $filterApiResult['http-body']; + $filterXML = new SimpleXMLElement($filterXMLString); + $filterID = sprintf("%s", $filterXML->filter->id); + $event->setPbs_filterID($filterID); + $startTime = date('H:i', strtotime($event->getStart())); if($event->getEnd()) { - $endDate = date('d.m.Y', strtotime($event->getEnd())); + $endTime = date('H:i', strtotime($event->getEnd())); } else { - $endDate = date('d.m.Y', strtotime($event->getStart())); + $endTime = date('H:i', strtotime($event->getStart()) + 900); + } + $filterentriesquery1 = "filterID=" . $event->getPbs_filterID() . "&filtertypeID=7&filtervalue=" . $startTime . "&filtervalue2=" . $endTime; + $filterentriesApiResult1 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery1); + $filterentriesXMLString1 = $filterentriesApiResult1['http-body']; + $filterentriesXML1 = new SimpleXMLElement($filterentriesXMLString1); + $filterentriesID1 = sprintf("%s", $filterentriesXML1->filterentry->id); + $filterentriesquery2 = "filterID=" . $event->getPbs_filterID() . "&filtertypeID=3&filtervalue=" . $event->getPbs_poolID(); + $filterentriesApiResult2 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery2); + $filterentriesXMLString2 = $filterentriesApiResult2['http-body']; + $filterentriesXML2 = new SimpleXMLElement($filterentriesXMLString2); + $filterentriesID2 = sprintf("%s", $filterentriesXML2->filterentry->id); + if(!$event->getRepeat()) { + $startDate = date('d.m.Y', strtotime($event->getStart())); + if($event->getEnd()) { + $endDate = date('d.m.Y', strtotime($event->getEnd())); + } else { + $endDate = date('d.m.Y', strtotime($event->getStart())); + } + $filterentriesquery3 = "filterID=" . $event->getPbs_filterID() . "&filtertypeID=11&filtervalue=" . $startDate . "&filtervalue2=" . $endDate; + $filterentriesApiResult3 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery3); + $filterentriesXMLString3 = $filterentriesApiResult3['http-body']; + $filterentriesXML3 = new SimpleXMLElement($filterentriesXMLString3); + $filterentriesID3 = sprintf("%s", $filterentriesXML3->filterentry->id); } - $filterentriesquery3 = "filterID=" . $event->getPbs_filterID() . "&filtertypeID=11&filtervalue=" . $startDate . "&filtervalue2=" . $endDate; - $filterentriesApiResult3 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery3); - $filterentriesXMLString3 = $filterentriesApiResult3['http-body']; - $filterentriesXML3 = new SimpleXMLElement($filterentriesXMLString3); - $filterentriesID3 = sprintf("%s", $filterentriesXML3->filterentry->id); } if($event->getRepeat() && isset($params['wdh'])) { - $this->repeatEvent($event); + $this->editRepeatEvent($oldEvent, $event); } else { try { $this->eventMapper->save($event); @@ -517,7 +525,7 @@ class EventController extends Zend_Controller_Action return; } } - $this->_redirect('/event/'); + //$this->_redirect('/event/'); } } else { $this->getRequest()->setParam('title', $event->getTitle()); @@ -651,7 +659,7 @@ class EventController extends Zend_Controller_Action // Check for overlap $overlaps = array(); foreach($events as $e) { - + $enewstart = strtotime($e['start']) + $diff; $enewend = strtotime($e['end']) + $diff; @@ -661,7 +669,7 @@ class EventController extends Zend_Controller_Action $overlaps[] = $o; } } - + $this->view->events = $events; $this->view->others = $others; $this->view->overlaps = $overlaps; @@ -2215,6 +2223,25 @@ class EventController extends Zend_Controller_Action return $eventID; } + private function editRepeatEvent(Application_Model_Event $oldEvent, Application_Model_Event $newEvent) { + $diff = $this->eventMapper->compare($newEvent, $oldEvent); + if(isset($diff['start']) || isset($diff['end']) || isset($diff['pbs_filterID'])) { + + } else { + $events = $this->eventMapper->findBy(array($oldEvent->getTitle())); + try { + foreach($events as $event) { + $event->setOptions($diff); + $this->eventMapper->save($event); + } + } catch (Zend_Exception $e) { + echo "Caught exception: " . get_class($e) . "
"; + echo "Message: " . $e->getMessage() . "
"; + return; + } + } + } + function deleteRepeatEvents(Application_Model_Event $repeatEvent) { $events = $this->eventMapper->findBy(array("title" => $repeatEvent->getTitle())); try { diff --git a/install.sh b/install.sh index c33987c..a0445c8 100755 --- a/install.sh +++ b/install.sh @@ -15,7 +15,7 @@ echo "Copying to /var/www/" sourceDir=$(readlink -f $(dirname $(readlink -f $0))) echo -n "enter vhost name: " read vhost_name -sed -e "37s/\$/$vhost_name/" -i $targetDir/application/configs/application.ini +sed -e "38s/\$/$vhost_name/" -i $targetDir/application/configs/application.ini targetDir="/var/www/$vhost_name" mkdir -p $targetDir cp -R $sourceDir/* $targetDir @@ -72,12 +72,12 @@ sed -e "21s/\$/$pbs2_host/" -i $targetDir/application/configs/application.ini echo -n "Please enter host of gearman server [localhost]: " read gearman_server_host [ "x" = "x$gearman_server_host" ] && gearman_server_host="localhost" -sed -e "40s/\$/$gearman_server_host/" -i $targetDir/application/configs/application.ini +sed -e "41s/\$/$gearman_server_host/" -i $targetDir/application/configs/application.ini echo -n "Please enter port of gearman server [4730]: " read gearman_server_port [ "x" = "x$gearman_server_port" ] && gearman_server_port="4730" -sed -e "41s/\$/$gearman_server_port/" -i $targetDir/application/configs/application.ini +sed -e "42s/\$/$gearman_server_port/" -i $targetDir/application/configs/application.ini echo "Create database and tables" cat $targetDir/setup/poolctrl.sql | sed -e "s,##poolctrl##,$db_name," > /tmp/poolctrl.sql -- cgit v1.2.3-55-g7522