Commit f8790a97 authored by Denis Valdenaire's avatar Denis Valdenaire

game model evolution

parent 1e87c9b1
......@@ -6,12 +6,51 @@ class Game {
public $commentaire, $infos_fabricant, $inventaire, $date_achat, $prix;
public $nombre_mini, $nombre_maxi, $age_mini, $age_maxi, $type;
public function __construct($id = 0)
{
// array containing the medias associated with the game
public $medias;
public function __construct($id = 0) {
if (!$this->id_jeu) {
$this->id_jeu = $id;
}
}
public function fetch($id) {
// SQL SELECT jeu prets
$sql = "SELECT jeu.id_jeu, nom, reference, fabricant, categorie, categorie_esar_id,
commentaire, infos_fabricant, inventaire, date_achat, prix, nombre_mini, nombre_maxi,
age_mini, age_maxi, type, id_pret
FROM jeu
LEFT OUTER JOIN prets ON (jeu.id_jeu = prets.id_jeu AND prets.rendu = 0)
WHERE jeu.id_jeu = ".$id;
$GLOBALS["data"]->select($sql, $my, "Game");
foreach(get_object_vars($my) as $var => $value) $this->$var = $value;
return $this->id_jeu;
}
public function fetch_medias() {
$this->medias = array();
// SQL SELECT medias
$sql = " SELECT id, description, media_type_id, file
FROM medias
WHERE id_jeu = ".$this->id_jeu;
$GLOBALS["data"]->select($sql, $this->medias, "Media");
return sizeof($this->medias);
}
public static function fetch_all(&$games) {
$games = array();
// SQL SELECT jeu categorie_esar prets
$sql = "SELECT jeu.id_jeu, nom,
CONCAT (categorie_esar.label, ' - ', categorie_esar.name) AS label,
id_pret as etat_pret
FROM jeu
LEFT OUTER JOIN categorie_esar ON jeu.categorie_esar_id = categorie_esar.id
LEFT OUTER JOIN prets ON (jeu.id_jeu = prets.id_jeu AND date_retour > curdate())
ORDER BY nom";
$GLOBALS["data"]->select($sql, $games, "Game");
return sizeof($games);
}
}
?>
<?php
global $db_user, $db_passwd, $db_host, $db_name;
global $db_user, $db_passwd, $db_host, $db_name, $debug;
$db_user = "db_user_here";
$db_passwd = "db_password_here";
$db_host = "db_host_here";
$db_name = "db_name_here";
$debug = false;
......@@ -30,7 +30,7 @@ function validate_and_submit ()
}
</script>
<?php
// since we are in the edit form, we have an existing $game
// since we are in the edit form, we have an existing $game from the controller
?>
<center>
<h3>JEU n°<?=$game->id_jeu?>
......
......@@ -16,38 +16,33 @@ This file is part of phpLudoreve.
along with phpLudoreve. If not, see <http://www.gnu.org/licenses/>.
*/
include("classes/game.php");
include("classes/media.php");
// controller + model part
// controller
$render = "list";
switch($_REQUEST["a"]) {
case "edit":
try {
// FIXME this should be in the model
// SQL SELECT jeu prets
$sql = "SELECT jeu.id_jeu, nom, reference, fabricant, categorie, categorie_esar_id,
commentaire, infos_fabricant, inventaire, date_achat, prix, nombre_mini, nombre_maxi,
age_mini, age_maxi, type, id_pret
FROM jeu
LEFT OUTER JOIN prets ON (jeu.id_jeu = prets.id_jeu AND prets.rendu = 0)
WHERE jeu.id_jeu = ".mysql_real_escape_string($_REQUEST["i"]);
$data->select($sql, $game, "Game");
if(sizeof($game)) {
// get medias associated with it
// SQL SELECT medias
$sql = " SELECT id, description, media_type_id, file
FROM medias
WHERE id_jeu = ".mysql_real_escape_string($_REQUEST["i"]);
$data->select($sql, $medias, "Media");
$game = new Game();
$id_jeu = $game->fetch($data->db_escape_string($_REQUEST["i"]));
if($id_jeu != 0) {
$game->fetch_medias();
$render = "games/edit";
} else {
print_r($id_jeu);
$render = "games/not_found"; // TODO
}
} catch(data_exception $e) {
$render = "views/data_exception";
}
break;
default:
try {
Game::fetch_all($games);
$render = "games/list";
} catch(data_exception $e) {
$render = "views/data_exception";
}
break;
}
// view part
......
<?php
// SQL SELECT jeu categorie_esar prets
$sql = "SELECT jeu.id_jeu, nom,
CONCAT (categorie_esar.label, ' - ', categorie_esar.name) AS label,
id_pret as etat_pret
FROM jeu
LEFT OUTER JOIN categorie_esar ON jeu.categorie_esar_id = categorie_esar.id
LEFT OUTER JOIN prets ON (jeu.id_jeu = prets.id_jeu AND date_retour > curdate())
ORDER BY nom";
$data->select($sql, $rset);
?>
<h1>Liste des jeux</h1>
<table id="list_jeu">
<thead>
......@@ -20,19 +9,19 @@ $data->select($sql, $rset);
</thead>
<tbody>
<?php
do { ?>
while(list($key, $val) = each($games)) { ?>
<tr>
<td>
<a href="index.php?o=games&a=edit&i=<?=$rset->value("id_jeu")?>"><?=$rset->value("nom")?></a>
<a href="index.php?o=games&a=edit&i=<?=$val->id_jeu?>"><?=$val->nom?></a>
</td>
<td>
<?=$rset->value("label")?>
<?=$val->label?>
</td>
<td>
<?=($rset->value("etat_pret") == "") ? "Libre" : "Emprunte"?>
<?=($val->etat_pret == "") ? "Libre" : "Emprunte"?>
</td>
</tr>
<?php } while($rset->nextrow()); ?>
<?php } ?>
</tbody>
</table>
<script>
......
......@@ -17,8 +17,11 @@ This file is part of phpLudoreve.
*/
session_start();
function __autoload($class_name) {
include "classes/".strtolower($class_name).".php";
}
include("config/config.php");
include("classes/data.php");
global $data;
$data = new data();
?>
<!DOCTYPE html>
......@@ -59,7 +62,10 @@ if(!array_key_exists("o", $_REQUEST) || !array_key_exists($_REQUEST["o"], $conte
<?php } ?>
</ul>
<form class="navbar-form navbar-right">
<input type="text" class="form-control" placeholder="Recherche...">
<input type="text" class="form-control" placeholder="Recherche..."
name="search" id="search" autocomplete="off">
<span role="status" aria-live="polite" class="ui-helper-hidden-accessible"></span>
<input type="hidden" name="everything_data" id="everything_data" value="">
</form>
<!-- when authentication will be ready
<ul class="nav navbar-nav navbar-right">
......@@ -129,16 +135,16 @@ SESSION :
<script src="js/zabuto_calendar.min.js"></script>
<script src="js/functions.js"></script>
<script type="application/javascript">
$(document).ready(function () {
$("#my-calendar").zabuto_calendar({
language: "fr",
today: true,
});
$(document).ready(function () {
$("#my-calendar").zabuto_calendar({
language: "fr",
today: true,
});
/*
TODO : Display calendar events via ajax
See documentation at https://github.com/zabuto/calendar
*/
});
/*
TODO : Display calendar events via ajax
See documentation at https://github.com/zabuto/calendar
*/
</script>
</body>
</html>
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