Skip to content
Snippets Groups Projects
Commit ad24aa9e authored by SASSU Thomas's avatar SASSU Thomas
Browse files

script faker fix

parent 9a9ba323
Branches
No related tags found
No related merge requests found
...@@ -12,6 +12,7 @@ use gp\modeles\Game; ...@@ -12,6 +12,7 @@ use gp\modeles\Game;
use gp\modeles\Company; use gp\modeles\Company;
use gp\modeles\Character; use gp\modeles\Character;
use gp\modeles\Rating_board; use gp\modeles\Rating_board;
use Faker;
class ControleurScript class ControleurScript
{ {
...@@ -355,36 +356,53 @@ class ControleurScript ...@@ -355,36 +356,53 @@ class ControleurScript
public function generation(){ public function generation(){
// use the factory to create a Faker\Generator instance // use the factory to create a Faker\Generator instance
$faker = Faker\Factory::create(); $faker = Faker\Factory::create();
if(User::take(50)== null){ if(User::first()== null){
//all users //all users
for($i=0; i<25000; $i++){ for($i=0; $i<10; $i++) {
//fake data $insert = false;
$tmp = $faker->name.split(' '); while (!$insert) {
$user['fname'] = $tmp[0]; try {
$user['name'] = $tmp[1]; //fake data
$user['adress'] = $faker->adress; $tmp = explode(' ', $faker->name);
$user['email'] = $faker->email; $user['fname'] = $tmp[0];
$user['tel'] = $faker->e164PhoneNumber; $user['name'] = $tmp[1];
$user['date'] = $faker->date('Y-m-d','2005-01-01'); $user['address'] = $faker->address;
//insert $user['email'] = $faker->email;
User::create($user['fname'], $user['name'], $user['email'], $user['adress'], $user['tel'], $user['date']); $user['tel'] = $faker->e164PhoneNumber;
$user['date'] = $faker->date('Y-m-d', '2005-01-01');
//insert
User::create($user['fname'], $user['name'], $user['email'], $user['address'], $user['tel'], $user['date']);
$insert = true;
} catch (PDOException $Exception) {
echo("Duplicate data : recreating new fake");
}
}
} }
} }
if(Comment::take(50)== null){ if(Comment::first()== null){
//all comments //all comments
for($i=0; i<250000; $i++){ for($i=0; $i<100; $i++){
//random user $insert = false;
$user = User::all()->random(1)->first(); while (!$insert) {
//random game try {
$game = Game::all()->random(1)->first(); $id_user = random_int(0, 9);
//fake data $id_game = random_int(0, 9);
$title = $faker->text(50); //random user
$content = $faker->text(200); $user = User::skip($id_user)->take(1)->first();
$date = $faker->date('Y-m-d', '2015-02-01'); //random game
//insert comment $game = Game::skip($id_game)->take(1)->first();
Comment::create($game->id, $user->email, $title, $content, $date); //fake data
$title = $faker->text(50);
$content = $faker->text(200);
$date = $faker->date('Y-m-d', '2015-02-01');
//insert comment
Comment::create($game->id, $user->email, $title, $content, $date);
$insert = true;
} catch (PDOException $Exception) {
echo("Duplicate data : recreating new fake");
}
}
} }
} }
} }
} }
\ No newline at end of file
...@@ -10,15 +10,19 @@ class Comment extends \Illuminate\Database\Eloquent\Model ...@@ -10,15 +10,19 @@ class Comment extends \Illuminate\Database\Eloquent\Model
public static function create($id_game, $email, $title, $content, $createdAt){ public static function create($id_game, $email, $title, $content, $createdAt){
$obj = new Comment(); $obj = new Comment();
$obj->email = $email; $obj->email = $email;
$obj->id_game =$id_game;
$obj->title = $title; $obj->title = $title;
$obj->content = $content; $obj->content = $content;
$obj->createdAt = $createdAt; $obj->created_at = $createdAt;
$obj->updated_at = $createdAt;
$obj->save(); $obj->save();
Game::where('id', '=', $id_game)->first()->comments()->attach([$id_game]);
return $obj; return $obj;
} }
function games(){ function game(){
return $this->BelongsToMany('gp\modeles\Game', 'game2comment','comment_id'); return $this->BelongsTo('gp\modeles\Game','id_game');
}
function user(){
return $this->BelongsTo('gp\modeles\User', 'email');
} }
} }
\ No newline at end of file
...@@ -7,19 +7,19 @@ class User extends \Illuminate\Database\Eloquent\Model ...@@ -7,19 +7,19 @@ class User extends \Illuminate\Database\Eloquent\Model
protected $primaryKey = 'id'; protected $primaryKey = 'id';
public $timestamps = false ; public $timestamps = false ;
public static function create($fname, $name, $email, $adress, $numtel, $date){ public static function create($fname, $name, $email, $address, $numtel, $date){
$obj = new User(); $obj = new User();
$obj->name = $name; $obj->name = $name;
$obj->fname = $fname; $obj->first_name = $fname;
$obj->email = $email; $obj->email = $email;
$obj->adress = $adress; $obj->address = $address;
$obj->numtel = $numtel; $obj->phone = $numtel;
$obj->date = $date; $obj->dateNaiss = $date;
$obj->save(); $obj->save();
return $obj; return $obj;
} }
function games(){ function comments(){
return $this->BelongsToMany('gp\modeles\Game', 'game2genre','genre_id'); return $this->hasMany('gp\modeles\Comment', 'email');
} }
} }
\ No newline at end of file
-- --------------------------------------------------------
--
-- Structure de la table `User`
--
DROP TABLE IF EXISTS `user`;
CREATE TABLE IF NOT EXISTS `user` (
`email` varchar(50) NOT NULL,
`name` varchar(50),
`first_name` varchar(50),
`address` varchar(200),
`phone` varchar(30),
`dateNaiss` date,
PRIMARY KEY (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Structure de la table `Comment`
--
DROP TABLE IF EXISTS `comment`;
CREATE TABLE IF NOT EXISTS `comment` (
`id` int(14) NOT NULL AUTO_INCREMENT,
`email` varchar(50) NOT NULL,
`id_game` int(14) NOT NULL,
`title` varchar(50),
`content` text,
`created_at` date,
`updated_at` date,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment