|
@ -32,15 +32,20 @@ function generateUrl($supplier = null, $event = null) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function findNext($start, $frequency, $excludes = [], $maxIterations = 1000, $direction = +1) { |
|
|
function findNext($start, $frequency, $excludes = [], $maxIterations = 1000, $direction = +1) { |
|
|
|
|
|
$now = new \DateTime('now'); |
|
|
$current = clone $start; |
|
|
$current = clone $start; |
|
|
$frequency = \DateInterval::createFromDateString($frequency); |
|
|
$frequency = \DateInterval::createFromDateString($frequency); |
|
|
do { |
|
|
do { |
|
|
while ( |
|
|
|
|
|
($current->getTimestamp() < $now->getTimestamp()) |
|
|
|
|
|
and ($maxIterations-- > 0) |
|
|
|
|
|
) { |
|
|
|
|
|
if ($direction === abs($direction)) $current->add($frequency); |
|
|
|
|
|
else $current->sub($frequency); |
|
|
|
|
|
|
|
|
if ($direction === abs($direction)) { |
|
|
|
|
|
while ( |
|
|
|
|
|
($current->getTimestamp() < $now->getTimestamp()) |
|
|
|
|
|
and ($maxIterations-- > 0) |
|
|
|
|
|
) $current->add($frequency); |
|
|
|
|
|
} else { |
|
|
|
|
|
while ( |
|
|
|
|
|
($current->getTimestamp() > $now->getTimestamp()) |
|
|
|
|
|
and ($maxIterations-- > 0) |
|
|
|
|
|
) $current->sub($frequency); |
|
|
} |
|
|
} |
|
|
$nextEvent = $current->format('Y-m-d'); |
|
|
$nextEvent = $current->format('Y-m-d'); |
|
|
} while ( |
|
|
} while ( |
|
@ -162,7 +167,6 @@ if (!$isConfig and $hasSupplier) { |
|
|
$start = new \DateTime($config[$supplier]['start']); |
|
|
$start = new \DateTime($config[$supplier]['start']); |
|
|
if (!$hasEvent) { |
|
|
if (!$hasEvent) { |
|
|
|
|
|
|
|
|
$now = new \DateTime('now'); |
|
|
|
|
|
$next = findNext($start, $config[$supplier]['frequency'], $config[$supplier]['excludes']); |
|
|
$next = findNext($start, $config[$supplier]['frequency'], $config[$supplier]['excludes']); |
|
|
$nextEvent = $next->format('Y-m-d'); |
|
|
$nextEvent = $next->format('Y-m-d'); |
|
|
header('Location: ' . generateUrl($supplier, $nextEvent)); |
|
|
header('Location: ' . generateUrl($supplier, $nextEvent)); |
|
|