partial #1828
This commit is contained in:
parent
10026ec807
commit
0732ed7f45
@ -770,6 +770,60 @@ class Crunchbutton_Restaurant extends Cana_Table_Trackchange {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Return minutes left to close
|
||||
public function closeIn() {
|
||||
if( !$this->open() ){
|
||||
return false;
|
||||
}
|
||||
$hours = $this->hours();
|
||||
$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));
|
||||
$close = new DateTime('today '.$hour->time_close, new DateTimeZone($this->timezone));
|
||||
if ($close->getTimestamp() < $open->getTimestamp()) {
|
||||
$close = new DateTime('+1 day '.$hour->time_close, new DateTimeZone($this->timezone));
|
||||
}
|
||||
if ($today->getTimestamp() >= $open->getTimestamp() && $today->getTimestamp() <= $close->getTimestamp()) {
|
||||
$interval = $today->diff( $close );
|
||||
$minutes = $interval->days * 24 * 60;
|
||||
$minutes += $interval->h * 60;
|
||||
$minutes += $interval->i;
|
||||
return $minutes;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Return minutes left to open
|
||||
public function openIn() {
|
||||
if( $this->open() ){
|
||||
return false;
|
||||
}
|
||||
$hours = $this->hours();
|
||||
$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));
|
||||
if ($today->getTimestamp() < $open->getTimestamp()) {
|
||||
$interval = $today->diff( $open );
|
||||
$minutes = $interval->days * 24 * 60;
|
||||
$minutes += $interval->h * 60;
|
||||
$minutes += $interval->i;
|
||||
return $minutes;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the notifications linked to this restaurant
|
||||
*
|
||||
@ -961,7 +1015,22 @@ class Crunchbutton_Restaurant extends Cana_Table_Trackchange {
|
||||
|
||||
$out = $this->properties();
|
||||
$out['_open'] = $this->open();
|
||||
$out['_weight'] = $this->weight();
|
||||
$out['_closeIn'] = $this->closeIn();
|
||||
$out['_minimumTime'] = 15; // Min minutes to show the hurry message
|
||||
// $out['_openIn'] = $this->openIn();
|
||||
$out['_closeIn'] = $this->closeIn();
|
||||
|
||||
if( $out['_open'] ){
|
||||
if( $out[ 'delivery' ] != 1 ){
|
||||
$out['_tag'] = 'takeout';
|
||||
} else {
|
||||
if( $out['_closeIn'] <= $out['_minimumTime'] ){
|
||||
$out['_tag'] = 'closing';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$out['_tag'] = 'closed';
|
||||
}
|
||||
|
||||
$timezone = new DateTimeZone( $this->timezone );
|
||||
$date = new DateTime( 'now ', $timezone ) ;
|
||||
|
||||
@ -30,7 +30,7 @@
|
||||
<h3 class="meal-food">{{restaurant._short_description}}</h3>
|
||||
<div ng-switch on="restaurant._tag">
|
||||
<div class="meal-item-tag" ng-switch-when="takeout">Take out only</div>
|
||||
<div class="meal-item-tag about-to-close" ng-switch-when="closing">Hurry, closes in {{restaurant._minToClose}} min!</div>
|
||||
<div class="meal-item-tag about-to-close" ng-switch-when="closing">Hurry, closes in {{restaurant._closeIn}} min!</div>
|
||||
<div class="meal-item-tag-closed" ng-switch-when="closed">Opens in a few hours</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -133,7 +133,7 @@ NGApp.controller( 'RestaurantsCtrl', function ( $scope, $rootScope, $http, $loca
|
||||
// Update status of the restaurant's list
|
||||
$scope.restaurants = restaurants.getStatus();
|
||||
updateStatus();
|
||||
} , 1000 * 15 );
|
||||
} , 1000 * 35 );
|
||||
}
|
||||
|
||||
$scope.$on( '$destroy', function(){
|
||||
@ -203,7 +203,10 @@ NGApp.controller( 'RestaurantsCtrl', function ( $scope, $rootScope, $http, $loca
|
||||
|
||||
$scope.restaurants = restaurants.sort();
|
||||
App.profile.log('returned sorting');
|
||||
updateStatus();
|
||||
// Wait one minute until update the status of the restaurants
|
||||
setTimeout( function(){
|
||||
updateStatus();
|
||||
}, 1000 * 60 );
|
||||
$scope.slogan = slogan;
|
||||
$scope.tagline = tagline;
|
||||
|
||||
|
||||
@ -51,13 +51,12 @@ var Restaurant = function(id) {
|
||||
*
|
||||
* @return int|boolean
|
||||
*/
|
||||
this.isAboutToClose = function() {
|
||||
this.closeIn = function() {
|
||||
/**
|
||||
* How many minutes to closing time to trigger the notification
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var minimumTime = 15;
|
||||
var today = Date.today().toString('ddd').toLowerCase();
|
||||
var tomorrow = Date.today().add(1).days().toString('ddd').toLowerCase();
|
||||
|
||||
@ -124,7 +123,7 @@ var Restaurant = function(id) {
|
||||
|
||||
closeTime = this._utcTime(closeTime);
|
||||
|
||||
openTime = closeTime.clone().addMinutes(-1 * minimumTime);
|
||||
openTime = closeTime.clone().addMinutes(-1 * self._minimumTime);
|
||||
utcNow = this._utcNow();
|
||||
|
||||
if (utcNow.between(openTime, closeTime)) {
|
||||
@ -299,7 +298,7 @@ var Restaurant = function(id) {
|
||||
}
|
||||
|
||||
if( isOpen ){
|
||||
var minToClose = self.isAboutToClose();
|
||||
var minToClose = self.closeIn();
|
||||
if( !isNaN( parseFloat( minToClose ) ) && minToClose == 0 ){
|
||||
isOpen = false;
|
||||
}
|
||||
|
||||
@ -195,11 +195,15 @@ NGApp.factory('LocationService', function ($location, $rootScope, RestaurantsSer
|
||||
// 4) get a more specific bounding location result from google
|
||||
if (App.isPhoneGap) {
|
||||
// @todo: id like to use native gelocation if posible at some point
|
||||
} else if (google && google.load && !google.maps) {
|
||||
google.load('maps', '3', {
|
||||
callback: service.googleCallback,
|
||||
other_params: 'sensor=false'
|
||||
});
|
||||
} else {
|
||||
try{
|
||||
if( google && google.load && !google.maps ){
|
||||
google.load('maps', '3', {
|
||||
callback: service.googleCallback,
|
||||
other_params: 'sensor=false'
|
||||
});
|
||||
}
|
||||
} catch(e){}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -15,8 +15,15 @@ NGApp.factory('RestaurantsService', function ($http, $rootScope, PositionsServic
|
||||
service.position = PositionsService;
|
||||
|
||||
service.sort = function () {
|
||||
var list = service.getStatus();
|
||||
|
||||
App.profile.log('start sort');
|
||||
|
||||
var list = restaurants;
|
||||
|
||||
for (var x in list) {
|
||||
// show short description
|
||||
list[x]._short_description = (list[x].short_description || ('Top Order: ' + (list[x].top_name ? (list[x].top_name || list[x].top_name) : '')));
|
||||
};
|
||||
|
||||
list.sort(sort_by({
|
||||
name: '_open',
|
||||
@ -37,13 +44,14 @@ NGApp.factory('RestaurantsService', function ($http, $rootScope, PositionsServic
|
||||
}
|
||||
|
||||
service.getStatus = function () {
|
||||
|
||||
App.profile.log('start status');
|
||||
|
||||
var list = restaurants;
|
||||
|
||||
for (var x in list) {
|
||||
App.profile.log('start calc open');
|
||||
// recalculate restaurant open status on relist
|
||||
list[x].open();
|
||||
|
||||
App.profile.log('end calc open');
|
||||
|
||||
// determine which tags to display
|
||||
@ -52,9 +60,10 @@ NGApp.factory('RestaurantsService', function ($http, $rootScope, PositionsServic
|
||||
} else {
|
||||
if (list[x].delivery != '1') {
|
||||
list[x]._tag = 'takeout';
|
||||
} else if (list[x].isAboutToClose()) {
|
||||
list[x]._minToClose = list[x].isAboutToClose();
|
||||
list[x]._tag = 'closing';
|
||||
} else {
|
||||
if( list[x].closeIn() ){
|
||||
list[x]._tag = 'closing';
|
||||
}
|
||||
}
|
||||
}
|
||||
// show short description
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user