Skip to content

Commit

Permalink
ignore unofficial achievements
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamiras committed Feb 1, 2025
1 parent a97b32d commit afa7fd1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ public function table(Table $table): Table
$numberOfAchievements = (int) $data['numberOfAchievements'];
/** @var Event $event */
$event = $this->getOwnerRecord();
$user_id = $event->achievements->first()?->achievement->user_id ?? EventAchievement::RAEVENTS_USER_ID;
$user_id = $event->publishedAchievements->first()?->achievement->user_id ?? EventAchievement::RAEVENTS_USER_ID;

(new AddAchievementsToEventAction())->execute($event, $numberOfAchievements, $user_id);

Notification::make()
->title("Created $numberOfAchievements new " . Str::Plural('achievement', $numberOfAchievements))
->title("Created $numberOfAchievements new " . Str::plural('achievement', $numberOfAchievements))
->success()
->send();
})
Expand Down
8 changes: 8 additions & 0 deletions app/Models/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ public function achievements(): HasManyThrough
)->with('achievement.game');
}

/**
* @return HasManyThrough<EventAchievement>
*/
public function publishedAchievements(): HasManyThrough
{
return $this->achievements()->published();
}

/**
* @return BelongsToMany<GameSet>
*/
Expand Down
13 changes: 12 additions & 1 deletion app/Models/EventAchievement.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,22 @@ public function scopeActive(Builder $query, ?Carbon $timestamp = null): Builder
{
$timestamp ??= Carbon::now();

return $query->where(function ($q) use ($timestamp) {
return $query->published()->where(function ($q) use ($timestamp) {
$q->where('active_from', '<=', $timestamp)->orWhereNull('active_from');
})
->where(function ($q) use ($timestamp) {
$q->where('active_until', '>', $timestamp)->orWhereNull('active_until');
});
}

/**
* @param Builder<EventAchievement> $query
* @return Builder<EventAchievement>
*/
public function scopePublished(Builder $query): Builder
{
return $query->whereHas('achievement', function ($q) {
$q->published();
});
}
}

0 comments on commit afa7fd1

Please sign in to comment.