index.ctp
4.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/**
* @var \App\View\AppView $this
* @var \App\Model\Entity\Stat[]|\Cake\Collection\CollectionInterface $stats
*/
// Variables passées par le controleur
$stats = $stats;
function getHourMnSecForDuration($duration_sec) {
//debug($duration_sec);
// PHP7 only (intdiv)
//$h = intdiv($duration_sec,3600);
// PHP5 !!!
$h = (int)($duration_sec/3600);
$m = (int)( ($duration_sec - $h*3600) / 60 );
$s = $duration_sec - $h*3600 - $m*60;
return [$h,$m,$s];
}
echo "<b>Temps de connexion moyen (moyenne sur tous les utilisateurs et toutes les années) : </b>";
$connex_nb_tot = 0;
$connex_dur_tot_tot = 0;
foreach ($stats as $stat) {
$connex_nb_tot += $stat->connex_nb;
$connex_dur_tot_tot += $stat->connex_dur_tot;
}
$connex_dur_tot_avg = round($connex_dur_tot_tot / $connex_nb_tot);
//$connex_dur_tot_avg = intdiv($connex_dur_tot_tot , $connex_nb_tot);
//echo $connex_dur_tot_avg;
list($h,$m,$s) = getHourMnSecForDuration($connex_dur_tot_avg);
echo "$h h $m mn $s sec";
echo "<br>";echo "<br>";
?>
<nav class="large-3 medium-4 columns" id="actions-sidebar">
<ul class="side-nav">
<li class="heading"><?= __('Actions') ?></li>
<li><?= $this->Html->link(__('New Stat'), ['action' => 'add']) ?></li>
<li><?= $this->Html->link(__('List Users'), ['controller' => 'Users', 'action' => 'index']) ?></li>
<li><?= $this->Html->link(__('New User'), ['controller' => 'Users', 'action' => 'add']) ?></li>
</ul>
</nav>
<div class="stats index large-9 medium-8 columns content">
<h3><?= __('Stats') ?></h3>
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
<th scope="col"><?= $this->Paginator->sort('year') ?></th>
<th scope="col"><?= $this->Paginator->sort('user_id') ?></th>
<th scope="col"><?= $this->Paginator->sort('last_login_time') ?></th>
<th scope="col"><?= $this->Paginator->sort('last_connex_dur', 'Durée connexion (mn)') ?></th>
<th scope="col"><?= $this->Paginator->sort('last_logout_time') ?></th>
<th scope="col"><?= $this->Paginator->sort('connex_dur_tot', "Durée connexion cumulée (sur année) (mn)") ?></th>
<th scope="col"><?= $this->Paginator->sort('connex_nb', "Nb connexions (sur année)") ?></th>
<th scope="col"><?= "Durée connexion moyenne (sur année)" ?></th>
<th scope="col" class="actions"><?= __('Actions') ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($stats as $stat): ?>
<tr>
<td><?= h($stat->year) ?></td>
<td><?= $stat->has('user') ? $this->Html->link($stat->user->nom, ['controller' => 'Users', 'action' => 'view', $stat->user->id]) : '' ?></td>
<td><?= h($stat->last_login_time) ?></td>
<?php
list($h,$m,$s) = getHourMnSecForDuration($stat->last_connex_dur);
?>
<td><?="$h h $m mn $s sec"?></td>
<!--
<td><= h($stat->last_connex_dur) ?></td>
-->
<td><?= h($stat->last_logout_time) ?></td>
<?php
list($h,$m,$s) = getHourMnSecForDuration($stat->connex_dur_tot);
?>
<td><?="$h h $m mn $s sec"?></td>
<!--
<td><= $this->Number->format($stat->connex_dur_tot) ?></td>
-->
<td><?= $this->Number->format($stat->connex_nb) ?></td>
<?php
// PHP7 only
//$connex_dur_avg = intdiv($stat->connex_dur_tot , $stat->connex_nb);
// PHP5
$connex_dur_avg = (int)($stat->connex_dur_tot / $stat->connex_nb);
list($h,$m,$s) = getHourMnSecForDuration($connex_dur_avg);
?>
<td><?="$h h $m mn $s sec"?></td>
<td class="actions">
<?= $this->Html->link(__('View'), ['action' => 'view', $stat->year,$stat->user_id]) ?>
<?= $this->Html->link(__('Edit'), ['action' => 'edit', $stat->year,$stat->user_id]) ?>
<?= $this->Form->postLink(__('Delete'), ['action' => 'delete', $stat->year,$stat->user_id], ['confirm' => __('Are you sure you want to delete # {0}?', $stat->year)]) ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div class="paginator">
<ul class="pagination">
<?= $this->Paginator->first('<< ' . __('first')) ?>
<?= $this->Paginator->prev('< ' . __('previous')) ?>
<?= $this->Paginator->numbers() ?>
<?= $this->Paginator->next(__('next') . ' >') ?>
<?= $this->Paginator->last(__('last') . ' >>') ?>
</ul>
<p><?= $this->Paginator->counter(['format' => __('Page {{page}} of {{pages}}, showing {{current}} record(s) out of {{count}} total')]) ?></p>
</div>
</div>