Commit 56cc2d81 authored by SASSU Thomas's avatar SASSU Thomas
Browse files

TD2 maj

parent eb184387
......@@ -14,5 +14,18 @@ $db->addConnection(parse_ini_file('../conf/conf.ini'));
$db->setAsGlobal();
$db->bootEloquent();
$c = new ControleurScript();
$c->td2();
echo ("<!DOCTYPE html>
<html>
<body>
<div>
<h1> Script TD2 </h1>
<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']<=9) {
$nb = $_GET['requete'];
$c = new ControleurScript();
$function = 'td2_q'. $nb;
$c->$function();
}
echo ("</body> </html>");
\ No newline at end of file
......@@ -4,55 +4,59 @@
namespace gp\controleurs;
use gp\modeles\Game_rating;
use gp\modeles\Genre;
use gp\modeles\Platform;
use gp\modeles\Game;
use gp\modeles\Company;
use gp\modeles\Character;
use gp\modeles\Rating_board;
class ControleurScript
{
public function td1(){
public function td1()
{
echo "script TD1";
$tab=null;
$tab = null;
$tab[] = $this->gameByName('Mario')->get();
$tab[] = $this->CompanyByCountry('Japan')->get();
$tab[] = $this->platformByBase('10000000')->get();
$tab[] = Game::skip(21173)->take(442)->get();
$data = Game::simplePaginate(500);
$s = "<p>--------------------------------------------------------<br>".
"Jeu contenant dans leur nom 'Mario'<br>".
$s = "<p>--------------------------------------------------------<br>" .
"Jeu contenant dans leur nom 'Mario'<br>" .
"--------------------------------------------------------</p>";
echo $s;
foreach ($tab[0] as $game){
echo ("<p>{$game->name}</p>");
foreach ($tab[0] as $game) {
echo("<p>{$game->name}</p>");
}
$s= "<p>--------------------------------------------------------<br>".
"Compagnies installées au 'Japon'<br>".
$s = "<p>--------------------------------------------------------<br>" .
"Compagnies installées au 'Japon'<br>" .
"--------------------------------------------------------</p>";
echo $s;
foreach ($tab[1] as $company){
echo ("<p>{$company->name}</p>");
foreach ($tab[1] as $company) {
echo("<p>{$company->name}</p>");
}
$s = "<p>--------------------------------------------------------<br>".
"Plateformes dont la base installée est >= 10 000 000<br>".
$s = "<p>--------------------------------------------------------<br>" .
"Plateformes dont la base installée est >= 10 000 000<br>" .
"--------------------------------------------------------</p>";
echo $s;
foreach ($tab[2] as $plat){
echo ("<p>{$plat->name}</p>");
foreach ($tab[2] as $plat) {
echo("<p>{$plat->name}</p>");
}
$s = "<p>--------------------------------------------------------<br>".
"liste de 442 jeux à partir du 21173ème<br>".
$s = "<p>--------------------------------------------------------<br>" .
"liste de 442 jeux à partir du 21173ème<br>" .
"--------------------------------------------------------</p>";
echo $s;
foreach ($tab[3] as $game){
echo ("<p>{$game->name}</p>");
foreach ($tab[3] as $game) {
echo("<p>{$game->name}</p>");
}
$s = "<p>--------------------------------------------------------<br>".
"liste des jeux en paginant (taille des pages : 500)<br>".
$s = "<p>--------------------------------------------------------<br>" .
"liste des jeux en paginant (taille des pages : 500)<br>" .
"--------------------------------------------------------</p>";
echo $s;
$res = "";
foreach ($data as $t){
foreach ($data as $t) {
$res = $res . "<p>$t->name</p>";
}
$res = "<div class=\"container\">
......@@ -61,15 +65,18 @@ class ControleurScript
echo $res;
}
private function gameByName($name){
private function gameByName($name)
{
return Game::where("name", "like", "%{$name}%");
}
private function companyByCountry($country){
private function companyByCountry($country)
{
return Company::where("location_country", "like", "{$country}");
}
private function platformByBase($base){
private function platformByBase($base)
{
return Platform::where("install_base", ">=", "{$base}");
}
......@@ -77,17 +84,21 @@ class ControleurScript
* TD_2
*/
public function td2(){
public function td2_q1()
{
$q = $this->nameDeckByGame(12342)->get();
echo ("<p>---------------------------------------------<br>" .
echo("<p>---------------------------------------------<br>" .
"<p>(name, deck) des personnages du jeu 12342<br>" .
"<p>---------------------------------------------<br>");
foreach ($q as $item) {
echo "<p>nom :$item->name , deck : $item->deck</p>";
}
}
$q = Game::where('name','like',"Mario%")->get();
echo ("<p>---------------------------------------------<br>" .
public function td2_q2()
{
$q = Game::where('name', 'like', "Mario%")->get();
echo("<p>---------------------------------------------<br>" .
"<p>les personnages des jeux dont le nom (du jeu) débute par 'Mario<br>" .
"<p>---------------------------------------------<br>");
foreach ($q as $game) {
......@@ -96,9 +107,12 @@ class ControleurScript
foreach ($list as $char)
echo "<p>nom : $char->name</p>";
}
}
public function td2_q3()
{
$q = Company::where("name", "like", "%sony%")->get();
echo ("<p>---------------------------------------------<br>" .
echo("<p>---------------------------------------------<br>" .
"<p>les jeux développés par une compagnie dont le nom contient 'Sony<br>" .
"<p>---------------------------------------------<br>");
foreach ($q as $company) {
......@@ -107,9 +121,12 @@ class ControleurScript
foreach ($list as $game)
echo "<p>nom : $game->name</p>";
}
}
$q = Game::where('name','like',"Mario%")->get();
echo ("<p>---------------------------------------------<br>" .
public function td2_q4()
{
$q = Game::where('name', 'like', "Mario%")->get();
echo("<p>---------------------------------------------<br>" .
"<p>le rating initial (indiquer le rating board) des jeux dont le nom contient Mario<br>" .
"<p>---------------------------------------------<br>");
foreach ($q as $game) {
......@@ -118,13 +135,86 @@ class ControleurScript
foreach ($list as $rate)
echo "<p>id rating_board : $rate->rating_board_id, name : {$rate->rating_board()->first()->name}</p>";
}
}
echo ("<p>---------------------------------------------<br>" .
public function td2_q5()
{
$q = Game::where('name', 'like', "Mario%")->get();
echo("<p>---------------------------------------------<br>" .
"<p>les jeux dont le nom débute par Mario et ayant plus de 3 personnages<br>" .
"<p>---------------------------------------------<br>");
foreach ($q as $game) {
$list = $game->characters()->get();
if(count($list)>3) echo "<p>$game->name</p>";
if (count($list) > 3) echo "<p>$game->name</p>";
}
}
public function td2_q6()
{
echo("<p>---------------------------------------------<br>" .
"<p>les jeux dont le nom débute par Mario et dont le rating initial contient \"3+\"<br>" .
"<p>---------------------------------------------<br>");
$list = Game_rating::select('name')->where('name', 'like', "%3+%")->get();
foreach ($list as $rate) {
echo "<p>$rate->name</p>";
$games = $rate->games()->where('name', 'like', "Mario%")->get();
echo $games;
foreach ($games as $game) echo "<p>$game->name</p>";
}
}
public function td2_q8()
{
$tmpGames = null;
$tmpBoard = null;
echo("<p>---------------------------------------------<br>" .
"<p>les jeux dont le nom débute par Mario, publiés par une compagnie dont le nom contient \"Inc.\" et dont le rating initial contient \"3+\"<br>" .
"<p>---------------------------------------------<br>");
$list = Game_rating::select('name')->where('name', 'like', "%3+%")->get();
foreach ($list as $rate) {
echo "<p>$rate->name</p>";
$games = $rate->games()->where('name', 'like', "Mario%")->get();
echo $games;
foreach ($games as $game) if($game->developers()->where('name', 'like', '%Inc.%')->get != null) $tmpGames[] = $game;
}
$tmpBoard = Game_rating::where('name', 'like', 'CERO')->first();
if($tmpBoard!=null) $tmpBoard = $tmpBoard->games()->get();
$res = array_intersect((array)$tmpGames, (array)$tmpBoard);
foreach ($res as $games){
echo "<p> {$games->nom} </p>";
}
}
public function td2_q7()
{
echo("<p>---------------------------------------------<br>" .
"<p>les jeux dont le nom débute par Mario, publiés par une compagnie dont le nom contient \"Inc.\" et dont le rating initial contient \"3+\" t ayant reçu un avis de la part du rating board nommé \"CERO\"<br>" .
"<p>---------------------------------------------<br>");
$list = Game_rating::select('name')->where('name', 'like', "%3+%")->get();
foreach ($list as $rate) {
echo "<p>$rate->name</p>";
$games = $rate->games()->where('name', 'like', "Mario%")->get();
echo $games;
foreach ($games as $game) if($game->developers()->where('name', 'like', '%Inc.%')->get != null) echo "<p>$game->name</p>";
}
}
public function td2_q9()
{
echo "q9";
$games = Game::where('id', '=', 12)->orWhere('id', '=', 56)->orWhere('id', '=', 345)->get();
if(Genre::where('name', 'like', '')->first() == null) {
$genre = Genre::create('Hardcore', 'Hardcore is hard.','<p style="">Hardcore games where you die a lot to succed.</p>');
foreach ($games as $game){
if($game->genres()->where('id', '=', $genre->id)->first() == null) $game->genres()->attach([$genre->id]);
}
}
foreach ($games as $game) {
echo "<p>Id : $game->id : </p>";
$genres = $game->genres()->get();
foreach ($genres as $genre){
echo "<p> Cat : $genre->name</p>";
}
}
}
......
......@@ -7,6 +7,15 @@ class Genre extends \Illuminate\Database\Eloquent\Model
protected $primaryKey = 'id';
public $timestamps = false ;
public static function create($name, $deck, $desc){
$obj = new Genre();
$obj->name = $name;
$obj->deck = $deck;
$obj->description = $desc;
$obj->save();
return $obj;
}
function games(){
return $this->BelongsToMany('gp\modeles\Game', 'game2genre','genre_id');
}
......
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