Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit dc01720

Browse files
committed
ENH: refs #0339. Place markers in correct location on download map
1 parent cd48cb1 commit dc01720

File tree

2 files changed

+39
-26
lines changed

2 files changed

+39
-26
lines changed
Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,58 @@
11
<?php
22

3+
/** Controller for statistics about an item */
34
class Statistics_ItemController extends Statistics_AppController
4-
{
5-
public $_moduleModels=array('Download');
6-
public $_models=array('Item');
5+
{
6+
public $_moduleModels = array('Download');
7+
public $_models = array('Item');
78
public $_components = array('Utility');
9+
810
/** index action*/
911
function indexAction()
1012
{
11-
if(!$this->logged||!$this->userSession->Dao->getAdmin()==1)
12-
{
13-
throw new Zend_Exception("You should be an administrator");
14-
}
15-
13+
1614
$item = $this->Item->load($_GET['id']);
1715
if(!$item)
1816
{
1917
throw new Zend_Exception("Item doesn't exist");
2018
}
21-
22-
$downloads = $this->Statistics_Download->getDownloads($item, date( 'c', strtotime ('-20 day'.date( 'Y-m-j G:i:s'))), date('c'));
19+
if(!$this->Item->policyCheck($item, $this->userSession->Dao, MIDAS_POLICY_READ))
20+
{
21+
throw new Zend_Exception('You do not have read permission on this item');
22+
}
23+
24+
//TODO instead of last 21 days, have that number be an adjustable parameter to the controller
25+
$downloads = $this->Statistics_Download->getDownloads($item, date('c', strtotime('-20 day'.date( 'Y-m-j G:i:s'))), date('c'));
26+
2327
$arrayDownload = array();
24-
$format = 'Y-m-j';
25-
for($i = 0; $i<21; $i++)
28+
$format = 'Y-m-j';
29+
$markers = array();
30+
for($i = 0; $i < 21; $i++)
2631
{
27-
$key = date($format, strtotime(date( 'c', strtotime ('-'.$i.' day'.date( 'Y-m-j G:i:s')))));
32+
$key = date($format, strtotime(date('c', strtotime('-'.$i.' day'.date( 'Y-m-j G:i:s')))));
2833
$arrayDownload[$key] = 0;
2934
}
3035
foreach($downloads as $download)
3136
{
32-
$key = date($format, strtotime($download->getDate()));
37+
$key = date($format, strtotime($download->getDate()));
3338
$arrayDownload[$key]++;
39+
$latitude = $download->getLatitude();
40+
$longitude = $download->getLongitude();
41+
42+
if($latitude || $longitude)
43+
{
44+
$markers[] = array($latitude, $longitude);
45+
}
3446
}
35-
47+
3648
$jqplotArray = array();
3749
foreach($arrayDownload as $key => $value)
3850
{
3951
$jqplotArray[] = array($key.' 8:00AM', $value);
4052
}
4153
$this->view->json['stats']['downloads'] = $jqplotArray;
54+
$this->view->markers = $markers;
4255
$this->view->itemDao = $item;
43-
}
44-
45-
}//end class
56+
}
57+
58+
}//end class

modules/statistics/views/item/index.phtml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ $this->headScript()->appendFile($this->moduleWebroot.'/public/js/jqplot/jqplot.p
3434
</div>
3535
<h3>Statistics - <?php echo $this->itemDao->getName()?></h3>
3636

37-
<img class="tabsLoading" alt="" src="<?php echo $this->coreWebroot?>/public/images/icons/loading.gif" />
37+
<img class="tabsLoading" alt="" src="<?php echo $this->coreWebroot?>/public/images/icons/loading.gif" />
3838
<div class="tabs" id='tabsGeneric'>
3939
<ul>
4040
<li><a href="#tabs-map">Download Map</a></li>
@@ -52,13 +52,13 @@ $this->headScript()->appendFile($this->moduleWebroot.'/public/js/jqplot/jqplot.p
5252
<script type="text/javascript">
5353
function placeDownloadPins(theMap)
5454
{
55-
var myLatlng = new google.maps.LatLng(35, -100.044922);
56-
57-
var marker = new google.maps.Marker({
58-
position: myLatlng,
59-
map: theMap,
60-
title:"Hello World!!"
61-
});
55+
<?php
56+
foreach($this->markers as $marker)
57+
{
58+
echo 'var myLatlng = new google.maps.LatLng('.$marker['latitude'].', '.$marker['longitude'].');';
59+
echo 'new google.maps.Marker({ position: myLatlng, map: theMap, title: "'.$marker['date'].'"});';
60+
}
61+
?>
6262
}
6363
</script>
6464
<!-- END -->

0 commit comments

Comments
 (0)