protected function buildSegments() { if (count($this->segments) > 0) { $segment_widget = $this->ui->getWidget('campaign_segment'); $segment_widget->parent->visible = true; $locale = SwatI18NLocale::get(); $last_instance_title = null; foreach ($this->segments as $segment) { if ($this->app->isMultipleInstanceAdmin() && $segment->instance instanceof SiteInstance && $last_instance_title != $segment->instance->title) { $last_instance_title = $segment->instance->title; $segment_widget->addDivider(sprintf('<span class="instance-header">%s</span>', $last_instance_title), 'text/xml'); } if ($segment->cached_segment_size > 0) { $subscribers = sprintf(Deliverance::ngettext('One subscriber', '%s subscribers', $segment->cached_segment_size), $locale->formatNumber($segment->cached_segment_size)); } else { $subscribers = Deliverance::_('No subscribers'); } $title = sprintf('%s <span class="swat-note">(%s)</span>', $segment->title, $subscribers); if ($segment->cached_segment_size > 0) { $segment_widget->addOption($segment->id, $title, 'text/xml'); } else { // TODO, use a real option and disable it. $segment_widget->addDivider($title, 'text/xml'); } } } }
protected function processDBData() { parent::processDBData(); $locale = SwatI18NLocale::get(); $relocate = true; $message = null; $delete_count = 0; $error_count = 0; $newsletters = $this->getNewsletters(); foreach ($newsletters as $newsletter) { // only allow deleting unsent newsletters. There is nothing // technically stopping us from deleting ones that have been sent, // but do this for the sake of stats until deleting sent newsletters // is required. if ($newsletter->isSent() == false) { $list = $this->getList($newsletter); $campaign_type = $newsletter->instance instanceof SiteInstance ? $newsletter->instance->shortname : null; $campaign = $newsletter->getCampaign($this->app, $campaign_type); $transaction = new SwatDBTransaction($this->app->db); try { // If not a draft, remove the resources. Don't delete draft // newsletter resources as they are shared across all // drafts. if ($newsletter->isScheduled()) { DeliveranceCampaign::removeResources($this->app, $campaign); } $list->deleteCampaign($campaign); $sql = 'delete from Newsletter where id = %s'; $sql = sprintf($sql, $this->app->db->quote($newsletter->id, 'integer')); $delete_count += SwatDB::exec($this->app->db, $sql); $transaction->commit(); } catch (DeliveranceAPIConnectionException $e) { $transaction->rollback(); $e->processAndContinue(); $error_count++; $relocate = false; } catch (Exception $e) { $transaction->rollback(); $e = new DeliveranceException($e); $e->processAndContinue(); $error_count++; $relocate = false; } } } if ($delete_count > 0) { $message = new SwatMessage(sprintf(Deliverance::ngettext('One newsletter has been deleted.', '%s newsletters have been deleted.', $delete_count), $locale->formatNumber($delete_count)), 'notice'); $this->app->messages->add($message); } if ($error_count > 0) { $message = new SwatMessage(Deliverance::_('There was an issue connecting to the email service ' . 'provider.'), 'error'); $message->content_type = 'text/xml'; $message->secondary_content = sprintf('<strong>%s</strong><br />%s', sprintf(Deliverance::ngettext('One newsletter has not been deleted.', '%s newsletters have not been deleted.', $error_count), $locale->formatNumber($error_count)), Deliverance::ngettext('Connection issues are typically short-lived and ' . 'attempting to delete the newsletter again after a ' . 'delay will usually be successful.', 'Connection issues are typically short-lived and ' . 'attempting to delete the newsletters again after a ' . 'delay will usually be successful.', $error_count)); } return $relocate; }
protected function getConfirmationMessage() { $locale = SwatI18NLocale::get(); ob_start(); printf('<p>%s</p><p>%s</p>', sprintf(Deliverance::ngettext('The newsletter “%s” will be sent to one subscriber.', 'The newsletter “%s” will be sent to %s subscribers.', $this->send_count), $this->newsletter->subject, $locale->formatNumber($this->send_count)), Deliverance::_('Subscriber counts are estimates. Full statistics ' . 'will be available once the newsletter has been sent.')); return ob_get_clean(); }