diff --git a/GamePedia/php/script_TD1.php b/GamePedia/php/script_TD1.php index ce837f8d415c73cab1d33fde7390a73286f0410a..1615d71e9678ca42e3c264f75c568504766f3102 100644 --- a/GamePedia/php/script_TD1.php +++ b/GamePedia/php/script_TD1.php @@ -1,7 +1,6 @@ <?php -require_once __DIR__ . '../vendor/autoload.php'; -session_start(); +require_once dirname (__DIR__) . '../vendor/autoload.php'; use \Slim\Slim as Slim; use Illuminate\Database\Capsule\Manager as DB; diff --git a/GamePedia/src/controleurs/ControleurScript.php b/GamePedia/src/controleurs/ControleurScript.php index 2a108492c70717d03dff9910622cb1f506366011..b1568639b5f7eef5e9c480054fa133959a9c9492 100644 --- a/GamePedia/src/controleurs/ControleurScript.php +++ b/GamePedia/src/controleurs/ControleurScript.php @@ -82,9 +82,40 @@ class ControleurScript echo ("<p>---------------------------------------------<br>" . "<p>(name, deck) des personnages du jeu 12342<br>" . "<p>---------------------------------------------<br>"); - foreach ($q1 as $item) { - echo "<p>nom :$q1->name , deck : $q1->deck</p>"; + echo "<p>nom :$item->name , deck : $item->deck</p>"; + } + + $q2 = 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 ($q2 as $game) { + echo "<p>Characters from :$game->name</p>"; + $list = $game->characters()->get(); + foreach ($list as $char) + echo "<p>nom : $char->name</p>"; + } + + $q3 = Company::where("name", "like", "%sony%")->get(); + echo ("<p>---------------------------------------------<br>" . + "<p>les jeux développés par une compagnie dont le nom contient 'Sony<br>" . + "<p>---------------------------------------------<br>"); + foreach ($q3 as $company) { + echo "<p>Games from :$company->name</p>"; + $list = $company->games()->get(); + foreach ($list as $game) + echo "<p>nom : $game->name</p>"; + } + + $q2 = 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 ($q2 as $game) { + $list = $game->ratings()->get(); + foreach ($list as $rate) + echo "<p>id rating_board : $rate->rating_board_id, name : {$rate->rating_boards()->first()->name}</p>"; } } diff --git a/GamePedia/src/modeles/Company.php b/GamePedia/src/modeles/Company.php index b5324928311bd353c716e0d652f4dbc1ca4f5031..c2bdaac7913fb21d25454b4cc33d5581fa31c6ac 100644 --- a/GamePedia/src/modeles/Company.php +++ b/GamePedia/src/modeles/Company.php @@ -7,6 +7,6 @@ class Company extends \Illuminate\Database\Eloquent\Model public $timestamps = false; function games(){ - return $this->BelongsToMany('gp\modeles\Game', 'game2company','company_id'); + 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..1743136d9724f0260b0d39786592813cbf4b9763 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'); } 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 index d11d362b79eeb38029b6f9dd693bb5b75ff61598..acdc7ecf1916f0bc97ffb7e8af9ef36d5484b95b 100644 --- a/GamePedia/src/modeles/Game_rating.php +++ b/GamePedia/src/modeles/Game_rating.php @@ -3,14 +3,53 @@ namespace gp\modeles; class Game_rating extends \Illuminate\Database\Eloquent\Model { protected $table = 'game_rating'; - protected $primaryKey ='id'; + protected $primaryKey =['id', 'rating_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', 'id'); + 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); } }