1
1
<?php
2
2
3
+ /** Controller for statistics about an item */
3
4
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 ' );
7
8
public $ _components = array ('Utility ' );
9
+
8
10
/** index action*/
9
11
function indexAction ()
10
12
{
11
- if (!$ this ->logged ||!$ this ->userSession ->Dao ->getAdmin ()==1 )
12
- {
13
- throw new Zend_Exception ("You should be an administrator " );
14
- }
15
-
13
+
16
14
$ item = $ this ->Item ->load ($ _GET ['id ' ]);
17
15
if (!$ item )
18
16
{
19
17
throw new Zend_Exception ("Item doesn't exist " );
20
18
}
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
+
23
27
$ 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 ++)
26
31
{
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 ' )))));
28
33
$ arrayDownload [$ key ] = 0 ;
29
34
}
30
35
foreach ($ downloads as $ download )
31
36
{
32
- $ key = date ($ format , strtotime ($ download ->getDate ()));
37
+ $ key = date ($ format , strtotime ($ download ->getDate ()));
33
38
$ arrayDownload [$ key ]++;
39
+ $ latitude = $ download ->getLatitude ();
40
+ $ longitude = $ download ->getLongitude ();
41
+
42
+ if ($ latitude || $ longitude )
43
+ {
44
+ $ markers [] = array ($ latitude , $ longitude );
45
+ }
34
46
}
35
-
47
+
36
48
$ jqplotArray = array ();
37
49
foreach ($ arrayDownload as $ key => $ value )
38
50
{
39
51
$ jqplotArray [] = array ($ key .' 8:00AM ' , $ value );
40
52
}
41
53
$ this ->view ->json ['stats ' ]['downloads ' ] = $ jqplotArray ;
54
+ $ this ->view ->markers = $ markers ;
42
55
$ this ->view ->itemDao = $ item ;
43
- }
44
-
45
- }//end class
56
+ }
57
+
58
+ }//end class
0 commit comments