Commit 6e4b57bd authored by KELBERT Paul's avatar KELBERT Paul
Browse files

seance 4

parent 4a0cfb94
<?php
use Illuminate\Database\Capsule\Manager as DB;
use seance\modele\Commentary;
use seance\modele\User;
require 'vendor/autoload.php';
$file = parse_ini_file('conf.ini');
$db = new DB();
$db->addConnection($file);
$db->setAsGlobal();
$db->bootEloquent();
//$u = new User();
//$u->nom = 'Ducon';
//$u->prenom = 'Christian';
//$u->email = 'christianducon@gmail.com';
//$u->adresse_detaillee = '11 allée des abricots, nancy';
//$u->dateNaiss = '2007-12-12 00:00';
//$u->save();
//
//
//
//$u2 = new User();
//$u2->nom = 'Cruz-Lara';
//$u2->prenom = 'Damien';
//$u2->email = 'damiencruzlara@yahoo.com';
//$u2->adresse_detaillee = '31 boulevard allédesjoyeux, Amsterdam';
//$u2->dateNaiss = '2000-09-11 00:00';
//$u2->save();
$c = new Commentary();
$c->titre = 'jeu trop b1 !';
$c->contenu = 'ce jeu est vraiment trop cool, j\'y ai passé bcp de temps, depuis je ne supporte plus le soleil.';
$c->dateCreation = '2019-01-01 00:00';
$c->jeuConcerne = 12342;
$c->userID = 1;
$c->save();
$c2 = new Commentary();
$c2->titre = 'jeu trop b1 2ieme du nom !';
$c2->contenu = 'ce jeu est vraiment trop cool, j\'y ai passé bcp de temps, depuis je ne supporte plus le soleil. 2ieme du nom';
$c2->dateCreation = '2019-01-02 00:00';
$c2->jeuConcerne = 12342;
$c2->userID = 1;
$c2->save();
$c3 = new Commentary();
$c3->titre = 'jeu trop b1 3ieme du nom !';
$c3->contenu = 'ce jeu est vraiment trop cool, j\'y ai passé bcp de temps, depuis je ne supporte plus le soleil. 3ieme du nom';
$c3->dateCreation = '2019-01-03 00:00';
$c3->jeuConcerne = 12342;
$c3->userID = 1;
$c3->save();
$c4 = new Commentary();
$c4->titre = 'coucou';
$c4->contenu = 'coucou';
$c4->dateCreation = '2019-01-05 00:00';
$c4->jeuConcerne = 12342;
$c4->userID = 2;
$c4->save();
$c6 = new Commentary();
$c6->titre = 'coucou 2';
$c6->contenu = 'coucou 2';
$c6->dateCreation = '2019-01-06 00:00';
$c6->jeuConcerne = 12342;
$c6->userID = 2;
$c6->save();
$c5 = new Commentary();
$c5->titre = 'coucou 3';
$c5->contenu = 'coucou 3';
$c5->dateCreation = '2019-01-06 00:00';
$c5->jeuConcerne = 12342;
$c5->userID = 2;
$c5->save();
echo 'tout les commentaires et user ont été ajoutés !';
\ No newline at end of file
<?php
use Illuminate\Database\Capsule\Manager as DB;
use seance\modele\Commentary;
use seance\modele\User;
require 'vendor/autoload.php';
$file = parse_ini_file('conf.ini');
$db = new DB();
$db->addConnection($file);
$db->setAsGlobal();
$db->bootEloquent();
$faker = Faker\Factory::create('fr_FR');
for ($i = 0; $i < 2500; $i++) {
$user = new User;
$user->nom = $faker->lastName;
$user->prenom = $faker->firstName;
$user->email = $faker->unique()->email;
$user->adresse_detaillee = $faker->address;
$user->dateNaiss = $faker->dateTimeThisCentury->format('Y-m-d');
$user->save();
}
for($l = 0; $l<30000; $l++){
$c = new Commentary();
$c->titre = $faker->title;
$c->contenu = $faker->sentence;
$c->dateCreation = $faker->dateTimeThisCentury->format('Y-m-d');
$c->userID = rand(1,2490);
$c->jeuConcerne = rand(1, 47940);
$c->save();
}
echo "fini (limitation à 30k commentaires pour éviter erreur fatale de temps d'exécution";
\ No newline at end of file
<?php
use Illuminate\Database\Capsule\Manager as DB;
require 'vendor/autoload.php';
new \seance\reponse\CQuestion3();
<?php
use Illuminate\Database\Capsule\Manager as DB;
require 'vendor/autoload.php';
new \seance\reponse\CQuestion4();
{
"require":{
"illuminate/database": "5.5.*",
"php": ">=7.3",
"fzaninotto/faker": "^1.9"
},
"autoload":{
"psr-4": {
"seance\\" : "src/"
}
}
}
This diff is collapsed.
driver=mysql
username=root
password=
host=localhost
database=applibd
\ No newline at end of file
<?php
require 'vendor/autoload.php';
use seance\modele\Game;
echo "<h1>PARTIE 1</h1>";
echo "<a href='Question1.php'>question 1 -- script ajoutant les personnes et les commentaires</a><br>";
echo "<a href='Question2.php'>question 2 -- ajout de 2500 users et 250000 commentaires (long)</a><br>";
echo "<a href='Question3.php'>question 3 -- lister les commentaires d'un utilisateur donné, afficher la date du commentaire de façon lisible, ordonnés par date décroissante</a><br>";
echo "<a href='Question4.php'>question 4 -- lister les utilisateurs ayant posté plus de 5 commentaires.</a><br>";
This diff is collapsed.
<?php
namespace seance\modele;
class Character extends \Illuminate\Database\Eloquent\Model
{
protected $table = 'character';
protected $primaryKey = 'id';
public $timestamps = false;
public function first_appeared_in_game(){
return $this->belongsTo('seance\modele\Game', 'id');
}
public function appears_in(){
return $this->belongsToMany('seance\modele\Game', 'game2character', 'character_id', 'game_id');
}
public function enemies(){
return $this->belongsToMany('seance\modele\Character', 'enemies', 'char1_id', 'char2_id');
}
public function friends(){
return $this->belongsToMany('seance\modele\Character', 'friends', 'char1_id', 'char2_id');
}
}
\ No newline at end of file
<?php
namespace seance\modele;
class Commentary extends \Illuminate\Database\Eloquent\Model
{
protected $table = 'commentary';
protected $primaryKey = 'id';
public $timestamps = false;
public function commentaires(){
return $this->belongsTo('seance\modele\User', 'id');
}
public function commente(){
return $this->belongsTo('seance\modele\Game', 'id');
}
}
\ No newline at end of file
<?php
namespace seance\modele;
class Company extends \Illuminate\Database\Eloquent\Model
{
protected $table = 'company';
protected $primaryKey = 'id';
public $timestamps = false;
public function developers(){
return $this->belongsToMany('seance\modele\Game', 'game_developers', 'comp_id', 'game_id');
}
public function publishers(){
return $this->belongsToMany('seance\modele\Game', 'game_publishers', 'comp_id', 'game_id');
}
public function producer(){
return $this->hasMany('seance\modele\Platform', 'id');
}
}
\ No newline at end of file
<?php
namespace seance\modele;
class Game extends \Illuminate\Database\Eloquent\Model
{
protected $table = 'game';
protected $primaryKey = 'id';
public $timestamps = false;
public function appears_in(){
return $this->belongsToMany('seance\modele\Character', 'game2character', 'game_id', 'character_id');
}
public function first_appeared_in_game(){
return $this->hasMany('seance\modele\Character', 'id');
}
public function simular_games(){
return $this->belongsToMany('seance\modele\Game', 'similar_games', 'game1_id', 'game2_id');
}
public function developers(){
return $this->belongsToMany('seance\modele\Company', 'game_developers', 'game_id', 'comp_id');
}
public function publishers(){
return $this->belongsToMany('seance\modele\Company', 'game_publishers', 'game_id', 'comp_id');
}
public function original_game_ratings(){
return $this->belongsToMany('seance\modele\Game_Rating', "game2rating", 'game_id', 'rating_id');
}
public function game2genre(){
return $this->belongsToMany('seance\modele\Genre', 'game2genre', 'game_id', 'genre_id');
}
public function game2theme(){
return $this->belongsToMany('seance\modele\Theme', 'game2theme', 'game_id', 'theme_id');
}
public function game2platform(){
return $this->belongsToMany('seance\modele\Platform', 'game2platform', 'game_id', 'platform_id');
}
public function commente(){
return $this->hasMany('seance\modele\Commentary', 'id');
}
}
\ No newline at end of file
<?php
namespace seance\modele;
class Game_Rating extends \Illuminate\Database\Eloquent\Model
{
protected $table = 'game_rating';
protected $primaryKey = 'id';
public $timestamps = false;
protected $fillable = [
"name",
"rating_board_id"
];
public function original_game_ratings(){
return $this->belongsToMany('seance\modele\Game', "game2rating", 'rating_id', 'game_id');
}
public function gameR2ratB(){
return $this->belongsTo('seance\modele\Rating_Board', 'id');
}
}
\ No newline at end of file
<?php
namespace seance\modele;
class Genre extends \Illuminate\Database\Eloquent\Model
{
protected $table = 'genre';
protected $primaryKey = 'id';
public $timestamps = false;
public function game2genre(){
return $this->belongsToMany('seance\modele\Game', 'game2genre', 'genre_id', 'game_id');
}
}
\ No newline at end of file
<?php
namespace seance\modele;
class Platform extends \Illuminate\Database\Eloquent\Model
{
protected $table = 'platform';
protected $primaryKey = 'id';
public $timestamps = false;
public function producer(){
return $this->belongsTo('seance\modele\Company', 'id');
}
public function game2platform(){
return $this->belongsToMany('seance\modele\Game', 'game2platform', 'platform_id', 'game_id');
}
}
\ No newline at end of file
<?php
namespace seance\modele;
class Rating_Board extends \Illuminate\Database\Eloquent\Model
{
protected $table = 'rating_board';
protected $primaryKey = 'id';
public $timestamps = false;
public function gameR2ratB(){
return $this->hasMany('seance\modele\Game_Rating', 'id');
}
}
\ No newline at end of file
<?php
namespace seance\modele;
class Theme extends \Illuminate\Database\Eloquent\Model
{
protected $table = 'theme';
protected $primaryKey = 'id';
public $timestamps = false;
public function game2theme(){
return $this->belongsToMany('seance\modele\Game', 'game2theme', 'theme_id', 'game_id');
}
}
\ No newline at end of file
<?php
namespace seance\modele;
class User extends \Illuminate\Database\Eloquent\Model
{
protected $table = 'user';
protected $primaryKey = 'id';
public $timestamps = false;
public function commentaires(){
return $this->hasMany('seance\modele\Commentary', 'userID');
}
// public function first_appeared_in_game(){
// return $this->belongsTo('seance\modele\Game', 'id');
// }
//
// public function appears_in(){
// return $this->belongsToMany('seance\modele\Game', 'game2character', 'character_id', 'game_id');
// }
//
//
// public function enemies(){
// return $this->belongsToMany('seance\modele\Character', 'enemies', 'char1_id', 'char2_id');
// }
// public function friends(){
// return $this->belongsToMany('seance\modele\Character', 'friends', 'char1_id', 'char2_id');
// }
}
\ No newline at end of file
<?php
namespace seance\reponse;
use Illuminate\Database\Capsule\Manager as DB;
use seance\modele\User;
class CQuestion3
{
public function __construct()
{
echo "<a href='index.php'>Retour au menu</a><br><br>";
$file = parse_ini_file('conf.ini');
$db = new DB();
$db->addConnection($file);
$db->setAsGlobal();
$db->bootEloquent();
$user = User::where('id', '=', 2)->first();
$com = $user->commentaires;
echo "Commentaires de : " . $user->nom . " " . $user->prenom ."<br><br>";
foreach ($com as $c){
echo $c->id . " || " . $c->dateCreation . '<br>';
}
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment