Get and merge comments for each event
This commit is contained in:
parent
c030a9658d
commit
dcf53f8b0f
|
@ -10,6 +10,7 @@ use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
|
use Tightenco\Collect\Support\Collection;
|
||||||
|
|
||||||
class PickWinnerCommand extends Command
|
class PickWinnerCommand extends Command
|
||||||
{
|
{
|
||||||
|
@ -84,5 +85,66 @@ class PickWinnerCommand extends Command
|
||||||
|
|
||||||
$cache->set($cacheKey, json_decode($response->getBody())->events, 3600);
|
$cache->set($cacheKey, json_decode($response->getBody())->events, 3600);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$events = collect($events);
|
||||||
|
$this->picker->setHosts($events);
|
||||||
|
$this->picker->setComments($this->allComments($events));
|
||||||
|
|
||||||
|
var_dump($this->picker->getWinners(1)->first());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all comments (talks and event) for the events.
|
||||||
|
*
|
||||||
|
* @param \Tightenco\Collect\Support\Collection $events
|
||||||
|
* The retrieved events.
|
||||||
|
*
|
||||||
|
* @return \Tightenco\Collect\Support\Collection
|
||||||
|
* The merged comments.
|
||||||
|
*/
|
||||||
|
private function allComments(Collection $events): Collection
|
||||||
|
{
|
||||||
|
return $events->map(function (\stdClass $event) {
|
||||||
|
return $this
|
||||||
|
->eventComments($event)
|
||||||
|
->merge($this->talkComments($event))
|
||||||
|
;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the event comments.
|
||||||
|
*
|
||||||
|
* @param \stdClass $event
|
||||||
|
* The event.
|
||||||
|
*
|
||||||
|
* @return \Tightenco\Collect\Support\Collection
|
||||||
|
*/
|
||||||
|
private function eventComments(\stdClass $event): Collection
|
||||||
|
{
|
||||||
|
$response = $this->client->get(
|
||||||
|
$event->comments_uri,
|
||||||
|
['query' => ['resultsperpage' => 1000]])
|
||||||
|
->getBody();
|
||||||
|
|
||||||
|
return collect(json_decode($response)->comments);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the talk comments.
|
||||||
|
*
|
||||||
|
* @param \stdClass $event
|
||||||
|
* The event.
|
||||||
|
*
|
||||||
|
* @return \Tightenco\Collect\Support\Collection
|
||||||
|
*/
|
||||||
|
private function talkComments(\stdClass $event): Collection
|
||||||
|
{
|
||||||
|
$response = $this->client->get(
|
||||||
|
$event->all_talk_comments_uri,
|
||||||
|
['query' => ['resultsperpage' => 1000]]
|
||||||
|
)->getBody();
|
||||||
|
|
||||||
|
return collect(json_decode($response)->comments);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue