summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjörn Geiger2011-10-24 15:27:15 +0200
committerBjörn Geiger2011-10-24 15:27:15 +0200
commit29572969d06e32db90045788455586f7b2fc9e07 (patch)
treec0f2675726d18a69ab614924773aac408c705398
parentnochmal Korrektur2 (diff)
downloadpoolctrl-29572969d06e32db90045788455586f7b2fc9e07.tar.gz
poolctrl-29572969d06e32db90045788455586f7b2fc9e07.tar.xz
poolctrl-29572969d06e32db90045788455586f7b2fc9e07.zip
event overlapping funktioniert jetzt
-rwxr-xr-xapplication/controllers/EventController.php2
-rwxr-xr-xapplication/forms/EventAdd.php5
-rwxr-xr-xapplication/forms/EventEdit.php6
-rwxr-xr-xapplication/models/EventMapper.php22
-rwxr-xr-xlibrary/Poolctrl/Validate/EventOverlapping.php28
5 files changed, 29 insertions, 34 deletions
diff --git a/application/controllers/EventController.php b/application/controllers/EventController.php
index 1951fa3..1576633 100755
--- a/application/controllers/EventController.php
+++ b/application/controllers/EventController.php
@@ -2702,4 +2702,4 @@ class EventController extends Zend_Controller_Action
}
}
}
-} \ No newline at end of file
+}
diff --git a/application/forms/EventAdd.php b/application/forms/EventAdd.php
index 734659c..e0bf00d 100755
--- a/application/forms/EventAdd.php
+++ b/application/forms/EventAdd.php
@@ -192,14 +192,13 @@ class Application_Form_EventAdd extends Zend_Form
array('StringLength', false, array(0, 19)),
array('Date', false, array('format' => 'mm/dd/yyyy h:i a')),
array('DateGreaterThan', false, array('element' => 'End', 'compare' => 'Start', 'min' => $this->getElement('start')->getValue())),
+ array('EventOverlapping', false, array('poolID' => $this->poolID, 'start' => $this->getElement('start')->getValue())),
),
'required' => false,
'label' => 'End:',
'value' => $this->end,
));
$this->getElement('end')->addPrefixPath('Poolctrl_Validate', 'Poolctrl/Validate/', 'validate');
- $this->getElement('start')->addValidator(new Poolctrl_Validate_EventOverlapping(array('end' => $this->getElement('end')->getValue(), 'poolID' => $this->poolID)));
- $this->getElement('start')->addPrefixPath('Poolctrl_Validate', 'Poolctrl/Validate/', 'validate');
$this->addElement('checkbox', 'repeat', array(
'onchange' => 'repeatChanged("repeat")',
@@ -329,4 +328,4 @@ class Application_Form_EventAdd extends Zend_Form
'onclick' => 'location.href="/event/"',
));
}
-} \ No newline at end of file
+}
diff --git a/application/forms/EventEdit.php b/application/forms/EventEdit.php
index 1e1ce39..1c1e592 100755
--- a/application/forms/EventEdit.php
+++ b/application/forms/EventEdit.php
@@ -164,6 +164,7 @@ class Application_Form_EventEdit extends Zend_Form
array('StringLength', false, array(0, 19)),
array('Date', false, array('format' => 'mm/dd/yyyy h:i a')),
array('DateGreaterThan', false, array('element' => 'End', 'compare' => 'Start', 'min' => $this->getElement('start')->getValue())),
+ array('EventOverlapping', false, array('poolID' => $this->params['pbs_poolID'], 'start' => $this->getElement('start')->getValue())),
),
'required' => false,
'label' => 'End:',
@@ -177,6 +178,7 @@ class Application_Form_EventEdit extends Zend_Form
array('StringLength', false, array(0, 19)),
array('Date', false, array('format' => 'mm/dd/yyyy h:i a')),
array('DateGreaterThan', false, array('element' => 'End', 'compare' => 'Start', 'min' => $this->getElement('start')->getValue())),
+ array('EventOverlapping', false, array('poolID' => $this->params['pbs_poolID'], 'start' => $this->getElement('start')->getValue())),
),
'required' => false,
'label' => 'End:',
@@ -184,8 +186,6 @@ class Application_Form_EventEdit extends Zend_Form
));
$this->getElement('end')->addPrefixPath('Poolctrl_Validate', 'Poolctrl/Validate/', 'validate');
}
- $this->getElement('start')->addValidator(new Poolctrl_Validate_EventOverlapping(array('end' => $this->getElement('end')->getValue(), 'poolID' => $this->params['pbs_poolID'])));
- $this->getElement('start')->addPrefixPath('Poolctrl_Validate', 'Poolctrl/Validate/', 'validate');
if( $this->params['repeat'] == 1) {
$this->addElement('checkbox', 'repeat', array(
@@ -398,4 +398,4 @@ class Application_Form_EventEdit extends Zend_Form
'onclick' => 'location.href="/event/"',
));
}
-} \ No newline at end of file
+}
diff --git a/application/models/EventMapper.php b/application/models/EventMapper.php
index 7e5f41a..28f0e23 100755
--- a/application/models/EventMapper.php
+++ b/application/models/EventMapper.php
@@ -465,21 +465,17 @@ class Application_Model_EventMapper
}
- public function getOverlappingEvents($start, $end) {
+ public function getOverlappingEvents($start, $end, $poolID) {
$db = Zend_Db_Table::getDefaultAdapter();
- $select = "SELECT * FROM poolctrl_event WHERE ( start < '" . $start . "' ) AND ( end BETWEEN '" . $end . "' AND '" . $start . "' )";
- $stmt1 = $db->query($select);
- $result1 = $stmt1->fetchAll();
- $select = "SELECT * FROM poolctrl_event WHERE ( start BEETWEEN '" . $start . "' AND '" . $end . "' ) AND ( end BEETWEEN '" . $start . "' AND '" . $end . "' )";
- $stmt2 = $db->query($select);
- $result2 = $stmt2->fetchAll();
- $merge = array_merge($result1, $result2);
- $select = "SELECT * FROM poolctrl_event WHERE ( start BEETWEEN '" . $start . "' AND '" . $end . "' ) AND ( end > '" . $end . "' )";
- $stmt3 = $db->query($select);
- $result3 = $stmt3->fetchAll();
- $return = array_merge($merge, $result3);
+ $select = "SELECT * FROM poolctrl_event WHERE ( ( start <= '" . $start . "' AND end >= '" . $end . "' ) OR ( start <= '" . $end . "' AND end >= '" . $end . "' ) OR ( start <= '" . $start . "' AND end >= '" . $start . "' ) OR ( start = '" . $start . "' AND end = '" . $end . "' ) ) AND pbs_poolID = '" . $poolID . "'";
+ $stmt = $db->query($select);
+ $results = $stmt->fetchAll();
+ foreach($results as $result) {
+ $event = new Application_Model_Event($result);
+ $return[] = $event;
+ }
return $return;
}
-} \ No newline at end of file
+}
diff --git a/library/Poolctrl/Validate/EventOverlapping.php b/library/Poolctrl/Validate/EventOverlapping.php
index f2a0779..b28630b 100755
--- a/library/Poolctrl/Validate/EventOverlapping.php
+++ b/library/Poolctrl/Validate/EventOverlapping.php
@@ -10,10 +10,10 @@ class Poolctrl_Validate_EventOverlapping extends Zend_Validate_Abstract
);
protected $_messageVariables = array(
- 'overlappingEvent' => '_overlappingEvent',
+ 'overlappingEvent' => '_overlappingevent',
);
- protected $_end;
+ protected $_start;
protected $_poolID;
protected $_overlappingevent;
@@ -24,11 +24,11 @@ class Poolctrl_Validate_EventOverlapping extends Zend_Validate_Abstract
}
if (is_array($option)) {
- if (array_key_exists('end', $option)) {
- $_end = strtotime($option['end']);
+ if (array_key_exists('start', $option)) {
+ $_start = strtotime($option['start']);
} else {
require_once 'Zend/Validate/Exception.php';
- throw new Zend_Validate_Exception("Missing option 'end'");
+ throw new Zend_Validate_Exception("Missing option 'start'");
}
if (array_key_exists('poolID', $option)) {
$_poolID = $option['poolID'];
@@ -38,18 +38,18 @@ class Poolctrl_Validate_EventOverlapping extends Zend_Validate_Abstract
}
}
- $this->_setEnd($_end);
+ $this->_setStart($_start);
$this->_setPoolID($_poolID);
}
- public function _getEnd()
+ public function _getStart()
{
- return $this->_end;
+ return $this->_start;
}
- public function _setEnd($_end)
+ public function _setStart($_start)
{
- $this->_end = $_end;
+ $this->_start = $_start;
}
public function _getOverlappingevent()
@@ -57,9 +57,9 @@ class Poolctrl_Validate_EventOverlapping extends Zend_Validate_Abstract
return $this->_overlappingevent;
}
- public function _setOverlappingevent($overlappingevent)
+ public function _setOverlappingevent($_overlappingevent)
{
- $this->_overlappingevent = $overlappingevent;
+ $this->_overlappingevent = $_overlappingevent;
}
public function _getPoolID()
@@ -76,7 +76,7 @@ class Poolctrl_Validate_EventOverlapping extends Zend_Validate_Abstract
{
$this->_setValue(strtotime($value));
$eventMapper = new Application_Model_EventMapper();
- $overlappingEvents = $eventMapper->getOverlappingEvents($this->_value, $this->_end);
+ $overlappingEvents = $eventMapper->getOverlappingEvents(date('Y-m-d H:i:s', $this->_start), date('Y-m-d H:i:s', $this->_value), $this->_poolID);
if (count($overlappingEvents) > 0) {
$this->_setOverlappingevent($overlappingEvents[0]->getTitle());
@@ -85,4 +85,4 @@ class Poolctrl_Validate_EventOverlapping extends Zend_Validate_Abstract
}
return true;
}
-} \ No newline at end of file
+}