diff --git a/include/controllers/default/crunchbutton/api/TimeMachine/index.php b/include/controllers/default/crunchbutton/api/TimeMachine/index.php new file mode 100644 index 000000000..e7ae76b2b --- /dev/null +++ b/include/controllers/default/crunchbutton/api/TimeMachine/index.php @@ -0,0 +1,46 @@ + '$_GET[\'time\'] was not set']; + + $DeLorean = new TimeMachine($timezone); + $DeLorean->travel($_GET['time']); + $DeLorean->toBeContinued(); + + $return = ['time' => $DeLorean->now()]; + + return $return; + } + + public function reset() + { + $return = null; + $timezone = (isset($_GET['timezone'])) ? $_GET['timezone'] : 'America/New_York'; + + $DeLorean = new TimeMachine($timezone); + $DeLorean->backToThePresent(); + $DeLorean->toBeContinued(); + + $return = ['time' => $DeLorean->now()]; + + return $return; + } + + /** + * Calls the public methodds as actions + */ + public function init() { + $action = c::getPagePiece(2); + if (is_callable(array($this, $action)) && ($action[0] != '_')) { + $return = $this->$action(); + } else { + $return = ['error' => 'invalid request']; + } + echo json_encode($return); + } +} diff --git a/include/library/Crunchbutton/Restaurant.php b/include/library/Crunchbutton/Restaurant.php index bdbb75faf..bc06c89f6 100644 --- a/include/library/Crunchbutton/Restaurant.php +++ b/include/library/Crunchbutton/Restaurant.php @@ -400,22 +400,31 @@ class Crunchbutton_Restaurant extends Cana_Table return $this->_hours[$gmt]; } + /** + * Confirms a restaurant is open + * + * Uses TimeMachine to test if the restaurant is open forcing time travel + * + * @link /api/TimeMachine/set?time=12:30am + * @link /api/TimeMachine/reset + */ public function open() { if (c::env() != 'live' && ($this->id_restaurant == 1 || $this->id_restaurant == 18)) { - return true; + // return true; } $hours = $this->hours(); - $today = new DateTime('now', new DateTimeZone($this->timezone)); - $day = strtolower($today->format('D')); + $DeLorean = new TimeMachine($this->timezone); + $today = $DeLorean->now(); + $day = strtolower($today->format('D')); foreach ($hours as $hour) { if ($hour->day != $day) { continue; } - $open = new DateTime('today '.$hour->time_open, new DateTimeZone($this->timezone)); + $open = new DateTime('today '.$hour->time_open, new DateTimeZone($this->timezone)); $close = new DateTime('today '.$hour->time_close, new DateTimeZone($this->timezone)); // if closeTime before openTime, then closeTime should be for tomorrow diff --git a/include/library/TimeMachine.php b/include/library/TimeMachine.php new file mode 100644 index 000000000..526c90a94 --- /dev/null +++ b/include/library/TimeMachine.php @@ -0,0 +1,72 @@ + + * $DeLorean = new TimeMachine(); + * var_log($DeLorean.now()); + * $DeLorean->travel('November 5, 1955'); + * var_log(DeLorean->now()); + * + * + * It's not called Tardis as it doesn't travel in space. + */ +class TimeMachine +{ + private $_fixedTime = null; + private $timezone = null; + + /** + * If there is any time traveled stored, load it. + * + * @param string $timezone The timezone to use. + * + * @return void + * + * @link http://www.php.net/manual/en/timezones.php + */ + public function __construct($timezone) + { + if ($_SESSION['TimeMachine']) { + $this->_fixedTime = $_SESSION['TimeMachine']; + } + $this->_timezone = new DateTimeZone($timezone); + } + + /** + * Returns the date of when the time machine has landed + * + * @return Date + */ + public function now() + { + return ($this->_fixedTime) ? $this->_fixedTime : new DateTime(); + } + + /** + * Returns the time machine to the present + * + * @return void + */ + function backToThePresent() + { + $this->_fixedTime = null; + } + + function toBeContinued() + { + $_SESSION['TimeMachine'] = $this->_fixedTime; + } + + /** + * Sets the time machine to the specific time + * + * @param string $newTime When to travel to + * + * @return void + */ + function travel($newTime) + { + $this->_fixedTime = new DateTime($newTime, $this->_timezone); + } +} \ No newline at end of file diff --git a/include/views/default/crunchbutton/bundle/js.phtml b/include/views/default/crunchbutton/bundle/js.phtml index 61a57b1de..ccede0569 100644 --- a/include/views/default/crunchbutton/bundle/js.phtml +++ b/include/views/default/crunchbutton/bundle/js.phtml @@ -4,6 +4,7 @@ + \ No newline at end of file + diff --git a/include/views/default/crunchbutton/layout/html.bottom.phtml b/include/views/default/crunchbutton/layout/html.bottom.phtml index 1c54c3dc2..e1b8a48c6 100644 --- a/include/views/default/crunchbutton/layout/html.bottom.phtml +++ b/include/views/default/crunchbutton/layout/html.bottom.phtml @@ -1,3 +1,6 @@ + if ((Cana::env() != 'live' ) && (isset($this->restaurant)) && (!$this->restaurant->open()) ) :?> + + endif?> if ($this->community->id_community) { @@ -12,6 +15,7 @@ if (!c::getPagePiece(0) || (c::getPagePiece(0) && !in_array(c::getPagePiece(0), $basicPages) && !$this->community)) { $e = ' short-meal-list'; } + ?>