diff --git a/README.md b/README.md index e4ebf23..12c93e3 100644 --- a/README.md +++ b/README.md @@ -8,4 +8,4 @@ Run the `app:get-raffle-winner` command to retrieve the 'yes' RSVPs from Meetup ./bin/console app:get-raffle-winner -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. diff --git a/src/Collection/EventCollection.php b/src/Collection/EventCollection.php new file mode 100644 index 0000000..3d26995 --- /dev/null +++ b/src/Collection/EventCollection.php @@ -0,0 +1,19 @@ +items))->filter(function (array $rsvp): bool { + return !Arr::get($rsvp, 'member.event_context.host'); + }); + } + +} \ No newline at end of file diff --git a/src/Command/GetRaffleWinnerCommand.php b/src/Command/GetRaffleWinnerCommand.php index 3832c35..ba6a380 100644 --- a/src/Command/GetRaffleWinnerCommand.php +++ b/src/Command/GetRaffleWinnerCommand.php @@ -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();