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'); + } }