Added functions to get targets an actuals of a person.

This commit is contained in:
Lukas Halbritter
2018-09-09 09:58:52 +02:00
parent cbaa9b9174
commit 50acdbd71e
+55 -5
View File
@@ -4,20 +4,24 @@ namespace App;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Carbon\Carbon; use Carbon\Carbon;
use App\MemberState; use App\MemberState;
use App\PersonTarget;
class Person extends Model class Person extends Model
{ {
/**************************************************************************
* MEMBER STATE FUNCTIONS *
**************************************************************************/
/* /*
* Return true, if the person is active member, return false otherwise. * Return true, if the person is active member, return false otherwise.
* *
* @return boolean * @return boolean
*/ */
public function isActiveMember() public function isMember()
{ {
$latest = $this->hasMany('\App\MemberState') $latest = $this->getMemberStates()->last();
->orderBy('joining_date', 'desc')
->first();
if (is_null($latest)) { if (is_null($latest)) {
return false; return false;
@@ -26,6 +30,18 @@ class Person extends Model
} }
} }
/*
* Returns true, if the person was active member at some time in the past.
* Note, that this function also returns true, if the person is still an
* active member.
*
* @return boolean
*/
public function wasMember()
{
return !($this->getMemberStates()->isEmpty());
}
/* /*
* Return a collection of all persons which are active members. * Return a collection of all persons which are active members.
* *
@@ -38,7 +54,7 @@ class Person extends Model
->select('person_id as id', 'title', 'name_or_company', ->select('person_id as id', 'title', 'name_or_company',
'surname', 'date_of_birth', 'city', 'street', 'surname', 'date_of_birth', 'city', 'street',
'postal_code', 'email', 'mobile', 'phone', 'postal_code', 'email', 'mobile', 'phone',
'people.created_at', 'people.updated_at') 'joining_date', 'leaving_date')
->get(); ->get();
} }
@@ -81,4 +97,38 @@ class Person extends Model
return $diff; return $diff;
} }
/*
* Get all member state records associated with a person.
*
* @return Illuminate\Database\Eloquent\Collection
*/
public function getMemberStates()
{
return $this->hasMany('\App\MemberState')->orderBy('joining_date')->get();
}
/**************************************************************************
* PERSON TARGET FUNCTIONS *
**************************************************************************/
/*
* Get all targets associated with a person.
*
* @return Illuminate\Database\Eloquent\Collection
*/
public function getTargets()
{
return $this->hasMany('\App\PersonTarget')->orderBy('date')->get();
}
/*
* Get all actuals associated with a person.
*
* @return Illuminate\Database\Eloquent\Collection
*/
public function getActuals()
{
return $this->hasManyThrough('\App\SubBooking', '\App\PersonTarget')->get();
}
} }