Fixed member block stats
This commit is contained in:
parent
2a49f83014
commit
b64c821e00
|
@ -44,6 +44,16 @@ class Membership extends Model
|
|||
return $this->belongsTo(Subactivity::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Builder<Membership> $query
|
||||
*
|
||||
* @return Builder<Membership>
|
||||
*/
|
||||
public function scopeActive(Builder $query): Builder
|
||||
{
|
||||
return $query->whereNull('to');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Builder<Membership> $query
|
||||
*
|
||||
|
|
|
@ -19,6 +19,7 @@ class AgeGroupCountBlock extends Block
|
|||
->join('subactivities', 'memberships.subactivity_id', 'subactivities.id')
|
||||
->isAgeGroup()
|
||||
->isMember()
|
||||
->active()
|
||||
->groupBy('subactivities.slug', 'subactivities.name')
|
||||
->orderBy('subactivity_id');
|
||||
}
|
||||
|
@ -31,6 +32,7 @@ class AgeGroupCountBlock extends Block
|
|||
return Membership::selectRaw('"leiter" AS slug, "Leiter" AS name, COUNT(member_id) AS count')
|
||||
->join('activities', 'memberships.activity_id', 'activities.id')
|
||||
->join('subactivities', 'memberships.subactivity_id', 'subactivities.id')
|
||||
->active()
|
||||
->isLeader();
|
||||
}
|
||||
|
||||
|
|
|
@ -51,6 +51,11 @@ class MembershipFactory extends Factory
|
|||
return $instance;
|
||||
}
|
||||
|
||||
public function ended(): self
|
||||
{
|
||||
return $this->state(['to' => now()->subDays(2)]);
|
||||
}
|
||||
|
||||
public function in(string $activity, int $activityNamiId, ?string $subactivity = null, ?int $subactivityNamiId = null): self
|
||||
{
|
||||
$instance = $this->for(Activity::factory()->name($activity)->inNami($activityNamiId));
|
||||
|
|
|
@ -26,7 +26,10 @@ class AgeGroupCountBlockTest extends TestCase
|
|||
Member::factory()->count(2)->has(Membership::factory()->in('€ LeiterIn', 2, 'Wölfling', 3))
|
||||
->defaults()
|
||||
->create();
|
||||
Member::factory()->count(2)->has(Membership::factory()->in('€ LeiterIn', 2, 'Jungpfadfinder', 3))
|
||||
Member::factory()->count(2)
|
||||
->has(Membership::factory()->in('€ LeiterIn', 2, 'Jungpfadfinder', 3))
|
||||
->has(Membership::factory()->ended()->in('€ LeiterIn', 2, 'Pfadfinder', 3))
|
||||
->has(Membership::factory()->ended()->in('€ Mitglied', 2, 'Jungpfadfinder', 3))
|
||||
->defaults()
|
||||
->create();
|
||||
|
||||
|
|
Loading…
Reference in New Issue