Commit 5c79fb68 authored by Denis S. Valdenaire's avatar Denis S. Valdenaire

liste des emprunts pour un jeu donné - debut

parent 101df853
......@@ -8,6 +8,8 @@ class Game extends Record {
// array containing the medias associated with the game
public $medias;
// loan history
public $loans;
public $table = "games";
......@@ -41,6 +43,12 @@ class Game extends Record {
return sizeof($this->medias);
}
public function fetch_loans() {
$this->loans = array();
Loan::fetch_loans($this->loans, $this->id);
return sizeof($this->loans);
}
public static function fetch_all(&$games) {
$games = array();
$where_clause = "";
......@@ -59,5 +67,3 @@ class Game extends Record {
return sizeof($games);
}
}
?>
......@@ -51,6 +51,19 @@ class Loan extends Record {
return sizeof($loans);
}
public static function fetch_loans(&$loans, $id) {
// SQL SELECT loans members
$sql = " SELECT l.id, start_date, end_date, is_back, l.created_at, l.updated_at,
l.member_id, CONCAT(m.firstname, ' ', m.lastname) AS member_name
FROM loans l, members m
WHERE l.game_id = $id
AND l.member_id = m.id
ORDER BY start_date DESC ";
$GLOBALS["data"]->select($sql, $loans, "Loan", true);
return sizeof($loans);
}
public static function fetch($id) {
// SQL SELECT loans
......
......@@ -74,12 +74,12 @@ class GamesController extends AppController {
$game = Game::fetch($GLOBALS["data"]->db_escape_string($_REQUEST["i"]));
if($game->id != 0) {
$_REQUEST["a"] = "confirm_delete";
$render = "games/confirm_delete";
return "games/confirm_delete";
} else {
$render = "games/not_found"; // TODO
return "games/not_found"; // TODO
}
} catch(data_exception $e) {
$render = "data_exception";
return "data_exception";
}
return $render;
}
......@@ -90,6 +90,21 @@ class GamesController extends AppController {
return "games/list";
}
function _loans() {
try {
$game = Game::fetch($GLOBALS["data"]->db_escape_string($_REQUEST["i"]));
if($game->id != 0) {
$game->fetch_loans();
$this->set("game", $game);
return "games/loans";
} else {
return "games/not_found";
}
} catch (data_exception $e) {
return "data_exception";
}
}
function _list() {
try {
Game::fetch_all($games);
......
{% extends "base.html" %}
{% block title %}Historique des emprunts{% endblock %}
{% block content %}
<div class="panel panel-default">
<div class="panel-heading">
<h4><!-- class="panel-title" -->
<span class="glyphicon glyphicon-knight" style="margin-right: 10px" ></span>
{{ game.name }}
<small>
{% if game.loan_id %}
INDISPONIBLE :
jusqu'au {{ game.loan_end_date | date("d/m/Y") }}
<span class="btn btn-success btn-md" style="float: right" id="reservation_button">
<i class="glyphicon glyphicon-plus"></i>
<span>Réserver...</span>
</span>
{% else %}
DISPONIBLE
{% endif %}
</small>
<a href="index.php?o=games&a=loans&i={{ game.id }}">
Historique des emprunts
</a>
</h4>
</div>
<div class="panel-body">
<table id="object_list" class="col-sm-12" width="100%">
<thead>
<tr>
<th>Nom</th>
<th>Date emprunt</th>
<th>Date retour</th>
<th>Rendu</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for key, val in game.loans %}
<tr>
<td><a href="index.php?o=member&a=edit&i={{ val.member_id }}">{{ val.member_name }}</a>
{% if val.is_late %} <span class="label label-warning">En retard</span> {% endif %}
</td>
<td>{{ val.start_date | date("d/m/Y") }}</td>
<td>{{ val.end_date | date("d/m/Y") }}</td>
<td><input type="checkbox" id="is_back_{{ val.id }}" name="is_back_{{ val.id }}" class="form-control is_back_cbx"
data-switch-with-ajax {{ val.is_back ? ' checked ' }}></td>
<td>
whatever...
</td>
{% else %}
<tr>
<th colspan="5">
<div class="alert alert-warning" role="alert">Aucun emprunt</div>
</th>
</tr>
{% endfor %}
</tbody>
</table>
<!-- end of panel -->
</div>
</div>
<script>
$('#back_button').click(function(){
window.location.href='index.php?o=games&a=list';
});
</script>
{% endblock %}
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