Added seeders for members-states and person targets.
This commit is contained in:
@@ -12,36 +12,12 @@ class TestMemberStatesTableSeeder extends Seeder
|
|||||||
*/
|
*/
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
/*DB::table('member_states')->insert([
|
|
||||||
[
|
|
||||||
'person_id' => 1,
|
|
||||||
'joining_date' => '2014-9-22',
|
|
||||||
'leaving_date' => '2014-12-31',
|
|
||||||
'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
|
|
||||||
'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'person_id' => 1,
|
|
||||||
'joining_date' => '2015-1-1',
|
|
||||||
'leaving_date' => null,
|
|
||||||
'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
|
|
||||||
'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'person_id' => 2,
|
|
||||||
'joining_date' => '2014-9-22',
|
|
||||||
'leaving_date' => null,
|
|
||||||
'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
|
|
||||||
'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
|
|
||||||
]
|
|
||||||
]);*/
|
|
||||||
|
|
||||||
// Iterate through existing People and randomly assign their ids
|
// Iterate through existing People and randomly assign their ids
|
||||||
// once or twice.
|
// once or twice.
|
||||||
foreach (App\Person::all() as $person) {
|
foreach (App\Person::all() as $person) {
|
||||||
|
|
||||||
// randomly decide if person has a state.
|
// randomly decide if person has a state.
|
||||||
$personHasState = rand(1,8) < 8;
|
$personHasState = rand_bool(88);
|
||||||
|
|
||||||
if($personHasState) {
|
if($personHasState) {
|
||||||
// if Person has a State, decide if it has one or two.
|
// if Person has a State, decide if it has one or two.
|
||||||
@@ -58,14 +34,14 @@ class TestMemberStatesTableSeeder extends Seeder
|
|||||||
|
|
||||||
public function createPerson($id, $numberOfStates = 1)
|
public function createPerson($id, $numberOfStates = 1)
|
||||||
{
|
{
|
||||||
// manually create faker Instance since you can't control iterations
|
// Manually create faker Instance since you can't control iterations
|
||||||
// in Factory-Files.
|
// in Factory-Files.
|
||||||
$faker = Faker\Factory::create();
|
$faker = Faker\Factory::create();
|
||||||
|
|
||||||
$startDate = "2014-04-01";
|
$startDate = "2014-04-01";
|
||||||
|
|
||||||
if($numberOfStates > 1) {
|
if($numberOfStates > 1) {
|
||||||
// if member has 2 states, the first one must be a few years in the past.
|
// If member has 2 states, the first one must be a few years in the past.
|
||||||
$lastLeaving = "2015-12-30";
|
$lastLeaving = "2015-12-30";
|
||||||
$firstSecondJoiningDate = "2017-06-01";
|
$firstSecondJoiningDate = "2017-06-01";
|
||||||
|
|
||||||
@@ -73,9 +49,9 @@ class TestMemberStatesTableSeeder extends Seeder
|
|||||||
$firstLeavingDate = $faker->dateTimeBetween($firstJoiningDate, $lastLeaving);
|
$firstLeavingDate = $faker->dateTimeBetween($firstJoiningDate, $lastLeaving);
|
||||||
|
|
||||||
$secondJoiningDate = $faker->dateTimeBetween($firstSecondJoiningDate, 'now');
|
$secondJoiningDate = $faker->dateTimeBetween($firstSecondJoiningDate, 'now');
|
||||||
$secondLeavingDate = NULL;
|
$secondLeavingDate = null;
|
||||||
if(rand(1,8) === 8)
|
|
||||||
{
|
if (rand_bool(12)) {
|
||||||
$secondLeavingDate = $faker->dateTimeBetween($secondJoiningDate, 'now');
|
$secondLeavingDate = $faker->dateTimeBetween($secondJoiningDate, 'now');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,11 +68,12 @@ class TestMemberStatesTableSeeder extends Seeder
|
|||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
$joiningDate = $faker->dateTimeBetween($startDate, 'now - 30 days');
|
$joiningDate = $faker->dateTimeBetween($startDate, 'now - 30 days');
|
||||||
$leavingDate = NULL;
|
$leavingDate = null;
|
||||||
if(rand(1,5) === 5)
|
|
||||||
{
|
if (rand_bool(20)) {
|
||||||
$leavingDate = $faker->dateTimeBetween($joiningDate, 'now');
|
$leavingDate = $faker->dateTimeBetween($joiningDate, 'now');
|
||||||
}
|
}
|
||||||
|
|
||||||
factory(App\MemberState::class, 1)->create([
|
factory(App\MemberState::class, 1)->create([
|
||||||
'person_id' => $id,
|
'person_id' => $id,
|
||||||
"joining_date" => $joiningDate,
|
"joining_date" => $joiningDate,
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
|
use App\Person;
|
||||||
|
|
||||||
class TestPersonTargetsTableSeeder extends Seeder
|
class TestPersonTargetsTableSeeder extends Seeder
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -11,6 +13,10 @@ class TestPersonTargetsTableSeeder extends Seeder
|
|||||||
*/
|
*/
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
//
|
$people = Person::all();
|
||||||
|
|
||||||
|
for ($i = 0; $i < 300; $i++) {
|
||||||
|
$people->random()->targets()->save(factory(App\PersonTarget::class)->make());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user