/** * {@inheritdoc} */ public function shareList(array $posts) { $contacts = $this->contactProvider->getContacts(); $now = new \DateTime(); $from = $this->from; $subject = $this->getSubject($now); $response = array('sended' => false, 'errors' => array()); foreach ($posts as $key => $post) { if (!$post->getPublished()) { $response['errors'][] = $this->translator->trans('newsletter_post_not_published', array('%post_title%' => $post->getTitle()), 'PostAdmin'); } } if (empty($response['errors'])) { foreach ($contacts as $contact) { if (!$contact instanceof ContactInterface) { throw new \InvalidArgumentException(sprintf("%s must implement %s.", get_class($contact), ContactInterface::class)); } $template = $this->templating->render('@Admin/Batch/Newsletter/share_posts.html.twig', array('posts' => $posts, 'contact' => $contact)); $to = array($contact->getEmail()); if ($this->emailSender->send($from, $to, $subject, $template)) { foreach ($posts as $post) { $post->setSharedNewsletter($now); } $response['sended'] = true; } } } return $response; }
private function getContacts() { return array_merge($this->contactProvider->getContactsFormRepresentation(), array('all' => 'form.select_all_contacts')); }