parent
655d01ba74
commit
a0f3e5485c
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
class Controller_api_TimeMachine extends Crunchbutton_Controller_Rest
|
||||
{
|
||||
public function set()
|
||||
{
|
||||
$return = null;
|
||||
$timezone = (isset($_GET['timezone'])) ? $_GET['timezone'] : 'America/New_York';
|
||||
if (!isset($_GET['time'])) $return = ['error' => '$_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);
|
||||
}
|
||||
}
|
||||
@ -400,14 +400,23 @@ 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));
|
||||
$DeLorean = new TimeMachine($this->timezone);
|
||||
$today = $DeLorean->now();
|
||||
$day = strtolower($today->format('D'));
|
||||
|
||||
foreach ($hours as $hour) {
|
||||
|
||||
72
include/library/TimeMachine.php
Normal file
72
include/library/TimeMachine.php
Normal file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
* Time traveling machine
|
||||
*
|
||||
* <example>
|
||||
* $DeLorean = new TimeMachine();
|
||||
* var_log($DeLorean.now());
|
||||
* $DeLorean->travel('November 5, 1955');
|
||||
* var_log(DeLorean->now());
|
||||
* </example>
|
||||
*
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
@ -4,6 +4,7 @@
|
||||
<script src="/assets/js/jquery.history.js"></script>
|
||||
<script src="/assets/js/jquery.cookie.js"></script>
|
||||
<script src="/assets/js/date.js"></script>
|
||||
<script src="/assets/js/TimeMachine.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(function() {
|
||||
|
||||
@ -1,3 +1,6 @@
|
||||
<? if ((Cana::env() != 'live' ) && (isset($this->restaurant)) && (!$this->restaurant->open()) ) :?>
|
||||
<style> .wrapper { background: lightgray;} </style>
|
||||
<? endif?>
|
||||
</head>
|
||||
<?
|
||||
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';
|
||||
}
|
||||
|
||||
?>
|
||||
<body>
|
||||
<div class="wrapper">
|
||||
|
||||
71
www/assets/js/TimeMachine.js
Normal file
71
www/assets/js/TimeMachine.js
Normal file
@ -0,0 +1,71 @@
|
||||
/**
|
||||
* Time traveling machine
|
||||
*
|
||||
* <example>
|
||||
* var DeLorean = new TimeMachine();
|
||||
* console.log(DeLorean.now());
|
||||
* DeLorean.travel('November 5, 1955');
|
||||
* console.log(DeLorean.now());
|
||||
* </example>
|
||||
*
|
||||
* It's not called Tardis as it doesn't travel in space.
|
||||
*
|
||||
* @returns {TimeMachine}
|
||||
*/
|
||||
function TimeMachine() {
|
||||
'use strict';
|
||||
var _fixedTime = null;
|
||||
|
||||
/**
|
||||
* If there is any time traveled stored, load it.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
this.__construct = function()
|
||||
{
|
||||
if ($.cookie('TimeMachine')) {
|
||||
_fixedTime = $.cookie('TimeMachine');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the date of when the time machine has landed
|
||||
*
|
||||
* @return Date
|
||||
*/
|
||||
this.now = function()
|
||||
{
|
||||
'use strict';
|
||||
return (_fixedTime) ? _fixedTime : Date.now();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the time machine to the present
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
this.returnToPresent = function()
|
||||
{
|
||||
'use strict';
|
||||
_fixedTime = false;
|
||||
}
|
||||
|
||||
this.toBeContinued = function()
|
||||
{
|
||||
$.cookie('TimeMachine', _fixedTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the time machine to the specific time
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
this.travel = function(newTime)
|
||||
{
|
||||
'use strict';
|
||||
_fixedTime = Date.parse(newTime);
|
||||
}
|
||||
|
||||
this.__construct();
|
||||
}
|
||||
var DeLorean = new TimeMachine();
|
||||
Loading…
x
Reference in New Issue
Block a user