/** * @param Rfc $rfc * @param array $voteDiff */ public function notify(Rfc $rfc, array $voteDiff) { foreach ($this->emailSubscriberRepository->findAll() as $subscriber) { $email = $this->twig->render('rfc.twig', ['rfcName' => $rfc->getName(), 'details' => $voteDiff['details'], 'changeLog' => $voteDiff['changeLog'], 'voteDiffs' => $voteDiff['votes'], 'rfcVotes' => $rfc->getVotes(), 'unsubscribeUrl' => sprintf('%s/unsubscribe/%s', $this->config->get('app.url'), $subscriber->getUnsubscribeToken())]); $message = $this->mailer->createMessage()->setSubject(sprintf('%s updated!', $rfc->getName()))->setFrom('*****@*****.**')->setTo($subscriber->getEmail())->setBody($email, 'text/html'); $this->mailer->send($message); } }
/** * @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); } }
public function testSetNameAndGetName() { $this->assertSame('', $this->rfc->getName()); $this->rfc->setName('name'); $this->assertSame('name', $this->rfc->getName()); }