Skip to content
Snippets Groups Projects
Commit 8580192d authored by dpi's avatar dpi
Browse files

Added ability for occurrences to specify how they interact with regular hours.

parent 38154e7c
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,16 @@ class OhOccurrence extends OhDateRange implements RefinableCacheableDependencyIn
use RefinableCacheableDependencyTrait;
/**
* Informs regular hours for the same day should be voided.
*/
public const REGULAR_HOUR_INTERACTION_VOID_REGULAR = 0b1;
/**
* Informs this occurrence will not trigger regular hours to be voided.
*/
public const REGULAR_HOUR_INTERACTION_NO_VOID_REGULAR = 0b0;
/**
* Message to add to the occurrence.
*
......@@ -26,6 +36,13 @@ class OhOccurrence extends OhDateRange implements RefinableCacheableDependencyIn
*/
protected $open = FALSE;
/**
* Regular hours interaction behaviour.
*
* @var int
*/
protected $regularHourInteraction = self::REGULAR_HOUR_INTERACTION_NO_VOID_REGULAR;
/**
* Add a message for the occurrence.
*
......@@ -88,6 +105,32 @@ class OhOccurrence extends OhDateRange implements RefinableCacheableDependencyIn
return $this->open;
}
/**
* Sets interaction behaviour with regular hours.
*
* Note: it only takes one exception to trigger voiding.
*
* @param int $value
* Interaction constant. See static::REGULAR_HOUR_INTERACTION_*.
*
* @return $this
* Return object for chaining.
*/
public function setRegularHourInteraction(int $value = self::REGULAR_HOUR_INTERACTION_NO_VOID_REGULAR) {
$this->regularHourInteraction = $value;
return $this;
}
/**
* Get interaction behaviour with regular hours.
*
* This method should only be used by exceptions, not regular hours.
*
* @return mixed
* Interaction constant. See static::REGULAR_HOUR_INTERACTION_*.
*/
public function getRegularHourInteraction(): int {
return $this->regularHourInteraction;
}
/**
......
......@@ -54,6 +54,9 @@ class OhOpeningHours implements OhOpeningHoursInterface {
if ($exceptions) {
foreach ($exceptions as $exception) {
$dayKey = $exception->getStart()->format(static::DAY_FORMAT);
if (!$exception->getRegularHourInteraction() & OhOccurrence::REGULAR_HOUR_INTERACTION_VOID_REGULAR) {
continue;
}
// Remove any regular hour occurrences on the same day as exceptions.
$occurrences = array_filter($occurrences, function (OhOccurrence $occurrence) use ($dayKey) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment