public function __viewPreview()
 {
     $this->setPageType('index');
     $this->setTitle(__("Symphony - Newsletter Recipient Groups Preview"));
     $sectionManager = new SectionManager($this);
     try {
         $source = RecipientgroupManager::create($this->_context[1]);
     } catch (Exception $e) {
         Administration::instance()->errorPageNotFound();
     }
     if ($_GET['pg']) {
         $source->dsParamSTARTPAGE = (int) $_GET['pg'];
     }
     $source->dsParamLIMIT = 17;
     $elements = $source->getSlice();
     $recipients = new XMLElement('recipients');
     General::array_to_xml($recipients, $source->about());
     General::array_to_xml($recipients, array('source' => is_numeric($section = $source->getSource()) ? $sectionManager->fetch($source->getSource())->get('handle') : 'system:' . $source->getSource()));
     General::array_to_xml($recipients, $elements);
     $context = new XMLElement('context');
     General::array_to_xml($context, $this->_context);
     $this->_XML->appendChild($context);
     $this->_XML->appendChild($recipients);
     $this->insertBreadcrumbs(array(Widget::Anchor(__('Email Newsletter Recipients'), SYMPHONY_URL . '/extension/email_newsletter_manager/recipientgroups/')));
     $about = $source->about();
     $this->appendSubheading($about['name'] . ' ' . __('preview'), array(Widget::Anchor(__('Edit %s group', array($layout)), SYMPHONY_URL . '/extension/email_newsletter_manager/recipientgroups/edit/' . $source->getHandle() . '/' . $layout, __('Edit %s group', array($layout)), 'button')));
 }
 /**
  * Append element to datasource output
  */
 public function appendFormattedElement(&$wrapper, $data, $encode = false)
 {
     $node = new XMLElement($this->get('element_name'));
     $newsletter = EmailNewsletterManager::create($data['newsletter_id']);
     $properties = $newsletter->getStats();
     $node->setAttribute('newsletter-id', $data['newsletter_id']);
     $node->setAttribute('started-on', $properties['started_on']);
     $node->setAttribute('started-by', $properties['started_by']);
     $node->setAttribute('completed-on', $properties['completed_on']);
     $node->setAttribute('status', $properties['status']);
     $node->setAttribute('total', $properties['total']);
     $node->setAttribute('sent', $properties['sent']);
     $node->setAttribute('failed', $properties['failed']);
     $node->appendChild(new XMLElement('subject', $newsletter->getTemplate()->subject));
     // load configuration;
     // use saved (entry) config XML if available (i.e.: if the email newsletter has been sent);
     // fallback: the field's configuration XML
     // sender
     $sender = new XMLElement('sender');
     $about = is_object($newsletter->getSender()) ? $newsletter->getSender()->about() : array();
     General::array_to_xml($sender, $about);
     $sender_name = $about['name'];
     $sender_handle = is_object($newsletter->getSender()) ? $newsletter->getSender()->getHandle() : NULL;
     $el = new XMLElement('name');
     $el->setAttribute('id', $sender_handle);
     $el->setValue($sender_name);
     $sender->replaceChildAt(0, $el);
     $node->appendChild($sender);
     // recipients
     $recipients = new XMLElement('recipient-groups');
     foreach ($newsletter->getRecipientGroups() as $group) {
         $rgroup = new XMLElement('group');
         $about = (array) $group->about();
         General::array_to_xml($rgroup, $about);
         $rgroup_name = $about['name'];
         $rgroup_handle = $group->getHandle();
         $el = new XMLElement('name');
         $el->setAttribute('id', $rgroup_handle);
         $el->setValue($rgroup_name);
         $rgroup->replaceChildAt(0, $el);
         $rgroup_count = RecipientgroupManager::create($rgroup_handle)->getCount();
         $rgroup->setAttribute('count', $rgroup_count);
         $recipients->appendChild($rgroup);
     }
     $node->appendChild($recipients);
     // template
     $template = new XMLElement('template');
     $about = (array) $newsletter->getTemplate()->about;
     General::array_to_xml($template, $about);
     $template_name = $about['name'];
     $template_handle = EmailTemplateManager::getHandleFromName($template_name);
     $el = new XMLElement('name');
     $el->setAttribute('id', $template_handle);
     $el->setValue($template_name);
     $template->replaceChildAt(0, $el);
     $node->appendChild($template);
     $wrapper->appendChild($node);
 }