Skip to content

Instantly share code, notes, and snippets.

@joshtronic
Created September 5, 2012 19:17
Show Gist options
  • Save joshtronic/3642896 to your computer and use it in GitHub Desktop.
Save joshtronic/3642896 to your computer and use it in GitHub Desktop.
<?php
if ($module_data['buyers'])
{
?>
<h4>Customer Map</h4>
<div id="map_canvas" style="width:310px;height:310px"></div><br />
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=true&amp;key=<?=$config->google['maps'];?>" type="text/javascript"></script>
<?=Utility::dynamicJavascript('gmaps/markermanager');?>
<?=Utility::dynamicJavascript('clusterer/Clusterer2');?>
<script type="text/javascript">
var map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(<?=City::getCurrent('latitude');?>, <?=City::getCurrent('longitude');?>), 9);
map.disableScrollWheelZoom();
map.disableDoubleClickZoom();
map.disableDragging();
var clusterer = new Clusterer(map);
clusterer.SetMaxVisibleMarkers(9999);
var customerIcon = new GIcon(G_DEFAULT_ICON);
customerIcon.iconSize = new GSize(32, 32);
customerIcon.image = 'http://maps.google.com/mapfiles/ms/icons/blue-dot.png';
<?php
if (is_array($module_data['buyers']))
{
$top_five_zips = array();
$total_sold = 0;
foreach ($module_data['buyers'] as $buyer)
{
?>
var point = new GLatLng(<?=$buyer['latitude'];?>, <?=$buyer['longitude'];?>);
var marker = new GMarker(point, { icon:customerIcon });
clusterer.AddMarker(marker);
<?php
$testing[] = $buyer['zip'];
if(isset($top_five_zips[$buyer['zip']]))
{
$top_five_zips[$buyer['zip']] += 1;
}
else
{
$top_five_zips[$buyer['zip']] = 1;
}
$total_sold++;
}
arsort($top_five_zips);
}
?>
</script>
<?php
}
if (isset($top_five_zips) && count($top_five_zips) > 0)
{
echo '<h4>Top 5 Buyer Zip Codes</h4>';
echo '<table class="table" style="width:98%">';
echo '<tr style="font-size:18px">';
echo '<th style="text-align:center" colspan="2">Zip Code</th>';
echo '<th style="text-align:center" colspan="2">% Purchased</th>';
echo '</tr>';
for ($i=0; $i < 5; $i++)
{
echo '<tr style="font-size:18px">';
if ($i == 0)
{
$calc_percentage_bought = current($top_five_zips) > 0 ? (current($top_five_zips) / $total_sold) * 100 : 0;
echo "<td style='text-align:center' colspan='2'>".key($top_five_zips)."</td><td style='text-align:center' colspan='2'>".number_format($calc_percentage_bought, 2)."%</td>";
}
else
{
// Strict check for boolean false to verify we aren't at the end of the array
// Used for deals that didn't have enough buyers to have five zip codes to list
if (next($top_five_zips) !== false)
{
$calc_percentage_bought = current($top_five_zips) > 0 ? (current($top_five_zips) / $total_sold) * 100 : 0;
echo "<td style='text-align:center' colspan='2'>".key($top_five_zips)."</td><td style='text-align:center' colspan='2'>".number_format($calc_percentage_bought, 2)."%</td>";
}
else
{
echo "<td style='text-align:center' colspan='2'>N/A</td><td style='text-align:center' colspan='2'>N/A</td>";
}
}
echo "</tr>";
}
echo "</table>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment