/**
* @param Rfc $rfc
* @param array $voteDiff
*/
public function notify(Rfc $rfc, array $voteDiff)
{
$attachments = [];
foreach ($voteDiff['votes'] as $title => $voteDiffs) {
$attachment = ['text' => $title, 'color' => 'good', 'fields' => []];
if (!empty($voteDiffs['new'])) {
$newVotes = array_map(function ($voter, $vote) {
return sprintf('%s: %s', $voter, $vote);
}, array_keys($voteDiffs['new']), $voteDiffs['new']);
$attachment['fields'][] = ['title' => 'New Votes', 'value' => implode(", ", $newVotes)];
}
if (!empty($voteDiffs['updated'])) {
$updatedVotes = array_map(function ($voter, $vote) {
return sprintf('%s: %s', $voter, $vote);
}, array_keys($voteDiffs['updated']), $voteDiffs['updated']);
$attachment['fields'][] = ['title' => 'Updated Votes', 'value' => implode(", ", $updatedVotes)];
}
$counts = [];
foreach ($rfc->getVotes()[$title]['counts'] as $header => $standing) {
if ($header === 'Real name') {
continue;
}
$counts[$header] = $standing;
}
$counts = array_map(function ($vote, $count) {
return sprintf('%s: %s', $vote, $count);
}, array_keys($counts), $counts);
$attachment['fields'][] = ['title' => 'Current Standings', 'value' => implode(", ", $counts)];
$attachments[] = $attachment;
}
$message = ['text' => sprintf("*PHP RFC Updates for %s*", $rfc->getName()), 'username' => 'PHP RFC Digestor', 'icon_url' => 'http://php.net/images/logos/php.ico', 'attachments' => json_encode($attachments)];
foreach ($this->slackSubscriberRepository->findAll() as $slackSubscriber) {
$this->commander->setToken($slackSubscriber->getToken());
$message['channel'] = '#' . $slackSubscriber->getChannel();
$this->commander->execute('chat.postMessage', $message);
}
}