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); } } }
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>']; }