partial #678
This commit is contained in:
parent
49fea2825d
commit
77a746e566
@ -68,6 +68,15 @@ class Crunchbutton_Community extends Cana_Table {
|
|||||||
return self::q('select * from community where permalink="'.$permalink.'"')->get(0);
|
return self::q('select * from community where permalink="'.$permalink.'"')->get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function all_locations(){
|
||||||
|
$res = Cana::db()->query( 'SELECT c.id_community, c.loc_lat, c.loc_lon FROM community c' );
|
||||||
|
$locations = array();
|
||||||
|
while ( $row = $res->fetch() ) {
|
||||||
|
$locations[ $row->id_community ] = array( 'loc_lat' => $row->loc_lat, 'loc_lon' => $row->loc_lon );
|
||||||
|
}
|
||||||
|
return $locations;
|
||||||
|
}
|
||||||
|
|
||||||
public function __construct($id = null) {
|
public function __construct($id = null) {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this
|
$this
|
||||||
|
|||||||
@ -12,7 +12,7 @@ class Crunchbutton_Community_Alias extends Cana_Table {
|
|||||||
public static function alias( $alias ) {
|
public static function alias( $alias ) {
|
||||||
$query = sprintf("
|
$query = sprintf("
|
||||||
SELECT
|
SELECT
|
||||||
ca.alias, c.permalink
|
ca.alias, c.permalink, c.id_community, ca.prep, ca.name_alt, c.loc_lat, c.loc_lon
|
||||||
FROM
|
FROM
|
||||||
community_alias ca
|
community_alias ca
|
||||||
INNER JOIN
|
INNER JOIN
|
||||||
@ -21,24 +21,33 @@ class Crunchbutton_Community_Alias extends Cana_Table {
|
|||||||
mysql_real_escape_string( $alias ) );
|
mysql_real_escape_string( $alias ) );
|
||||||
$res = Cana::db()->query( $query );
|
$res = Cana::db()->query( $query );
|
||||||
while ( $row = $res->fetch() ) {
|
while ( $row = $res->fetch() ) {
|
||||||
return [ $row->alias => $row->permalink ];
|
return array( 'id_community' => $row->id_community, 'permalink' => $row->permalink, 'prep' => $row->prep, 'name_alt' => $row->name_alt, 'loc_lat' => $row->loc_lat, 'loc_lon' => $row->loc_lon );
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function all() {
|
public static function all( $just_fields = false ) {
|
||||||
$res = Cana::db()->query('
|
$res = Cana::db()->query('
|
||||||
SELECT
|
SELECT
|
||||||
ca.alias, c.permalink
|
ca.alias, c.permalink, c.id_community, ca.prep, ca.name_alt, c.loc_lat, c.loc_lon
|
||||||
FROM
|
FROM
|
||||||
community_alias ca
|
community_alias ca
|
||||||
INNER JOIN community c ON c.id_community = ca.id_community ');
|
INNER JOIN community c ON c.id_community = ca.id_community ');
|
||||||
$aliases = array();
|
$aliases = array();
|
||||||
while ($row = $res->fetch()) {
|
while ($row = $res->fetch()) {
|
||||||
$aliases[ $row->alias ] = $row->permalink;
|
$alias = array();
|
||||||
|
foreach( $row as $key => $value ){
|
||||||
|
if( !$just_fields ){
|
||||||
|
$alias[ $key ] = $value;
|
||||||
|
} else {
|
||||||
|
if( in_array( $key, $just_fields ) ){
|
||||||
|
$alias[ $key ] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$aliases[ $row->alias ] = $alias;
|
||||||
}
|
}
|
||||||
return $aliases;
|
return $aliases;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,8 @@ $(function() {
|
|||||||
<? if (!c::isBot()) : ?>
|
<? if (!c::isBot()) : ?>
|
||||||
$('.home-text').hide();
|
$('.home-text').hide();
|
||||||
<? endif ; ?>
|
<? endif ; ?>
|
||||||
App.aliases = <?php echo json_encode( Community_Alias::all() ); ?>;
|
App.aliases = <?php echo json_encode( Community_Alias::all( array( 'id_community', 'prep', 'name_alt' ) ) ); ?>;
|
||||||
|
App.locations = <?php echo json_encode( Community::all_locations() ); ?>;
|
||||||
App.communities = {};
|
App.communities = {};
|
||||||
<? foreach (Community::all(c::getPagePiece(0)) as $community) : ?>
|
<? foreach (Community::all(c::getPagePiece(0)) as $community) : ?>
|
||||||
App.communities['<?=$community->permalink?>'] = {
|
App.communities['<?=$community->permalink?>'] = {
|
||||||
|
|||||||
@ -72,42 +72,34 @@ App.loadRestaurant = function(id) {
|
|||||||
|
|
||||||
App.loadCommunity = function(id) {
|
App.loadCommunity = function(id) {
|
||||||
/* App.loadCommunity is deprecated */
|
/* App.loadCommunity is deprecated */
|
||||||
return App.routeCommunity( id );
|
return App.routeAlias( id );
|
||||||
};
|
};
|
||||||
|
|
||||||
App.routeCommunity = function(id) {
|
App.routeAlias = function(id) {
|
||||||
if (App.loadedPage == id) {
|
// Get the alias
|
||||||
App.community = App.cached['Community'][id];
|
alias = App.aliases[ id ] || false;
|
||||||
App.loadedPage = null;
|
if( alias ){
|
||||||
}
|
// Get the location of the alias
|
||||||
// If it doesn't find a community it'll try to find an alias.
|
var loc = App.locations[ alias.id_community ];
|
||||||
if( !App.communities[ id ] ){
|
if( loc.loc_lat && loc.loc_lon ){
|
||||||
alias = App.aliases[ id ] || false;
|
App.loc.lat = loc.loc_lat;
|
||||||
if( alias ){
|
App.loc.lon = loc.loc_lon;
|
||||||
id = alias;
|
App.loc.prep = alias.prep;
|
||||||
|
App.loc.name_alt = alias.name_alt;
|
||||||
|
$.cookie( 'location_prep', alias.prep, { expires: new Date(3000,01,01), path: '/'});
|
||||||
|
$.cookie( 'location_name_lat', alias.name_alt, { expires: new Date(3000,01,01), path: '/'});
|
||||||
|
$.cookie( 'location_lat', App.loc.lat, { expires: new Date(3000,01,01), path: '/'});
|
||||||
|
$.cookie( 'location_lon', App.loc.lon, { expires: new Date(3000,01,01), path: '/'});
|
||||||
|
var url = '/' + App.restaurants.permalink;
|
||||||
|
History.pushState( {}, 'Crunchbutton', url );
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Make sure that the community exists.
|
// If the alias doesn't exist show the home with the error location message.
|
||||||
if( App.communities[ id ] ){
|
App.forceHome = true;
|
||||||
App.cache('Community',id, function() {
|
App.showErrorLocation = true;
|
||||||
App.community = this;
|
App.loadHome();
|
||||||
var community = this;
|
return;
|
||||||
if( community.loc_lat && App.community.loc_lon ){
|
|
||||||
App.loc.lat = community.loc_lat;
|
|
||||||
App.loc.lon = community.loc_lon;
|
|
||||||
$.cookie('location_lat', App.loc.lat, { expires: new Date(3000,01,01), path: '/'});
|
|
||||||
$.cookie('location_lon', App.loc.lon, { expires: new Date(3000,01,01), path: '/'});
|
|
||||||
var loc = '/' + App.restaurants.permalink;
|
|
||||||
History.pushState({}, 'Crunchbutton', loc);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// If the community doesn't exist show the home with the error location message.
|
|
||||||
App.forceHome = true;
|
|
||||||
App.showErrorLocation = true;
|
|
||||||
App.loadHome();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
App.loadHome = function() {
|
App.loadHome = function() {
|
||||||
@ -232,80 +224,18 @@ App.page.home = function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
App.page.community = function(id) {
|
|
||||||
|
|
||||||
App.lastCommunity = id;
|
|
||||||
App.currentPage = 'community';
|
|
||||||
|
|
||||||
$( '.config-icon' ).removeClass( 'config-icon-mobile-hide' );
|
|
||||||
|
|
||||||
App.cache('Community', id, function() {
|
|
||||||
App.community = this;
|
|
||||||
|
|
||||||
App.track('Community page loaded', {community: App.community.name});
|
|
||||||
|
|
||||||
document.title = App.community.name + ' Food Delivery | Order Food from ' + (App.community.name_alt ? App.community.name_alt : 'Local') + ' Restaurants | Crunchbutton';
|
|
||||||
|
|
||||||
var slogan = App.slogans[Math.floor(Math.random()*App.slogans.length)];
|
|
||||||
var sloganReplace = App.community.prep + ' ' + App.community.name;
|
|
||||||
var tagline = App.tagline.replace('%s', sloganReplace);
|
|
||||||
slogan = slogan.replace('%s', sloganReplace);
|
|
||||||
|
|
||||||
$('.main-content').html(
|
|
||||||
'<div class="home-tagline"><h1>' + slogan + '</h1><h2>' + tagline + '</h2></div>' +
|
|
||||||
'<div class="content-padder-before"></div><div class="content-padder"><div class="meal-items"></div></div>'
|
|
||||||
);
|
|
||||||
|
|
||||||
var rs = this.restaurants();
|
|
||||||
|
|
||||||
if (rs.length == 4) {
|
|
||||||
$('.content').addClass('short-meal-list');
|
|
||||||
} else {
|
|
||||||
$('.content').removeClass('short-meal-list');
|
|
||||||
}
|
|
||||||
$('.content').removeClass('smaller-width');
|
|
||||||
|
|
||||||
for (var x in rs) {
|
|
||||||
var restaurant = $('<div class="meal-item'+ (!rs[x].open() ? ' meal-item-closed' : '') +'" data-id_restaurant="' + rs[x]['id_restaurant'] + '" data-permalink="' + rs[x]['permalink'] + '"></div>');
|
|
||||||
var restaurantContent = $('<div class="meal-item-content">');
|
|
||||||
|
|
||||||
restaurantContent
|
|
||||||
.append('<div class="meal-pic" style="background: url(' + rs[x]['img64'] + ');"></div>')
|
|
||||||
.append('<h2 class="meal-restaurant">' + rs[x]['name'] + '</h2>')
|
|
||||||
.append('<h3 class="meal-food">' + (rs[x].short_description || ('Top Order: ' + (rs[x].top() ? (rs[x].top().top_name || rs[x].top().name) : ''))) + '</h3>');
|
|
||||||
|
|
||||||
if (rs[x].open()) {
|
|
||||||
if (rs[x].delivery != '1') {
|
|
||||||
restaurantContent.append('<div class="meal-item-tag">Take out only</div>');
|
|
||||||
} else if (rs[x].isAboutToClose()) {
|
|
||||||
restaurantContent.append('<div class="meal-item-tag about-to-close">Hurry, closes in ' + rs[x].isAboutToClose() +' min!</div>');
|
|
||||||
} else if (!rs[x].delivery_fee) {
|
|
||||||
// restaurantContent.append('<div class="meal-item-tag">Free Delivery</div>');
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
restaurantContent.append('<div class="meal-item-tag-closed">Opens in a few hours</div>');
|
|
||||||
}
|
|
||||||
|
|
||||||
restaurant
|
|
||||||
.append('<div class="meal-item-spacer"></div>')
|
|
||||||
.append(restaurantContent);
|
|
||||||
|
|
||||||
$('.meal-items').append(restaurant);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
App.page.foodDelivery = function() {
|
App.page.foodDelivery = function() {
|
||||||
|
|
||||||
App.currentPage = 'food-delivery';
|
App.currentPage = 'food-delivery';
|
||||||
App.loc.lat = ( App.loc.lat && App.loc.lat != 0 ) ? App.loc.lat : parseFloat( $.cookie( 'location_lat' ) );
|
App.loc.lat = ( App.loc.lat && App.loc.lat != 0 ) ? App.loc.lat : parseFloat( $.cookie( 'location_lat' ) );
|
||||||
App.loc.lon = ( App.loc.lon && App.loc.lon != 0 ) ? App.loc.lon : parseFloat( $.cookie( 'location_lon' ) );
|
App.loc.lon = ( App.loc.lon && App.loc.lon != 0 ) ? App.loc.lon : parseFloat( $.cookie( 'location_lon' ) );
|
||||||
|
App.loc.prep = ( App.loc.prep && App.loc.prep != '' ) ? App.loc.prep : $.cookie( 'location_prep' );
|
||||||
|
App.loc.name_alt = ( App.loc.name_alt && App.loc.name_alt != '' ) ? App.loc.name_alt : $.cookie( 'location_name_lat' );
|
||||||
|
|
||||||
$( '.config-icon' ).removeClass( 'config-icon-mobile-hide' );
|
$( '.config-icon' ).removeClass( 'config-icon-mobile-hide' );
|
||||||
|
|
||||||
// Go home you don't have lat neither lon
|
// Go home you don't have lat neither lon
|
||||||
if( !App.loc.lat || !App.loc.lon ){
|
if( !App.loc.lat || !App.loc.lon || !App.loc.prep || !App.loc.name_alt ){
|
||||||
App.forceHome = true;
|
App.forceHome = true;
|
||||||
App.loadHome();
|
App.loadHome();
|
||||||
$('input').blur();
|
$('input').blur();
|
||||||
@ -315,7 +245,7 @@ App.page.foodDelivery = function() {
|
|||||||
document.title = 'Food Delivery | Order Food from Local Restaurants | Crunchbutton';
|
document.title = 'Food Delivery | Order Food from Local Restaurants | Crunchbutton';
|
||||||
|
|
||||||
var slogan = App.slogans[Math.floor(Math.random()*App.slogans.length)];
|
var slogan = App.slogans[Math.floor(Math.random()*App.slogans.length)];
|
||||||
var sloganReplace = '[some slogan here]';
|
var sloganReplace = App.loc.prep + ' ' + App.loc.name_alt;
|
||||||
var tagline = App.tagline.replace('%s', sloganReplace);
|
var tagline = App.tagline.replace('%s', sloganReplace);
|
||||||
slogan = slogan.replace('%s', sloganReplace);
|
slogan = slogan.replace('%s', sloganReplace);
|
||||||
|
|
||||||
@ -389,6 +319,8 @@ App.page.restaurant = function(id) {
|
|||||||
|
|
||||||
App.restaurant = this;
|
App.restaurant = this;
|
||||||
|
|
||||||
|
App.community = App.getCommunityById( App.restaurant.id_community );
|
||||||
|
|
||||||
App.track('Restaurant page loaded', {restaurant: App.restaurant.name});
|
App.track('Restaurant page loaded', {restaurant: App.restaurant.name});
|
||||||
document.title = App.restaurant.name + ' | Food Delivery | Order from Local Restaurants | Crunchbutton';
|
document.title = App.restaurant.name + ' | Food Delivery | Order from Local Restaurants | Crunchbutton';
|
||||||
|
|
||||||
@ -838,6 +770,7 @@ App.loadPage = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var restaurantRegex = new RegExp('^\/(restaurant)|(' + App.restaurants.permalink + ')/', 'i');
|
var restaurantRegex = new RegExp('^\/(restaurant)|(' + App.restaurants.permalink + ')/', 'i');
|
||||||
|
var cleaned_url = $.trim( url.replace( '/', '' ) );
|
||||||
|
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case /^legal/i.test(url):
|
case /^legal/i.test(url):
|
||||||
@ -855,14 +788,14 @@ App.loadPage = function() {
|
|||||||
case /^reset/i.test(url):
|
case /^reset/i.test(url):
|
||||||
App.page.resetPassword( path );
|
App.page.resetPassword( path );
|
||||||
break;
|
break;
|
||||||
|
case new RegExp( App.restaurants.permalink + '$', 'i' ).test( cleaned_url ):
|
||||||
|
App.page.foodDelivery();
|
||||||
|
break;
|
||||||
case restaurantRegex.test(url):
|
case restaurantRegex.test(url):
|
||||||
App.page.restaurant(path[1]);
|
App.page.restaurant(path[1]);
|
||||||
break;
|
break;
|
||||||
case new RegExp( App.restaurants.permalink + '$', 'i' ).test(url):
|
|
||||||
App.page.foodDelivery();
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
App.routeCommunity( path[ 0 ] );
|
App.routeAlias( path[ 0 ] );
|
||||||
$('.nav-back').removeClass('nav-back-show');
|
$('.nav-back').removeClass('nav-back-show');
|
||||||
$('.footer').removeClass('footer-hide');
|
$('.footer').removeClass('footer-hide');
|
||||||
setTimeout(scrollTo, 80, 0, 1);
|
setTimeout(scrollTo, 80, 0, 1);
|
||||||
@ -1755,8 +1688,6 @@ App.loc = {
|
|||||||
App.loc.reverseGeocodeCity = results[0].address_components[2].long_name + ', ' + results[0].address_components[4].short_name;
|
App.loc.reverseGeocodeCity = results[0].address_components[2].long_name + ', ' + results[0].address_components[4].short_name;
|
||||||
break;
|
break;
|
||||||
case 'postal_code':
|
case 'postal_code':
|
||||||
App.loc.reverseGeocodeCity = results[0].address_components[1].long_name + ', ' + results[0].address_components[3].short_name;
|
|
||||||
break;
|
|
||||||
case 'route':
|
case 'route':
|
||||||
App.loc.reverseGeocodeCity = results[0].address_components[1].long_name + ', ' + results[0].address_components[3].short_name;
|
App.loc.reverseGeocodeCity = results[0].address_components[1].long_name + ', ' + results[0].address_components[3].short_name;
|
||||||
break;
|
break;
|
||||||
@ -1829,9 +1760,8 @@ App.loc = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Check if the typed address has an alias
|
// Check if the typed address has an alias
|
||||||
var permalink = App.aliases[ address ] || false;
|
if( App.aliases[ address ] ){
|
||||||
if( permalink ){
|
return App.routeAlias( address );
|
||||||
return App.routeCommunity( permalink );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
geocoder.geocode({'address': $('.location-address').val()}, function(results, status) {
|
geocoder.geocode({'address': $('.location-address').val()}, function(results, status) {
|
||||||
@ -1931,7 +1861,6 @@ $(function() {
|
|||||||
|
|
||||||
var complete = function() {
|
var complete = function() {
|
||||||
var closest = App.loc.getClosest();
|
var closest = App.loc.getClosest();
|
||||||
|
|
||||||
if (closest) {
|
if (closest) {
|
||||||
if (closest.distance < 25) {
|
if (closest.distance < 25) {
|
||||||
App.community = closest;
|
App.community = closest;
|
||||||
@ -2072,7 +2001,7 @@ $(function() {
|
|||||||
App.loadRestaurant(r);
|
App.loadRestaurant(r);
|
||||||
} else if (c) {
|
} else if (c) {
|
||||||
History.pushState({},c,c);
|
History.pushState({},c,c);
|
||||||
App.routeCommunity(c);
|
App.routeAlias(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$(this).removeClass('meal-item-down');
|
$(this).removeClass('meal-item-down');
|
||||||
@ -3118,4 +3047,13 @@ App.modal.contentWidth = function(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
App.getCommunityById = function( id ){
|
||||||
|
for (x in App.communities) {
|
||||||
|
if( App.communities[x].id_community == id ){
|
||||||
|
return App.communities[x];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
google.load('maps', '3', {callback: App.loc.preProcess, other_params: 'sensor=false'});
|
google.load('maps', '3', {callback: App.loc.preProcess, other_params: 'sensor=false'});
|
||||||
Loading…
x
Reference in New Issue
Block a user