Skip to content
Snippets Groups Projects
Commit 5ff94713 authored by SASSU Thomas's avatar SASSU Thomas
Browse files

merge

parents b371a21e b71ff518
Branches
No related tags found
No related merge requests found
<?php
require_once dirname (__DIR__) . '/vendor/autoload.php';
session_start();
use \Slim\Slim as Slim;
use Illuminate\Database\Capsule\Manager as DB;
use \gp\controleurs\ControleurPrincipal as ControleurPrincipal;
use \gp\controleurs\ControleurScript as ControleurScript;
$db = new DB();
$db->addConnection(parse_ini_file('../conf/conf.ini'));
$db->setAsGlobal();
$db->bootEloquent();
echo ("<!DOCTYPE html>
<html>
<body>
<div>
<h1> Script TD3 </h1>
<h2> Consignes : </h2>
<p> Pour chaque requête, calculer le temps d'execution </p>
</div>");
$c = new ControleurScript();
echo $c->allGame();
echo '<br>';
echo $c->gameMario();
echo '<br>';
echo $c->gameDebMario();
echo '<br>';
echo $c->gameDebMarioRate();
echo ("</body> </html>");
\ No newline at end of file
......@@ -83,6 +83,7 @@ class ControleurScript
* TD_2
*/
public function td2_q1()
{
$q = $this->nameDeckByGame(12342)->get();
......@@ -189,7 +190,7 @@ class ControleurScript
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();
$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();
......@@ -220,6 +221,7 @@ class ControleurScript
private function nameDeckByGame($id){
return Game::where('id','=',$id)->first()->characters();
}
/*-------------------------------------------------------------------
* TD3 PART II
* ------------------------------------------------------------------
......@@ -276,4 +278,39 @@ class ControleurScript
public function td3_q5b(){
return Company::where('name','like', '%Sony%')->get()->games();
}
public function allGame(){
$time_start = microtime(true);
Game::get();
$time_end = microtime(true);
$time = $time_end - $time_start;
return $time;
}
public function gameMario(){
$time_start = microtime(true);
Game::where('name', 'like', "%Mario%")->get();
$time_end = microtime(true);
$time = $time_end - $time_start;
return $time;
}
public function gameDebMario(){
$time_start = microtime(true);
$q= Game::where('name', 'like', "Mario%")->get();
foreach ($q as $game) {
$game->characters()->get();
}
$time_end = microtime(true);
$time = $time_end - $time_start;
return $time;
}
public function gameDebMarioRate(){
$time_start = microtime(true);
Game_rating::select('name')->where('name', 'like', '%3+%')->get();
$time_end = microtime(true);
$time = $time_end - $time_start;
return $time;
}
}
\ No newline at end of file
......@@ -8,6 +8,6 @@ class Character extends \Illuminate\Database\Eloquent\Model
public $timestamps = false ;
function games(){
return $this->BelongsToMany('gp\modeles\Game', 'game2character','character_id');
return $this->BelongsToMany('gp\modeles\Game', 'game2character','character_id', 'game_id');
}
}
\ No newline at end of file
<?php
namespace gp\modeles;
class Client extends \Illuminate\Database\Eloquent\Model
{
protected $table = 'client';
protected $primaryKey = 'idCli';
public $timestamps = false ;
}
\ No newline at end of file
......@@ -5,4 +5,8 @@ class Company extends \Illuminate\Database\Eloquent\Model
protected $table = 'company';
protected $primaryKey='id';
public $timestamps = false;
function games(){
return $this->BelongsToMany('gp\modeles\Game', 'game_developers','comp_id');
}
}
......@@ -10,17 +10,17 @@ class Game extends \Illuminate\Database\Eloquent\Model
public function characters(){
return $this->belongsToMany('gp\modeles\Character', 'game2character','game_id');
}
public function platform(){
public function platforms(){
return $this->belongsToMany('gp\modeles\Platform', 'game2platform','game_id');
}
public function theme(){
public function themes(){
return $this->belongsToMany('gp\modeles\Theme', 'game2theme','game_id');
}
public function genre(){
public function genres(){
return $this->belongsToMany('gp\modeles\Genre', 'game2genre','game_id');
}
public function rating(){
return $this->belongsToMany('gp\modeles\Rating', 'game2rating','game_id');
public function ratings(){
return $this->belongsToMany('gp\modeles\Game_rating', 'game2rating','game_id','rating_id');
}
public function publishers(){
return $this->belongsToMany('gp\modeles\Company', 'game_publishers','game_id');
......
<?php
namespace gp\modeles;
use Illuminate\Database\Eloquent\Builder;
class Game_rating extends \Illuminate\Database\Eloquent\Model
{
protected $table = 'game_rating';
protected $primaryKey ='id';
public $timestamps = false;
public $incrementing = false;
function games(){
return $this->BelongsToMany('gp\modeles\Game', 'game2rating','rating_id');
}
function rating_board(){
return $this->BelongsTo('gp\modeles\Rating_board', 'rating_board_id');
}
/**
* Set the keys for a save update query.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
protected function setKeysForSaveQuery(Builder $query)
{
$keys = $this->getKeyName();
if(!is_array($keys)){
return parent::setKeysForSaveQuery($query);
}
foreach($keys as $keyName){
$query->where($keyName, '=', $this->getKeyForSaveQuery($keyName));
}
return $query;
}
/**
* Get the primary key value for a save query.
*
* @param mixed $keyName
* @return mixed
*/
protected function getKeyForSaveQuery($keyName = null)
{
if(is_null($keyName)){
$keyName = $this->getKeyName();
}
if (isset($this->original[$keyName])) {
return $this->original[$keyName];
}
return $this->getAttribute($keyName);
}
}
......@@ -6,4 +6,17 @@ class Genre extends \Illuminate\Database\Eloquent\Model
protected $table = 'genre';
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');
}
}
\ No newline at end of file
......@@ -6,4 +6,8 @@ class Platform extends \Illuminate\Database\Eloquent\Model
protected $table = 'platform';
protected $primaryKey = 'id';
public $timestamps = false ;
function games(){
return $this->BelongsToMany('gp\modeles\Game', 'game2platform','platform_id');
}
}
\ No newline at end of file
<?php
namespace gp\modeles;
use Illuminate\Database\Eloquent\Builder;
class Rating_board extends \Illuminate\Database\Eloquent\Model
{
protected $table = 'rating_board';
protected $primaryKey ='id';
public $timestamps = false;
function rating_board(){
return $this->hasMany('gp\modeles\Game_rating', 'id');
}
}
\ No newline at end of file
......@@ -5,4 +5,8 @@ class Theme extends \Illuminate\Database\Eloquent\Model
protected $table = 'theme';
protected $primaryKey ='id';
public $timestamps = false;
function games(){
return $this->BelongsToMany('gp\modeles\Game', 'game2theme','theme_id');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment