-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Allow to cancel a race * Identify wildcard when participant register * Include wildcard info in details and export for timekeeping
- Loading branch information
Showing
29 changed files
with
2,357 additions
and
21 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
app/Actions/Wildcard/AttributeWildcardBasedOnFirstRace.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace App\Actions\Wildcard; | ||
|
||
use App\Models\Race; | ||
use App\Models\Participant; | ||
|
||
class AttributeWildcardBasedOnFirstRace | ||
{ | ||
/** | ||
* Identify if a participant should have the wildcard status in a race within a championship | ||
* | ||
* @param \App\Models\Participant $participant | ||
* @param \App\Models\Race $race | ||
* @return bool|null the wildcard status | ||
*/ | ||
public function __invoke(Participant $participant, Race $race): ?bool | ||
{ | ||
$firstRace = $race->championship->races()->closed()->first(); | ||
|
||
if(is_null($firstRace)){ | ||
return false; | ||
} | ||
|
||
if($firstRace->is($race)){ | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace App\Data; | ||
|
||
use App\Models\WildcardStrategy; | ||
use Spatie\LaravelData\Data; | ||
|
||
class WildcardSettingsData extends Data | ||
{ | ||
public function __construct( | ||
public bool $enabled = false, | ||
public ?WildcardStrategy $strategy = null, | ||
) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace App\Listeners; | ||
|
||
use App\Events\ParticipantRegistered; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
|
||
class CheckParticipantForWildcard implements ShouldQueue | ||
{ | ||
/** | ||
* Create the event listener. | ||
*/ | ||
public function __construct() | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Handle the event. | ||
*/ | ||
public function handle(ParticipantRegistered $event): void | ||
{ | ||
$championship = $event->race->championship; | ||
|
||
if(!$championship->wildcard?->enabled){ | ||
return ; | ||
} | ||
|
||
$evaluate = $championship->wildcard->strategy->resolve(); | ||
|
||
$event->participant->wildcard = $evaluate($event->participant, $event->race); | ||
$event->participant->save(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace App\Listeners; | ||
|
||
use App\Events\ParticipantRegistered; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
|
||
class CheckParticipantIsWildcard | ||
{ | ||
/** | ||
* Create the event listener. | ||
*/ | ||
public function __construct() | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Handle the event. | ||
*/ | ||
public function handle(ParticipantRegistered $event): void | ||
{ | ||
// $bonus = $event->race->championship->bonuses()->licenceHash($event->participant->driver_licence)->first(); | ||
|
||
// $useBonus = $bonus?->hasRemaining() ?? false; | ||
|
||
if($bonus && $useBonus){ | ||
$event->participant->update(['wildcard' => true]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
namespace App\Livewire; | ||
|
||
use App\Models\Championship; | ||
use App\Models\WildcardStrategy; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Support\Facades\Validator; | ||
use Illuminate\Validation\Rules\Enum; | ||
use Laravel\Jetstream\Jetstream; | ||
use Livewire\Attributes\Locked; | ||
use Livewire\Component; | ||
|
||
class WildcardSettings extends Component | ||
{ | ||
|
||
/** | ||
* The create API token form state. | ||
* | ||
* @var array | ||
*/ | ||
public $wildcardForm = [ | ||
'enabled' => false, | ||
'strategy' => null, | ||
]; | ||
|
||
#[Locked] | ||
public $championship_id = null; | ||
|
||
/** | ||
* Mount the component. | ||
* | ||
* @return void | ||
*/ | ||
public function mount(Championship $championship) | ||
{ | ||
$this->championship_id = $championship->getKey(); | ||
|
||
$this->wildcardForm['enabled'] = $championship->wildcard?->enabled ?? false; | ||
$this->wildcardForm['strategy'] = $championship->wildcard?->strategy?->value ?? null; | ||
} | ||
|
||
public function updateWildcardSettings() | ||
{ | ||
$this->resetErrorBag(); | ||
|
||
Validator::make([ | ||
'wildcard_enabled' => $this->wildcardForm['enabled'], | ||
'wildcard_strategy' => $this->wildcardForm['strategy'], | ||
], [ | ||
'wildcard_enabled' => ['required', 'boolean'], | ||
'wildcard_strategy' => ['required', 'integer', new Enum(WildcardStrategy::class)], | ||
])->validateWithBag('updateWildcardSettings'); | ||
|
||
auth()->user()->can('update', $this->championship); | ||
|
||
$this->championship->wildcard->enabled = $this->wildcardForm['enabled']; | ||
$this->championship->wildcard->strategy = WildcardStrategy::from($this->wildcardForm['strategy']); | ||
$this->championship->save(); | ||
|
||
$this->dispatch('saved'); | ||
} | ||
|
||
/** | ||
* Get the current user of the application. | ||
* | ||
* @return mixed | ||
*/ | ||
public function getUserProperty() | ||
{ | ||
return Auth::user(); | ||
} | ||
|
||
|
||
public function getChampionshipProperty() | ||
{ | ||
return Championship::find($this->championship_id); | ||
} | ||
|
||
public function getStrategiesProperty() | ||
{ | ||
return WildcardStrategy::cases(); | ||
} | ||
|
||
|
||
public function render() | ||
{ | ||
return view('livewire.wildcard-settings'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use App\Actions\Wildcard\AttributeWildcardBasedOnFirstRace; | ||
use Illuminate\Support\Str; | ||
|
||
enum WildcardStrategy: int | ||
{ | ||
/** | ||
* First non canceled race in championship is used to derive partecipants that can gain points for the championship | ||
*/ | ||
case BASED_ON_FIRST_RACE = 10; | ||
|
||
// case BASED_ON_BIB_RESERVATION = 20; | ||
|
||
// case BASED_ON_BONUS = 30; | ||
|
||
public function localizedName(): string | ||
{ | ||
return trans("wildcard-options.{$this->name}"); | ||
} | ||
|
||
|
||
public function resolve() | ||
{ | ||
return app()->make(AttributeWildcardBasedOnFirstRace::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.