Merge branch 'people' of ssh://halbi.ddnss.de:2122/media/raid/repositories/pollux into people
This commit is contained in:
+4
-5
@@ -22,7 +22,6 @@ class Person extends Model
|
|||||||
public function isMember()
|
public function isMember()
|
||||||
{
|
{
|
||||||
$latest = $this->memberStates->last();
|
$latest = $this->memberStates->last();
|
||||||
|
|
||||||
if (is_null($latest)) {
|
if (is_null($latest)) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
@@ -56,7 +55,7 @@ class Person extends Model
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Return the last date since when the person is an active member.
|
* Return the last date since when the person is an active member.
|
||||||
*
|
*
|
||||||
* @return Carbon\Carbon
|
* @return Carbon\Carbon
|
||||||
*/
|
*/
|
||||||
public function activeSince()
|
public function activeSince()
|
||||||
@@ -64,7 +63,7 @@ class Person extends Model
|
|||||||
$latest = $this->memberStates
|
$latest = $this->memberStates
|
||||||
->orderBy('joining_date', 'desc')
|
->orderBy('joining_date', 'desc')
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
return Carbon::parse($latest['joining_date']);
|
return Carbon::parse($latest['joining_date']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +75,7 @@ class Person extends Model
|
|||||||
public function activeTime()
|
public function activeTime()
|
||||||
{
|
{
|
||||||
$activeTimes = $this->memberStates;
|
$activeTimes = $this->memberStates;
|
||||||
|
|
||||||
$diff = 0;
|
$diff = 0;
|
||||||
|
|
||||||
foreach ($activeTimes as $period) {
|
foreach ($activeTimes as $period) {
|
||||||
@@ -84,7 +83,7 @@ class Person extends Model
|
|||||||
$end = is_null($period['leaving_date']) ?
|
$end = is_null($period['leaving_date']) ?
|
||||||
Carbon::now() :
|
Carbon::now() :
|
||||||
Carbon::parse($period['leaving_date']);
|
Carbon::parse($period['leaving_date']);
|
||||||
|
|
||||||
$diffYears = Carbon::parse($start)->diffInYears($end);
|
$diffYears = Carbon::parse($start)->diffInYears($end);
|
||||||
$diffDays = Carbon::parse($start)->diffInDays($end);
|
$diffDays = Carbon::parse($start)->diffInDays($end);
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Faker\Generator as Faker;
|
use Faker\Generator as Faker;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Carbon\CarbonPeriod;
|
||||||
|
|
||||||
$factory->define(App\MemberStates::class, function (Faker $faker) {
|
$factory->define(App\MemberState::class, function (Faker $faker) {
|
||||||
return [
|
return [
|
||||||
//
|
'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
|
||||||
];
|
'updated_at' => Carbon::now()->format('Y-m-d H:i:s'),
|
||||||
|
];
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -14,10 +14,10 @@ class TestDataSeeder extends Seeder
|
|||||||
$this->call([
|
$this->call([
|
||||||
TestBookingsTableSeeder::class,
|
TestBookingsTableSeeder::class,
|
||||||
TestPeopleTableSeeder::class,
|
TestPeopleTableSeeder::class,
|
||||||
TestMemberStatesTableSeeder::class,
|
|
||||||
TestPersonTargetsTableSeeder::class,
|
TestPersonTargetsTableSeeder::class,
|
||||||
TestProjectsTableSeeder::class,
|
TestProjectsTableSeeder::class,
|
||||||
TestSubBookingsTableSeeder::class
|
TestSubBookingsTableSeeder::class,
|
||||||
|
TestMemberStatesTableSeeder::class,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class TestMemberStatesTableSeeder extends Seeder
|
|||||||
*/
|
*/
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
DB::table('member_states')->insert([
|
/*DB::table('member_states')->insert([
|
||||||
[
|
[
|
||||||
'person_id' => 1,
|
'person_id' => 1,
|
||||||
'joining_date' => '2014-9-22',
|
'joining_date' => '2014-9-22',
|
||||||
@@ -34,6 +34,74 @@ class TestMemberStatesTableSeeder extends Seeder
|
|||||||
'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
|
'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
|
||||||
'updated_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;
|
||||||
|
|
||||||
|
if($personHasState) {
|
||||||
|
// if Person has a State, decide if it has one or two.
|
||||||
|
$numberOfStates = rand(1,2);
|
||||||
|
|
||||||
|
if($numberOfStates > 1) {
|
||||||
|
$this->createPerson($person->id, $numberOfStates);
|
||||||
|
} else {
|
||||||
|
$this->createPerson($person->id, $numberOfStates);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createPerson($id, $numberOfStates = 1)
|
||||||
|
{
|
||||||
|
// 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.
|
||||||
|
$lastLeaving = "2015-12-30";
|
||||||
|
$firstSecondJoiningDate = "2017-06-01";
|
||||||
|
|
||||||
|
$firstJoiningDate = $faker->dateTimeBetween($startDate, "2015-11-30");
|
||||||
|
$firstLeavingDate = $faker->dateTimeBetween($firstJoiningDate, $lastLeaving);
|
||||||
|
|
||||||
|
$secondJoiningDate = $faker->dateTimeBetween($firstSecondJoiningDate, 'now');
|
||||||
|
$secondLeavingDate = NULL;
|
||||||
|
if(rand(1,8) === 8)
|
||||||
|
{
|
||||||
|
$secondLeavingDate = $faker->dateTimeBetween($secondJoiningDate, 'now');
|
||||||
|
}
|
||||||
|
|
||||||
|
factory(App\MemberState::class, 1)->create([
|
||||||
|
'person_id' => $id,
|
||||||
|
"joining_date" => $firstJoiningDate,
|
||||||
|
"leaving_date" => $firstLeavingDate,
|
||||||
|
]);
|
||||||
|
|
||||||
|
factory(App\MemberState::class, 1)->create([
|
||||||
|
'person_id' => $id,
|
||||||
|
"joining_date" => $secondJoiningDate,
|
||||||
|
"leaving_date" => $secondLeavingDate,
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
$joiningDate = $faker->dateTimeBetween($startDate, 'now - 30 days');
|
||||||
|
$leavingDate = NULL;
|
||||||
|
if(rand(1,5) === 5)
|
||||||
|
{
|
||||||
|
$leavingDate = $faker->dateTimeBetween($joiningDate, 'now');
|
||||||
|
}
|
||||||
|
factory(App\MemberState::class, 1)->create([
|
||||||
|
'person_id' => $id,
|
||||||
|
"joining_date" => $joiningDate,
|
||||||
|
"leaving_date" => $leavingDate,
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class TestPeopleTableSeeder extends Seeder
|
|||||||
$people = $people->concat(factory(App\Person::class, 40)->states('male')->create());
|
$people = $people->concat(factory(App\Person::class, 40)->states('male')->create());
|
||||||
$people = $people->concat(factory(App\Person::class, 40)->states('female')->create());
|
$people = $people->concat(factory(App\Person::class, 40)->states('female')->create());
|
||||||
|
|
||||||
// Create random member states for
|
// Create random member states for
|
||||||
// $people->each(function ($person) {
|
// $people->each(function ($person) {
|
||||||
// $person->memberStates->save(factory('App\MemberState')->make());
|
// $person->memberStates->save(factory('App\MemberState')->make());
|
||||||
// });
|
// });
|
||||||
|
|||||||
Reference in New Issue
Block a user