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,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
|
||||
|
||||
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() {
|
||||
@ -65,4 +66,4 @@ mixpanel.init("6eb260b54eecfd293d50b5f1423c6e98");</script>
|
||||
|
||||
<script type="application/x-javascript">
|
||||
addEventListener('touchstart',function(){}); addEventListener('load', function(event) {setTimeout(scrollTo, 80, 0, 1);}, false);
|
||||
</script>
|
||||
</script>
|
||||
|
||||
@ -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">
|
||||
@ -67,30 +71,30 @@ window.fbAsyncInit = function() {
|
||||
xfbml: true,
|
||||
oauth: true
|
||||
});
|
||||
FB.getLoginStatus( App.signin.facebook.processStatus );
|
||||
FB.getLoginStatus( App.signin.facebook.processStatus );
|
||||
FB.Event.subscribe('auth.statusChange', App.signin.facebook.processStatus );
|
||||
};
|
||||
});
|
||||
(function(d, s, id) {
|
||||
var js, fjs = d.getElementsByTagName(s)[0];
|
||||
if (d.getElementById(id)) return;
|
||||
js = d.createElement(s); js.id = id;
|
||||
js.src = "//connect.facebook.net/en_US/all.js";
|
||||
fjs.parentNode.insertBefore(js, fjs);
|
||||
var js, fjs = d.getElementsByTagName(s)[0];
|
||||
if (d.getElementById(id)) return;
|
||||
js = d.createElement(s); js.id = id;
|
||||
js.src = "//connect.facebook.net/en_US/all.js";
|
||||
fjs.parentNode.insertBefore(js, fjs);
|
||||
}(document, 'script', 'facebook-jssdk'));
|
||||
</script>
|
||||
<? if ($_SERVER['__HTTP_HOST'] == 'crunchbutton.com') : ?>
|
||||
<script type="text/javascript">
|
||||
var _gaq = _gaq || [];
|
||||
_gaq.push(['_setAccount', 'UA-36135548-1']);
|
||||
_gaq.push(['_setDomainName', 'crunchbutton.com']);
|
||||
_gaq.push(['_setAllowLinker', true]);
|
||||
_gaq.push(['_trackPageview']);
|
||||
(function() {
|
||||
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
||||
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
||||
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
||||
})();
|
||||
var _gaq = _gaq || [];
|
||||
_gaq.push(['_setAccount', 'UA-36135548-1']);
|
||||
_gaq.push(['_setDomainName', 'crunchbutton.com']);
|
||||
_gaq.push(['_setAllowLinker', true]);
|
||||
_gaq.push(['_trackPageview']);
|
||||
(function() {
|
||||
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
||||
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
||||
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
||||
})();
|
||||
</script>
|
||||
<? endif ; ?>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
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