diff --git a/index.php b/index.php index b73fafa..b2b3148 100644 --- a/index.php +++ b/index.php @@ -13,7 +13,9 @@ require __DIR__ . '/src/functions.php'; $dotenv = \Dotenv\Dotenv::create(__DIR__ . '/src'); $dotenv->load(); $dotenv->required([ - 'EVENT_TICKET_PRICE', + 'EVENT_TICKET_PRICE_1', + 'EVENT_TICKET_PRICE_2', + 'EVENT_TICKET_PRICE_3', 'ENHANCER_TICKET_PRICE', 'CHILDCARE_PRICE', 'CABANA_PRICE', @@ -39,6 +41,9 @@ $router->set404(function () { echo '404, route not found!'; }); +// Get event pricing based on dates +list($_SERVER['EVENT_TICKET_PRICE'], $_SERVER['TABLE_TICKET_PRICE']) = getEventPricing(new DateTime('now', new DateTimeZone('America/Chicago'))); + $router->before('GET|POST', '/admin/.*', function() { session_start(); diff --git a/src/.env.example b/src/.env.example index 5287d60..c452ca6 100644 --- a/src/.env.example +++ b/src/.env.example @@ -1,5 +1,9 @@ -EVENT_TICKET_PRICE="55" -TABLE_TICKET_PRICE="350" +EVENT_TICKET_PRICE_1="55" +TABLE_TICKET_PRICE_1="350" +EVENT_TICKET_PRICE_2="65" +TABLE_TICKET_PRICE_2="450" +EVENT_TICKET_PRICE_3="75" +TABLE_TICKET_PRICE_3="500" ENHANCER_TICKET_PRICE="20" CHILDCARE_PRICE="25" CABANA_PRICE="250" diff --git a/src/functions.php b/src/functions.php index 9789688..ff14e6a 100644 --- a/src/functions.php +++ b/src/functions.php @@ -21,6 +21,47 @@ function getInteger($variable, $postiveOnly = true) return $variable; } +/** + * Calculate Event Pricing based on date + * + * @param DateTime $date + * @return array + * @throws Exception + */ +function getEventPricing($date = null) +{ + $priceIncrease1 = new DateTime('4/1/2019', new DateTimeZone('America/Chicago')); + $priceIncrease2 = new DateTime('5/1/2019', new DateTimeZone('America/Chicago')); + + if (empty($date)) { + return [ + $_SERVER['EVENT_TICKET_PRICE_1'], + $_SERVER['TABLE_TICKET_PRICE_1'], + ]; + } + + $interval = $date->diff($priceIncrease1); + if ($interval->invert !== 0) { + return [ + $_SERVER['EVENT_TICKET_PRICE_2'], + $_SERVER['TABLE_TICKET_PRICE_2'], + ]; + } + + $interval = $date->diff($priceIncrease2); + if ($interval->invert !== 0) { + return [ + $_SERVER['EVENT_TICKET_PRICE_3'], + $_SERVER['TABLE_TICKET_PRICE_3'], + ]; + }else { + return [ + $_SERVER['EVENT_TICKET_PRICE_1'], + $_SERVER['TABLE_TICKET_PRICE_1'], + ]; + } +} + /** * Converts possible float or string to cents * @@ -69,9 +110,9 @@ function eventPricing($qty) // If pricing is 8 or more then we need to factor in table reservations if ($qty > 7) { - $tableQty = (int) ($qty / 8); + $tableQty = (int)($qty / 8); $eventQty = $qty - ($tableQty * 8); - }else { + } else { $eventQty = $qty; } @@ -86,13 +127,14 @@ function shoppingCartTotal($price) '; } -function checkIfTicketsAreOnSale() { +function checkIfTicketsAreOnSale() +{ $todaysDate = new DateTime('now', new DateTimeZone('America/Chicago')); $dateOnSale = new DateTime('3/15/2019 8:00am', new DateTimeZone('America/Chicago')); $interval = $todaysDate->diff($dateOnSale); - if($interval->days >= 0 && $interval->invert === 0) { - header('Location: /notify?d='.$dateOnSale->format('c')); + if ($interval->days >= 0 && $interval->invert === 0) { + header('Location: /notify?d=' . $dateOnSale->format('c')); } } \ No newline at end of file diff --git a/views/family.php b/views/family.php index 35716d7..ee37a2a 100644 --- a/views/family.php +++ b/views/family.php @@ -1,15 +1,31 @@