index.ctp 4.92 KB
<?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>