root/trunk/wifidog-auth/wifidog/classes/StatisticGraph/VisitsPerMonth.php @ 768

Revision 768, 3.7 KB (checked in by benoitg, 8 years ago)

2005-09-25 Benoit Gr�goire <bock@…>

  • Statistics: At long last, the monster statistics commit. We finally have a stable, documented and uniform codebase for statistics. This resulted is removal of several functions in other classes too. There are a few new reports, but mostly, each report is a lot more flexible. Still TODO: -Security: This is to be implemented directly in the Statistics class, by forcing restrictions to the selected nodes and network. -Support selecting multiple users for a report. The code and SQL queries support it, but the UI doesn't. An easy and quick way would be to simply parse a coma-separated list. Comment are off course welcome!
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2/********************************************************************\
3 * This program is free software; you can redistribute it and/or    *
4 * modify it under the terms of the GNU General Public License as   *
5 * published by the Free Software Foundation; either version 2 of   *
6 * the License, or (at your option) any later version.              *
7 *                                                                  *
8 * This program is distributed in the hope that it will be useful,  *
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
11 * GNU General Public License for more details.                     *
12 *                                                                  *
13 * You should have received a copy of the GNU General Public License*
14 * along with this program; if not, contact:                        *
15 *                                                                  *
16 * Free Software Foundation           Voice:  +1-617-542-5942       *
17 * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       *
18 * Boston, MA  02111-1307,  USA       gnu@gnu.org                   *
19 *                                                                  *
20 \********************************************************************/
21/**@file VisitsPerMonth.php
22 * @author Copyright (C) 2005 Philippe April and Technologies Coeus inc.
23 */
24
25require_once BASEPATH.'include/common.php';
26require_once BASEPATH.'classes/StatisticGraph.php';
27
28/* An abstract class.  All statistics must inherit from this class */
29class VisitsPerMonth extends StatisticGraph
30{
31        /** Get the Graph's name.  Must be overriden by the report class
32         * @return a localised string */
33        public static function getGraphName()
34        {
35                return _("Number of individual user visits per month");
36        }
37
38        /** Constructor, must be called by subclasses */
39        protected function __construct()
40        {
41                parent :: __construct();
42        }
43
44        /** Get the actual report. 
45         * Classes can (but don't have to) override this, but must call the parent's
46         * method with what would otherwise be their return value and return that
47         * instead.
48         * @param $statistics_object Mandatory to give the report it's context
49         * @param $child_html The child method's return value
50         * @return A html fragment
51         */
52        public function getReportUI(Statistics $statistics_object, $child_html = null)
53        {
54                $html = '';
55                $html .= _("Note:  A visit is like counting connections, but only counting one connection per day for each user at a single node");
56                return parent::getReportUI($statistics_object, $html);
57        }
58       
59        /** Return the actual Image data 
60         * Classes must override this.
61         * @param $child_html The child method's return value
62         * @return A html fragment
63         */
64        public function showImageData()
65        {
66                require_once ("Image/Graph.php");
67                global $db;
68$Graph =& Image_Graph::factory("Image_Graph", array(600, 200));
69$Plotarea =& $Graph->add(Image_Graph::factory("Image_Graph_Plotarea"));
70$Dataset =& Image_Graph::factory("Image_Graph_Dataset_Trivial");
71$Bar =& Image_Graph::factory("Image_Graph_Plot_Bar", $Dataset);
72$Bar->setFillColor("#9db8d2");
73$Plot =& $Plotarea->add($Bar);
74
75                $candidate_connections_sql = self :: $stats->getSqlCandidateConnectionsQuery("COUNT(DISTINCT user_id||connections.node_id) AS daily_connections, date_trunc('day', timestamp_in) AS date");
76$db->ExecSql("SELECT SUM(daily_connections) AS connections, date_trunc('month', date) AS month FROM ($candidate_connections_sql GROUP BY date) AS daily_connections_table GROUP BY month ORDER BY month", $results, false);
77if ($results != null) {
78        foreach($results as $row) {
79        /* Cut xxxx-xx-xx xx:xx:Xx to yy-mm */
80        $Dataset->addPoint( substr($row['month'],0,7), $row['connections']);
81        }
82}
83
84                $Graph->done();
85        }
86
87} //End class
88?>
Note: See TracBrowser for help on using the browser.