function index(Request $request, Application $app) { $sendemail = new SendEmailModel(); $sendemail->setSiteId($app['currentSite']->getId()); $sendemail->setTimezone($app['currentTimeZone']); $form = $app['form.factory']->create(new SendEmailNewForm(), $sendemail); if ('POST' == $request->getMethod()) { $form->bind($request); $sendemail->setSendTo($request->request->get('send_to') == 'other' ? $request->request->get('send_to_other') : $request->request->get('send_to')); if (!filter_var($sendemail->getSendTo(), FILTER_VALIDATE_EMAIL)) { $form->addError(new FormError('Please enter an email address')); } if ($form->isValid()) { $sendemail->buildEvents($app); $repository = new SendEmailRepository(); $repository->create($sendemail, $app['currentSite'], $app['currentUser']); return $app->redirect("/admin/sendemail/" . $sendemail->getSlug()); } } $emails = array($app['currentUser']->getEmail()); $rb = new SendEmailRepositoryBuilder(); $rb->setSite($app['currentSite']); $rb->setUserCreatedBy($app['currentUser']); foreach ($rb->fetchAll() as $sendemail) { if (!in_array($sendemail->getSendTo(), $emails)) { $emails[] = $sendemail->getSendTo(); } } return $app['twig']->render('site/sendemailnew/index.html.twig', array('form' => $form->createView(), 'emails' => $emails)); }
public function fetchAll() { $this->buildStart(); $this->build(); $this->buildStat(); $results = array(); while ($data = $this->stat->fetch()) { $sendemail = new SendEmailModel(); $sendemail->setFromDataBaseRow($data); $results[] = $sendemail; } return $results; }
public function markSent(SendEmailModel $sendEmail, UserAccountModel $sentBy) { global $DB; $stat = $DB->prepare("UPDATE send_email_information SET sent_at=:sent_at, sent_by=:sent_by WHERE id =:id"); $stat->execute(array('id' => $sendEmail->getId(), 'sent_at' => \TimeSource::getFormattedForDataBase(), 'sent_by' => $sentBy->getId())); }