From b71ff518740b9b27e2aeee289929e058a7f43e4c Mon Sep 17 00:00:00 2001 From: Cahit PERCIN <cahit.percin7@etu.univ-lorraine.fr> Date: Wed, 11 Mar 2020 10:52:27 +0100 Subject: [PATCH] ajout modeles --- GamePedia/src/modeles/Character.php | 2 +- GamePedia/src/modeles/Client.php | 9 ----- GamePedia/src/modeles/Company.php | 4 ++ GamePedia/src/modeles/Game.php | 10 ++--- GamePedia/src/modeles/Game_rating.php | 56 ++++++++++++++++++++++++++ GamePedia/src/modeles/Genre.php | 13 ++++++ GamePedia/src/modeles/Platform.php | 4 ++ GamePedia/src/modeles/Rating_board.php | 15 +++++++ GamePedia/src/modeles/Theme.php | 4 ++ 9 files changed, 102 insertions(+), 15 deletions(-) delete mode 100644 GamePedia/src/modeles/Client.php create mode 100644 GamePedia/src/modeles/Game_rating.php create mode 100644 GamePedia/src/modeles/Rating_board.php diff --git a/GamePedia/src/modeles/Character.php b/GamePedia/src/modeles/Character.php index 2daad7f..be7725b 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 ec48fcd..0000000 --- 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 0d7ed57..c2bdaac 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 2d8743e..11f8781 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 0000000..b6915dc --- /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 da686ba..1f9253d 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 93fd3e9..61bcc64 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 0000000..63d99cb --- /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 3828bb4..cd33370 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'); + } } -- GitLab