diff options
author | AlexKlimenkov <shurick.klimenkov@gmail.com> | 2016-08-31 20:52:28 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-31 20:52:28 +0300 |
commit | d276ce08991385c5853ad24eff0fe38c25ee41d1 (patch) | |
tree | 4914c5a9669da7ee9e332a04bdd9156334e0da2f /SchedulerHelper.php | |
parent | c5dadfc3de449081ce6b0f10ae2ef2795fd575e1 (diff) | |
parent | a664bd255cdede492e0c175be8054c2e863c622e (diff) | |
download | scheduler-helper-php-master.zip scheduler-helper-php-master.tar.gz scheduler-helper-php-master.tar.bz2 |
Merge pull request #31 from mperednya/masterHEADorigin/masterorigin/HEADmaster
Fix recurring getting when rec is finished before interval.
Diffstat (limited to 'SchedulerHelper.php')
-rwxr-xr-x | SchedulerHelper.php | 50 |
1 files changed, 31 insertions, 19 deletions
diff --git a/SchedulerHelper.php b/SchedulerHelper.php index 6b2dd1a..9e58adf 100755 --- a/SchedulerHelper.php +++ b/SchedulerHelper.php @@ -235,7 +235,7 @@ class Helper extends DHelper implements IHelper OR ".$this->getRecurringTypeFieldName()." = '".RecurringType::IS_RECURRING_BREAK."' OR ".$this->getRecurringTypeFieldName()." IS NULL ) - AND ".$this->getLengthFieldName()." = '0' + AND (".$this->getLengthFieldName()." = '0' OR ".$this->getLengthFieldName()." is NULL) "; $query = $this->getConnection()->prepare($getEventsSql); @@ -269,33 +269,43 @@ class Helper extends DHelper implements IHelper * @return array */ private function _getRecurringEventsByInterval($startDate, $endDate) - { - $getEventsSql = " + { + $getEventsSql = " SELECT * FROM - ".$this->getTablename()." + " . $this->getTablename() . " WHERE ( - ( - ".$this->getEndDateFieldName()." >= '{$startDate}' - AND ".$this->getStartDateFieldName()." <= '{$endDate}' - ) - ) - AND ( - ".$this->getRecurringTypeFieldName()." != '".RecurringType::IS_RECURRING_EXCEPTION."' - AND ".$this->getRecurringTypeFieldName()." != '".RecurringType::IS_RECURRING_BREAK."' - AND ".$this->getRecurringTypeFieldName()." IS NOT NULL + " . $this->getRecurringTypeFieldName() . " != '" . RecurringType::IS_RECURRING_EXCEPTION . "' + AND " . $this->getRecurringTypeFieldName() . " != '" . RecurringType::IS_RECURRING_BREAK . "' + AND " . $this->getRecurringTypeFieldName() . " IS NOT NULL ) - AND ".$this->getLengthFieldName()." != '0' + AND " . $this->getLengthFieldName() . " != '0' "; - $query = $this->getConnection()->prepare($getEventsSql); - $query->execute(); + $query = $this->getConnection()->prepare($getEventsSql); + $query->execute(); $data = $query->fetchAll(); $this->closeConnection(); - return $data; - } + + $startDateFieldName = $this->getStartDateFieldName(); + $endDateFieldName = $this->getEndDateFieldName(); + $lengthFieldName = $this->getLengthFieldName(); + + $startStamp = $this->getDateTimestamp($startDate); + $endStamp = $this->getDateTimestamp($endDate); + + $data = array_filter($data, function ($el) use ($startDateFieldName, $endDateFieldName, $lengthFieldName, $startStamp, $endStamp) { + $evStart = $this->getDateTimestamp($el[$startDateFieldName]); + $evEnd = $this->getDateTimestamp($el[$endDateFieldName]); + $evLength = $el[$lengthFieldName]; + + return $evEnd + $evLength > $startStamp && $evStart < $endStamp; + }); + + return $data; + } /** * Exclude event extra data. @@ -374,6 +384,7 @@ class Helper extends DHelper implements IHelper $recField = $this->getRecurringTypeFieldName(); $startField = $this->getStartDateFieldName(); $endField = $this->getEndDateFieldName(); + $lengthField = $this->getLengthFieldName(); $recConfig = array( "start_on_monday" => $this->config["start_on_monday"] ); @@ -384,9 +395,10 @@ class Helper extends DHelper implements IHelper //Parse recurring data format. $recurringTypeData = $eventData[$recField]; + $recLength = $eventData[$lengthField]; $recurringStartDateStamp = $this->getDateTimestamp($eventData[$startField]); $recurringEndDateStamp = $this->getDateTimestamp($eventData[$endField]); - $recurringTypeObj = new RecurringType($recurringTypeData, $recurringStartDateStamp, $recurringEndDateStamp, $recConfig); + $recurringTypeObj = new RecurringType($recurringTypeData, $recurringStartDateStamp, $recurringEndDateStamp, $recLength, $recConfig); //Get recurring dates by parsed format. $recurringDatesStamps = $recurringTypeObj->getRecurringDates($intervalStartDateStamp, $intervalEndDateStamp); |