Added seeders for members-states and person targets.
This commit is contained in:
@@ -12,36 +12,12 @@ class TestMemberStatesTableSeeder extends Seeder
|
||||
*/
|
||||
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
|
||||
// once or twice.
|
||||
foreach (App\Person::all() as $person) {
|
||||
|
||||
// randomly decide if person has a state.
|
||||
$personHasState = rand(1,8) < 8;
|
||||
$personHasState = rand_bool(88);
|
||||
|
||||
if($personHasState) {
|
||||
// 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)
|
||||
{
|
||||
// manually create faker Instance since you can't control iterations
|
||||
// Manually create faker Instance since you can't control iterations
|
||||
// in Factory-Files.
|
||||
$faker = Faker\Factory::create();
|
||||
|
||||
$startDate = "2014-04-01";
|
||||
|
||||
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";
|
||||
$firstSecondJoiningDate = "2017-06-01";
|
||||
|
||||
@@ -73,9 +49,9 @@ class TestMemberStatesTableSeeder extends Seeder
|
||||
$firstLeavingDate = $faker->dateTimeBetween($firstJoiningDate, $lastLeaving);
|
||||
|
||||
$secondJoiningDate = $faker->dateTimeBetween($firstSecondJoiningDate, 'now');
|
||||
$secondLeavingDate = NULL;
|
||||
if(rand(1,8) === 8)
|
||||
{
|
||||
$secondLeavingDate = null;
|
||||
|
||||
if (rand_bool(12)) {
|
||||
$secondLeavingDate = $faker->dateTimeBetween($secondJoiningDate, 'now');
|
||||
}
|
||||
|
||||
@@ -92,11 +68,12 @@ class TestMemberStatesTableSeeder extends Seeder
|
||||
]);
|
||||
} else {
|
||||
$joiningDate = $faker->dateTimeBetween($startDate, 'now - 30 days');
|
||||
$leavingDate = NULL;
|
||||
if(rand(1,5) === 5)
|
||||
{
|
||||
$leavingDate = null;
|
||||
|
||||
if (rand_bool(20)) {
|
||||
$leavingDate = $faker->dateTimeBetween($joiningDate, 'now');
|
||||
}
|
||||
|
||||
factory(App\MemberState::class, 1)->create([
|
||||
'person_id' => $id,
|
||||
"joining_date" => $joiningDate,
|
||||
|
||||
Reference in New Issue
Block a user