diff --git a/GamePedia/php/script_TD3a.php b/GamePedia/php/script_TD3a.php new file mode 100644 index 0000000000000000000000000000000000000000..33c8e7aef53fe53da1452e3ef856907bede4761a --- /dev/null +++ b/GamePedia/php/script_TD3a.php @@ -0,0 +1,35 @@ +<?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 diff --git a/GamePedia/src/controleurs/ControleurScript.php b/GamePedia/src/controleurs/ControleurScript.php index a45822c9f39c63176e3ea957d4c25abced85c761..bdf532e94ab30cc7d14e067276077f8600c515df 100644 --- a/GamePedia/src/controleurs/ControleurScript.php +++ b/GamePedia/src/controleurs/ControleurScript.php @@ -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 diff --git a/GamePedia/src/modeles/Character.php b/GamePedia/src/modeles/Character.php index 2daad7f86e25b22cebb0d39393893effee6c3283..be7725bce2456fc4597b509b6f1bf2b40f0dcba3 100644 --- a/GamePedia/src/modeles/Character.php +++ b/GamePedia/src/modeles/Character.php @@ -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 diff --git a/GamePedia/src/modeles/Client.php b/GamePedia/src/modeles/Client.php deleted file mode 100644 index ec48fcd9762810034ad2068d49028e5b36576aaa..0000000000000000000000000000000000000000 --- a/GamePedia/src/modeles/Client.php +++ /dev/null @@ -1,9 +0,0 @@ -<?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 diff --git a/GamePedia/src/modeles/Company.php b/GamePedia/src/modeles/Company.php index 0d7ed575cb86defbef5e6470069f3bb829573120..c2bdaac7913fb21d25454b4cc33d5581fa31c6ac 100644 --- a/GamePedia/src/modeles/Company.php +++ b/GamePedia/src/modeles/Company.php @@ -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'); + } } diff --git a/GamePedia/src/modeles/Game.php b/GamePedia/src/modeles/Game.php index 2d8743e77a9e776d1af2cfe5dec2c437cd1314ff..11f8781d33e2cc9039eae521176a9f74aca4ee02 100644 --- a/GamePedia/src/modeles/Game.php +++ b/GamePedia/src/modeles/Game.php @@ -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'); diff --git a/GamePedia/src/modeles/Game_rating.php b/GamePedia/src/modeles/Game_rating.php new file mode 100644 index 0000000000000000000000000000000000000000..b6915dcf445d686ee601500e2c9729f2a7b0ee72 --- /dev/null +++ b/GamePedia/src/modeles/Game_rating.php @@ -0,0 +1,56 @@ +<?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); + } +} diff --git a/GamePedia/src/modeles/Genre.php b/GamePedia/src/modeles/Genre.php index da686bafc63340bd9936e74903001a032de8c4e0..1f9253d6604d4eb43e03d44455cad0b1be4ee327 100644 --- a/GamePedia/src/modeles/Genre.php +++ b/GamePedia/src/modeles/Genre.php @@ -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 diff --git a/GamePedia/src/modeles/Platform.php b/GamePedia/src/modeles/Platform.php index 93fd3e935a6f5c58fd656358b489729b368b7cb3..61bcc643975686eedd2e50ba93a53cdaa4cfb876 100644 --- a/GamePedia/src/modeles/Platform.php +++ b/GamePedia/src/modeles/Platform.php @@ -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 diff --git a/GamePedia/src/modeles/Rating_board.php b/GamePedia/src/modeles/Rating_board.php new file mode 100644 index 0000000000000000000000000000000000000000..63d99cbfbffbff7dfee7ec21fe223bdb4bd60262 --- /dev/null +++ b/GamePedia/src/modeles/Rating_board.php @@ -0,0 +1,15 @@ +<?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 diff --git a/GamePedia/src/modeles/Theme.php b/GamePedia/src/modeles/Theme.php index 3828bb45db07cbc3171ef8a1c1deb802276c9a75..cd33370163cba06f69e373b41655bd4247549a30 100644 --- a/GamePedia/src/modeles/Theme.php +++ b/GamePedia/src/modeles/Theme.php @@ -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'); + } }