Commit 2372835d authored by thejoelinux's avatar thejoelinux

ajout des stats en tableau et possibilité de les effacer

parent 914858c2
......@@ -28,4 +28,80 @@ class Statistic extends Record {
} while($rset->nextrow());
return substr($datas, 0, -1)."]]";
}
public static function count_all() {
// SQL SELECT lud_statistics
$sql = " SELECT count(*) AS num_rows
FROM ".Statistic::$table;
$GLOBALS["data"]->select($sql, $rset);
return $rset->value("num_rows");
}
public static function delete_posted_timestamp() {
// DELETE lud_statistics
$sql = " DELETE FROM ".Statistic::$table."
WHERE stat_date = '".$GLOBALS["data"]->db_escape_string($_REQUEST["date"])."'
AND stat_time = '".$GLOBALS["data"]->db_escape_string($_REQUEST["time"])."'
LIMIT 1 ";
return $GLOBALS["data"]->delete($sql);
}
public static function fetch_array_with_request_params(&$recordsFiltered) {
// paging
$sLimit = "";
if ( isset( $_GET['start'] ) && $_GET['length'] != '-1' ) {
$sLimit = "LIMIT ".intval( $_GET['start'] ).", ".
intval( $_GET['length'] );
}
// ordering
$sOrder = "";
while(list($key, $val) = each($_GET["order"])) {
$sOrder .= " ".(intval($val["column"]) + 1)." ".
($val["dir"] == "desc" ? "DESC" : "ASC").", ";
}
if($sOrder != "") {
$sOrder = " ORDER BY ".substr($sOrder, 0, -2);
}
// filtering
$sWhere = "";
$aColumns = array('stat_date', 'stat_time', 'member_name', 'num_adult', 'num_child');
if($_GET["search"]["value"] != "") {
$sWhere = "WHERE (";
for ($i=0 ; $i<count($aColumns) ; $i++) {
if($_GET["columns"][$i]["searchable"] == "true") {
$sWhere .= $aColumns[$i]." LIKE '%".$GLOBALS["data"]->db_escape_string( $_GET["search"]["value"] )."%' OR ";
}
}
$sWhere = substr_replace( $sWhere, "", -3 );
$sWhere .= ')';
}
// SQL SELECT lud_statistics
$sql = " SELECT SQL_CALC_FOUND_ROWS stat_date, stat_time, m.lastname AS member_name,
num_adult, num_child
FROM ".Statistic::$table." s
LEFT JOIN ".Member::$table." m ON (m.id = s.member_id) ";
$sql .= $sWhere." ".$sOrder." ".$sLimit;
$GLOBALS["data"]->select($sql, $rset);
$datas = array();
do {
$datas[] = array(
$rset->value("stat_date"),
$rset->value("stat_time"),
$rset->value("member_name"),
$rset->value("num_adult"),
$rset->value("num_child"),
""
);
} while ($rset->nextrow());
$sql = " SELECT FOUND_ROWS() AS num_rows ";
$GLOBALS["data"]->select($sql, $rset);
$recordsFiltered = $rset->value("num_rows");
return $datas;
}
}
......@@ -30,5 +30,23 @@ class StatisticsController extends AppController {
exit();
}
function _draw() {
$response = new Record();
$response->draw = intval($_GET["draw"]);
$response->recordsTotal = Statistic::count_all();
$response->data = Statistic::fetch_array_with_request_params($response->recordsFiltered);
echo json_encode($response);
exit();
}
function _delete() {
// TODO : code me
try {
Statistic::delete_posted_timestamp();
echo "[]";
} catch (data_exception $e) {
header($_SERVER['SERVER_PROTOCOL'] . ' Internal Server Error', true, 500);
}
exit();
}
}
.jqplot-target{position:relative;color:#666;font-family:"Trebuchet MS",Arial,Helvetica,sans-serif;font-size:1em}.jqplot-axis{font-size:.75em}.jqplot-xaxis{margin-top:10px}.jqplot-x2axis{margin-bottom:10px}.jqplot-yaxis{margin-right:10px}.jqplot-y2axis,.jqplot-y3axis,.jqplot-y4axis,.jqplot-y5axis,.jqplot-y6axis,.jqplot-y7axis,.jqplot-y8axis,.jqplot-y9axis,.jqplot-yMidAxis{margin-left:10px;margin-right:10px}.jqplot-axis-tick,.jqplot-xaxis-tick,.jqplot-yaxis-tick,.jqplot-x2axis-tick,.jqplot-y2axis-tick,.jqplot-y3axis-tick,.jqplot-y4axis-tick,.jqplot-y5axis-tick,.jqplot-y6axis-tick,.jqplot-y7axis-tick,.jqplot-y8axis-tick,.jqplot-y9axis-tick,.jqplot-yMidAxis-tick{position:absolute;white-space:pre}.jqplot-xaxis-tick{top:0;left:15px;vertical-align:top}.jqplot-x2axis-tick{bottom:0;left:15px;vertical-align:bottom}.jqplot-yaxis-tick{right:0;top:15px;text-align:right}.jqplot-yaxis-tick.jqplot-breakTick{right:-20px;margin-right:0;padding:1px 5px 1px 5px;z-index:2;font-size:1.5em}.jqplot-y2axis-tick,.jqplot-y3axis-tick,.jqplot-y4axis-tick,.jqplot-y5axis-tick,.jqplot-y6axis-tick,.jqplot-y7axis-tick,.jqplot-y8axis-tick,.jqplot-y9axis-tick{left:0;top:15px;text-align:left}.jqplot-yMidAxis-tick{text-align:center;white-space:nowrap}.jqplot-xaxis-label{margin-top:10px;font-size:11pt;position:absolute}.jqplot-x2axis-label{margin-bottom:10px;font-size:11pt;position:absolute}.jqplot-yaxis-label{margin-right:10px;font-size:11pt;position:absolute}.jqplot-yMidAxis-label{font-size:11pt;position:absolute}.jqplot-y2axis-label,.jqplot-y3axis-label,.jqplot-y4axis-label,.jqplot-y5axis-label,.jqplot-y6axis-label,.jqplot-y7axis-label,.jqplot-y8axis-label,.jqplot-y9axis-label{font-size:11pt;margin-left:10px;position:absolute}.jqplot-meterGauge-tick{font-size:.75em;color:#999}.jqplot-meterGauge-label{font-size:1em;color:#999}table.jqplot-table-legend{margin-top:12px;margin-bottom:12px;margin-left:12px;margin-right:12px}table.jqplot-table-legend,table.jqplot-cursor-legend{background-color:rgba(255,255,255,0.6);border:1px solid #ccc;position:absolute;font-size:.75em}td.jqplot-table-legend{vertical-align:middle}td.jqplot-seriesToggle:hover,td.jqplot-seriesToggle:active{cursor:pointer}.jqplot-table-legend .jqplot-series-hidden{text-decoration:line-through}div.jqplot-table-legend-swatch-outline{border:1px solid #ccc;padding:1px}div.jqplot-table-legend-swatch{width:0;height:0;border-top-width:5px;border-bottom-width:5px;border-left-width:6px;border-right-width:6px;border-top-style:solid;border-bottom-style:solid;border-left-style:solid;border-right-style:solid}.jqplot-title{top:0;left:0;padding-bottom:.5em;font-size:1.2em}table.jqplot-cursor-tooltip{border:1px solid #ccc;font-size:.75em}.jqplot-cursor-tooltip{border:1px solid #ccc;font-size:.75em;white-space:nowrap;background:rgba(208,208,208,0.5);padding:1px}.jqplot-highlighter-tooltip,.jqplot-canvasOverlay-tooltip{border:1px solid #ccc;font-size:.75em;white-space:nowrap;background:rgba(208,208,208,0.5);padding:1px}.jqplot-point-label{font-size:.75em;z-index:2}td.jqplot-cursor-legend-swatch{vertical-align:middle;text-align:center}div.jqplot-cursor-legend-swatch{width:1.2em;height:.7em}.jqplot-error{text-align:center}.jqplot-error-message{position:relative;top:46%;display:inline-block}div.jqplot-bubble-label{font-size:.8em;padding-left:2px;padding-right:2px;color:rgb(20%,20%,20%)}div.jqplot-bubble-label.jqplot-bubble-label-highlight{background:rgba(90%,90%,90%,0.7)}div.jqplot-noData-container{text-align:center;background-color:rgba(96%,96%,96%,0.3)}
\ No newline at end of file
......@@ -9,7 +9,7 @@
<h4 class="panel-title">Nombre de visites par jour</h4>
</div>
<div class="panel-body">
<div id="main_chart" style="height:200px;width:450px;"></div>
<div id="main_chart" style="height:200px;width:500px;"></div>
</div>
</div>
</div>
......@@ -22,9 +22,18 @@
</div>
<div class="panel-body">
<table id="objects_list" width="100%">
<thead>
<tr>
<th>Date</th>
<th>Time</th>
<th>Adhérent</th>
<th>Adultes</th>
<th>Enfants</th>
<th>&nbsp;</th>
</tr>
</thead>
</table>
</div>
</div>
......@@ -38,6 +47,37 @@
<script src="js/plugins/jqplot.categoryAxisRenderer.min.js"></script>
<script>
$(document).ready(function() {
var table = $('#objects_list').DataTable( {
"processing": true,
"serverSide": true,
"ajax": "api.php?o=statistics&a=draw",
"autoWidth": true,
"columnDefs": [
{
"orderable": false,
"targets": 5,
"render": function ( data, type, row ) {
return '<button type="button" data-date="' + row[0] + '" data-time="' + row[1] + '" class="btn btn-danger btn-xs delete_button">'
+ '<i class="glyphicon glyphicon-trash"></i></button>';
}
}
]
});
$('#objects_list').addClass('table table-striped table-bordered table-condensed');
$('#objects_list').on("click", ".delete_button", function (e) {
var button = $(e.currentTarget);
$.post('api.php', { o: 'statistics', a: 'delete',
date: button.data('date'),
time: button.data('time')})
.done(function(data) {})
.fail(function(){});
//alert('TODO : make an ajax call');
//table.row( button.parents('tr') ).remove().draw();
table.draw();
});
var ajaxDataRenderer = function(url, plot, options) {
var ret = null;
$.ajax({
......@@ -59,7 +99,8 @@ $(document).ready(function() {
var main_plot = $.jqplot('main_chart', main_url, {
axes:{
xaxis:{
renderer:$.jqplot.DateAxisRenderer
renderer:$.jqplot.DateAxisRenderer,
tickInterval:'1 weeks'
},
yaxis:{
label:'Visiteurs',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment