| 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 | |
|---|
| 25 | require_once BASEPATH.'include/common.php'; |
|---|
| 26 | require_once BASEPATH.'classes/StatisticGraph.php'; |
|---|
| 27 | |
|---|
| 28 | /* An abstract class. All statistics must inherit from this class */ |
|---|
| 29 | class 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); |
|---|
| 77 | if ($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 | ?> |
|---|