Exclude event hosts
Automatically filter event hosts (i.e. organisers) from the RSVP list so that they aren't potentially returned as winners. Fixes #2
This commit is contained in:
parent
3ad31b95b0
commit
c188676033
|
@ -8,4 +8,4 @@ Run the `app:get-raffle-winner` command to retrieve the 'yes' RSVPs from Meetup
|
|||
|
||||
./bin/console app:get-raffle-winner <event_id>
|
||||
|
||||
Currently, all 'yes' RSVPs are possible to be returned, including event hosts.
|
||||
RSVPs by event hosts (i.e. organisers) are automatically removed so that they are not returned.
|
||||
|
|
19
src/Collection/EventCollection.php
Normal file
19
src/Collection/EventCollection.php
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Collection;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
final class EventCollection extends Collection
|
||||
{
|
||||
public function excludeEventHosts(): self
|
||||
{
|
||||
return (new self($this->items))->filter(function (array $rsvp): bool {
|
||||
return !Arr::get($rsvp, 'member.event_context.host');
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Collection\EventCollection;
|
||||
use DateInterval;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
|
@ -96,7 +97,7 @@ class GetRaffleWinnerCommand extends Command
|
|||
$this->eventData['name']
|
||||
));
|
||||
|
||||
$io->section(sprintf('%s \'yes\' RSVPs', $this->yesRsvps->count()));
|
||||
$io->section(sprintf('%s \'yes\' RSVPs (excluding hosts)', $this->yesRsvps->count()));
|
||||
$io->listing($this->yesRsvps->pluck('member.name')->sort()->toArray());
|
||||
$io->success(
|
||||
sprintf('Winner: %s', Arr::get($this->winner, 'member.name'))
|
||||
|
@ -163,8 +164,10 @@ class GetRaffleWinnerCommand extends Command
|
|||
)
|
||||
);
|
||||
|
||||
$this->rsvps = EventCollection::make($response->toArray())
|
||||
->excludeEventHosts();
|
||||
|
||||
$rsvps->expiresAfter(DateInterval::createFromDateString('1 hour'));
|
||||
$this->rsvps = new Collection($response->toArray());
|
||||
$this->cache->save($rsvps->set($this->rsvps));
|
||||
} else {
|
||||
$this->rsvps = $rsvps->get();
|
||||
|
|
Loading…
Reference in a new issue