add quota to user list
This commit is contained in:
parent
4a39865903
commit
03ae69b82a
|
@ -53,6 +53,13 @@ class User extends \descartes\Controller
|
|||
public function list_json()
|
||||
{
|
||||
$entities = $this->internal_user->list();
|
||||
|
||||
foreach ($entities as &$entity)
|
||||
{
|
||||
$quota_percentage = $this->internal_quota->get_usage_percentage($entity['id']);
|
||||
$entity['quota_percentage'] = $quota_percentage * 100;
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(['data' => $entities]);
|
||||
}
|
||||
|
|
|
@ -58,14 +58,14 @@ namespace models;
|
|||
* @param \DateTime $at : date to get usage percent at
|
||||
* @return float : percent of used credits
|
||||
*/
|
||||
public function get_usage_percentage (int $id_user, \DateTime $at): int
|
||||
public function get_usage_percentage (int $id_user, \DateTime $at): float
|
||||
{
|
||||
$query = '
|
||||
SELECT (consumed / (credit + additional)) AS usage_percentage
|
||||
FROM quota
|
||||
WHERE id_user = :id_user
|
||||
AND start_date <= :at
|
||||
AND end_date > :at';
|
||||
AND expiration_date > :at';
|
||||
|
||||
$params = [
|
||||
'id_user' => $id_user,
|
||||
|
@ -74,7 +74,7 @@ namespace models;
|
|||
|
||||
$result = $this->_run_query($query, $params);
|
||||
|
||||
return ($result[0]['usage_percentage'] ?? 0);
|
||||
return (float) ($result[0]['usage_percentage'] ?? 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -36,12 +36,13 @@
|
|||
<div class="panel-body">
|
||||
<form method="GET">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-bordered table-hover table-striped datatable" id="table-users">
|
||||
<table class="table table-bordered table-hover table-striped datatable" id="table-users" style="width:100%">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Email</th>
|
||||
<th>Admin</th>
|
||||
<th>Statut</th>
|
||||
<th>Crédit utilisé</th>
|
||||
<th class="checkcolumn">✓</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
@ -49,17 +50,16 @@
|
|||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div>
|
||||
<div class="col-xs-6 no-padding">
|
||||
<a class="btn btn-success" href="<?php echo \descartes\Router::url('User', 'add'); ?>"><span class="fa fa-plus"></span> Ajouter un utilisateur</a>
|
||||
</div>
|
||||
<div class="text-right col-xs-6 no-padding">
|
||||
<strong>Action pour la séléction :</strong>
|
||||
<button class="btn btn-default" type="submit" formaction="<?php echo \descartes\Router::url('User', 'update_status', ['csrf' => $_SESSION['csrf'], 'status' => 0]); ?>"><span class="fa fa-pause"></span> Suspendre</button>
|
||||
<button class="btn btn-default" type="submit" formaction="<?php echo \descartes\Router::url('User', 'update_status', ['csrf' => $_SESSION['csrf'], 'status' => 1]); ?>"><span class="fa fa-play"></span> Activer</button>
|
||||
<button class="btn btn-default" type="submit" formaction="<?php echo \descartes\Router::url('User', 'edit'); ?>"><span class="fa fa-edit"></span> Modifier</button>
|
||||
<button class="btn btn-default btn-confirm" type="submit" formaction="<?php echo \descartes\Router::url('User', 'delete', ['csrf' => $_SESSION['csrf']]); ?>"><span class="fa fa-trash-o"></span> Supprimer</button>
|
||||
</div>
|
||||
<div>
|
||||
<div class="col-xs-6 no-padding">
|
||||
<a class="btn btn-success" href="<?php echo \descartes\Router::url('User', 'add'); ?>"><span class="fa fa-plus"></span> Ajouter un utilisateur</a>
|
||||
</div>
|
||||
<div class="text-right col-xs-6 no-padding">
|
||||
<strong>Action pour la séléction :</strong>
|
||||
<button class="btn btn-default" type="submit" formaction="<?php echo \descartes\Router::url('User', 'update_status', ['csrf' => $_SESSION['csrf'], 'status' => 0]); ?>"><span class="fa fa-pause"></span> Suspendre</button>
|
||||
<button class="btn btn-default" type="submit" formaction="<?php echo \descartes\Router::url('User', 'update_status', ['csrf' => $_SESSION['csrf'], 'status' => 1]); ?>"><span class="fa fa-play"></span> Activer</button>
|
||||
<button class="btn btn-default" type="submit" formaction="<?php echo \descartes\Router::url('User', 'edit'); ?>"><span class="fa fa-edit"></span> Modifier</button>
|
||||
<button class="btn btn-default btn-confirm" type="submit" formaction="<?php echo \descartes\Router::url('User', 'delete', ['csrf' => $_SESSION['csrf']]); ?>"><span class="fa fa-trash-o"></span> Supprimer</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
@ -92,6 +92,13 @@ jQuery(document).ready(function ()
|
|||
{data: 'email', render: jQuery.fn.dataTable.render.text()},
|
||||
{data: 'admin', render: jQuery.fn.dataTable.render.text()},
|
||||
{data: 'status', render: jQuery.fn.dataTable.render.text()},
|
||||
{
|
||||
data: 'quota_percentage',
|
||||
render: function (data, type, row, meta) {
|
||||
return jQuery.fn.dataTable.render.text().display(data) + "%";
|
||||
return '<input name="user_ids[]" type="checkbox" value="' + data + '">';
|
||||
},
|
||||
},
|
||||
{
|
||||
data: 'id',
|
||||
render: function (data, type, row, meta) {
|
||||
|
|
Loading…
Reference in New Issue