Commit 4e296f35 authored by SASSU Thomas's avatar SASSU Thomas
Browse files

TD3 done

parent 00f253ad
......@@ -22,16 +22,21 @@ echo ("<!DOCTYPE html>
<h2> Consignes : </h2>
<p> Pour chaque requête, mettre le paramètre dans l'url ?requete='Numero de la requete'</p>
</div>");
if(isset($_GET['requete']) && $_GET['requete']>0 && $_GET['requete']<=5) {
if(isset($_GET['requete']) && $_GET['requete']>0 && $_GET['requete']<=6) {
echo "<div><center>";
$nb = $_GET['requete'];
$c = new ControleurScript();
$c->setLog(true);
$function = 'td3_q'. $nb .'b';
$res = $c->$function();
// foreach ($res as $item){
// echo "<p>$item->name</p>";
// }
if($res != null) {
foreach ($res as $item) {
if($nb!=6)
echo "<p>$item->name</p>";
else
echo "<p>$item</p>";
}
} else echo "<p>Aucun résultat</p>";
echo "</center></div>";
echo "<div>";
echo $c->getLog();
......
<?php
require_once __DIR__ . '../vendor/autoload.php';
require_once dirname (__DIR__) . '/vendor/autoload.php';;
session_start();
use \Slim\Slim as Slim;
......@@ -9,7 +9,7 @@ use \gp\controleurs\ControleurPrincipal as ControleurPrincipal;
use \gp\controleurs\ControleurScript as ControleurScript;
$db = new DB();
$db->addConnection(parse_ini_file('./conf/conf.ini'));
$db->addConnection(parse_ini_file('../conf/conf.ini'));
$db->setAsGlobal();
$db->bootEloquent();
......
......@@ -248,7 +248,7 @@ class ControleurScript
}
public function td3_q1b(){
return Game::where('name','like','%Mario%')->get();
return Game::where('name', 'like','%Mario%')->get();
}
public function td3_q2b(){
......@@ -257,26 +257,54 @@ class ControleurScript
public function td3_q3b(){
$res = null;
$games = Game::where('name','like','%Mario%')->get();;
foreach ($games as $game)
echo "<p>$game->name</p>";
$characters = $game->characters()->get();
foreach ($characters as $character){
echo "<p>$character->name</p>";
$first = $character->games()->orderBy('original_release_date', 'asc')->first();
if($first != null && str_contains(strtolower($first->name),'mario'))
$q = Game::where('name', 'like', "%Mario%")->get();
foreach ($q as $game) {
$list = $game->characters()->get();
foreach ($list as $character)
$first = $character->games()->orderBy('original_release_date', 'asc')->first();
if($first != null && str_contains(strtolower($first->name),'mario'))
$res[] = $character;
}
$res = array_unique((array)$res);
return $res;
}
public function td3_q4b(){
$characters = $this->td3_q1b()->characters()->get();
return $characters;
$q = Game::where('name', 'like', "Mario%")->get();
foreach ($q as $game) {
$characters = $game->characters()->get();
foreach ($characters as $char)
$res[] = $char;
}
$res = array_unique((array)$res);
return $res;
}
public function td3_q5b(){
return Company::where('name','like', '%Sony%')->get()->games();
$res = null;
$comps = Company::where('name','like', '%Sony%')->get();
foreach ($comps as $comp) {
$games = $comp->games()->get();
foreach ($games as $game) $res[] = $game;
}
$res = array_unique((array)$res);
return $res;
}
public function td3_q6b(){
$res = null;
$results = DB::table('game')
->select(DB::raw('group_concat(character.name) as names'))
->join('game2character', 'game.id', '=', 'game2character.game_id')
->join('character', 'game2character.character_id', '=', 'character.id')
->whereRaw('`game`.`name` like \'%Mario%\'')
->groupBy('game.name')
->get();
foreach ($results as $result) {
$names = explode(',', $result->names);
foreach($names as $name) $res[] = $name;
}
return $res;
}
public function allGame(){
......
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