Fixed member block stats

This commit is contained in:
philipp lang 2023-02-23 01:20:51 +01:00
parent 2a49f83014
commit b64c821e00
4 changed files with 21 additions and 1 deletions

View File

@ -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
*

View File

@ -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();
}

View File

@ -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));

View File

@ -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();