public static final function sendCommunication(Communication $communication, $ignoreTime = false) { Log::debug("Considering to send CommunicationItem with ID: " . $communication->CommunicationID, "COMMS"); $currentDateTime = new RhubarbDateTime("now"); if (CommunicationsModule::isEmailSendingEnabled() && ($ignoreTime || $communication->shouldSendCommunication($currentDateTime))) { if (self::sendItems($communication)) { $communication->markSent(); } else { $communication->Status = Communication::STATUS_FAILED; } $communication->save(); return true; } else { return false; } }
/** * @return Communication * @throws \Rhubarb\Stem\Exceptions\RecordNotFoundException */ public function createCommunicationForEmail() { $email = new SimpleEmail(); $email->setSubject("The three billy goats"); $email->addRecipient("*****@*****.**", "John Smith"); $email->setSender("*****@*****.**", "Jane Smith"); $email->setText("Michael went to mow, went to mow a meadow."); $email->setHtml("<p>Michael went to mow, went to mow a meadow.</p>"); return Communication::fromEmail($email); }
protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $communicationID = $input->getArgument('communicationID'); if (isset($communicationID)) { $communication = new Communication($communicationID); CommunicationProcessor::sendCommunication($communication); } else { $unsentCommunicationsArray = Communication::findUnsentCommunications(); foreach ($unsentCommunicationsArray as $communication) { CommunicationProcessor::sendCommunication($communication); } } }
/** * @return Communication * @throws \Rhubarb\Stem\Exceptions\RecordNotFoundException */ public function createCommunicationForEmail() { $email = new SimpleEmail(); $email->setSubject("The three billy goats"); $email->addRecipientByEmail("*****@*****.**", "John Smith"); $email->setSender("*****@*****.**", "Jane Smith"); $email->setText("Michael went to mow, went to mow a meadow."); $email->setHtml("<p>Michael went to mow, went to mow a meadow.</p>"); $package = new CommunicationPackage(); $package->addSendable($email); $package->title = $email->getSubject(); $package->send(); return Communication::findLast(); }
public function testCommunicationEmailProviderCantBeAProcessor() { $this->assertCount(0, CommunicationItem::find(), "CommunicationItem count was not 0"); $this->assertCount(0, Communication::find(), "Communication count was not 0"); $email = new SimpleEmail(); $email->setSubject("A fine day in the park"); $email->addRecipientByEmail("*****@*****.**", "Joe Bloggs"); $email->setHtml("<html><head>Test Head</head><body>Test Body</body></html>"); $email->setText("Test Text Body"); CommunicationProcessor::setProviderClassName(EmailProvider::class, CommunicationEmailProvider::class); try { EmailProvider::setProviderClassName(CommunicationEmailProvider::class); EmailProvider::getProvider()->send($email); $this->fail('Email should not sent due to invalid Communication Provider being set'); } catch (InvalidProviderException $exception) { } }
protected function createSubLeaves() { $communicationItems = $this->model->restCollection; if ($this->model->archive) { $communicationItems->filter(new Not(new Equals('Status', 'Not Sent'))); } $communicationItems->intersectWith(Communication::find(), 'CommunicationID', 'CommunicationID', ['Title', 'DateToSend']); $this->registerSubLeaf($table = new Table($communicationItems->addSort('DateCreated', false)), $searchPanel = new CommunicationItemSearchPanel('SearchPanel'), $sendAllButton = new Button('SendAllCommunicationsButton', 'Send All Communications Now', function () { foreach (Communication::findUnsentCommunications() as $unsentCommunication) { CommunicationProcessor::sendCommunication($unsentCommunication, true); } throw new ForceResponseException(new RedirectResponse('./')); }), new CommunicationItemCollectionCheckbox('EnableSendingEmails')); $sendAllButton->setConfirmMessage('Are you sure you want to send all scheduled emails?'); $table->bindEventsWith($searchPanel); $table->columns = ['#' => 'CommunicationItemID', 'Title' => '{Title}', 'Recipient', 'DateCreated', 'Date to Send' => new DateColumn('DateToSend', 'Date to Send', CommunicationDecorator::DATE_FORMAT), 'DateSent', 'Status', '' => '<a class="view-content-button" data-id="{CommunicationItemID}" href="#ViewContent">View Content</a>']; }
private function createCommunicationWithMultipleRecipients($dateToSend, $noOfRecipients) { $email = new SimpleEmail(); $email->setText("Test Message Body"); $email->setSender("*****@*****.**"); foreach (range(1, $noOfRecipients) as $i) { $email->addRecipientByEmail("test@test" . $i . ".com"); } $package = new CommunicationPackage(); if ($dateToSend) { $package->dateToSend = $dateToSend; } $package->addSendable($email); $package->send(); $communication = Communication::findLast(); return $communication; }
public function testPackageCanBeRecordedNotSent() { $lastEmail = UnitTestingEmailProvider::getLastEmail(); $email = new SimpleEmail(); $package = new CommunicationPackage(); $package->title = "Test With No Send"; $package->addSendable($email); $package->draft(); $communication = Communication::findLast(); $communication->markSent(); $this->assertEquals("Sent", $communication->Status); $this->assertEquals($lastEmail, UnitTestingEmailProvider::getLastEmail()); }