From 4ab0ff36daea0e0316a7df20d41a7b8b9618a7a9 Mon Sep 17 00:00:00 2001 From: SASSU Thomas <thomas.sassu5@etu.univ-lorraine.fr> Date: Thu, 19 Mar 2020 21:00:36 +0100 Subject: [PATCH] script td4a --- GamePedia/php/script_TD4a.php | 67 ++++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 17 deletions(-) diff --git a/GamePedia/php/script_TD4a.php b/GamePedia/php/script_TD4a.php index 6cb4be7..89f8549 100644 --- a/GamePedia/php/script_TD4a.php +++ b/GamePedia/php/script_TD4a.php @@ -1,12 +1,12 @@ <?php require_once dirname (__DIR__) . '/vendor/autoload.php'; -session_start(); -use \Slim\Slim as Slim; +use gp\modeles\Comment; +use gp\modeles\Game; +use gp\modeles\User; use Illuminate\Database\Capsule\Manager as DB; -use \gp\controleurs\ControleurPrincipal as ControleurPrincipal; -use \gp\controleurs\ControleurScript as ControleurScript; +use Faker; $db = new DB(); $db->addConnection(parse_ini_file('../conf/conf.ini')); @@ -14,16 +14,49 @@ $db->addConnection(parse_ini_file('../conf/conf.ini')); $db->setAsGlobal(); $db->bootEloquent(); -$db::table('user')->insert( - [], - [] -); - -$db::table('comment')->insert( - [], - [], - [], - [], - [], - [] -); \ No newline at end of file +// use the factory to create a Faker\Generator instance +$faker = Faker\Factory::create(); +if(User::first()== null){ + //all users + for($i=0; $i<2; $i++) { + $insert = false; + while (!$insert) { + try { + //fake data + $tmp = explode(' ', $faker->name); + $user['fname'] = $tmp[0]; + $user['name'] = $tmp[1]; + $user['address'] = $faker->address; + $user['email'] = $faker->email; + $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::first()== null){ + //all comments + $users = User::get(); + $game = Game::where('id', '=', 12342)->first(); + foreach($users as $user){ + $insert = false; + while (!$insert) { + try { + //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 -- GitLab