You are here

class FrxEmailMerge in Forena Reports 8

Email Merge Template

Plugin annotation


@FrxTemplate(id="FrxEmailMerge", name="Email Merge")

Hierarchy

Expanded class hierarchy of FrxEmailMerge

File

src/FrxPlugin/Template/FrxEmailMerge.php, line 12
FrxEmailMerge Email merge template.

Namespace

Drupal\forena\Template
View source
class FrxEmailMerge extends TemplateBase {
  public $templateName = 'Mail Merge';
  public $email_input_format;
  public function __construct() {
    parent::__construct();
    $this->email_input_format = \Drupal::config('forena.settings')
      ->get('email_input_format');
    $this->doc_types = array(
      'email',
    );
  }
  public function scrapeConfig(\SimpleXMLElement $xml) {
    $config = array();
    $config['class'] = get_class($this);
    $config['from'] = html_entity_decode($this
      ->extractXPathInnerHTML("*//*[@class='email-header-from']", $this->reportDocDomNode));
    $config['to'] = html_entity_decode($this
      ->extractXPathInnerHTML("*//*[@class='email-header-to']", $this->reportDocDomNode));
    $config['cc'] = html_entity_decode($this
      ->extractXPathInnerHTML("*//*[@class='email-header-cc']", $this->reportDocDomNode));
    $config['bcc'] = html_entity_decode($this
      ->extractXPathInnerHTML("*//*[@class='email-header-bcc']", $this->reportDocDomNode));
    $config['subject'] = $this
      ->extractXPathInnerHTML("*//*[@class='email-header-subject']", $this->reportDocDomNode);
    $config['body']['value'] = $this
      ->extractXPathInnerHTML("*//*[@class='email-body']", $this->reportDocDomNode);
    return $config;
  }
  public function configForm($config) {
    $form_ctl['from'] = array(
      '#type' => 'textfield',
      '#title' => t('From'),
      '#default_value' => @$config['from'],
    );
    $form_ctl['to'] = array(
      '#type' => 'textfield',
      '#title' => t('To'),
      '#default_value' => @$config['to'],
    );
    $form_ctl['cc'] = array(
      '#type' => 'textfield',
      '#title' => t('Cc'),
      '#default_value' => @$config['cc'],
    );
    $form_ctl['bcc'] = array(
      '#type' => 'textfield',
      '#title' => t('Bcc'),
      '#default_value' => @$config['bcc'],
    );
    $form_ctl['subject'] = array(
      '#type' => 'textfield',
      '#title' => t('Subject'),
      '#default_value' => @$config['subject'],
    );
    $form_ctl['body'] = array(
      '#type' => 'text_format',
      '#title' => t('Message'),
      "#format" => $this->email_input_format,
      '#default_value' => @$config['body']['value'],
    );
    return $form_ctl;
  }
  public function configValidate(&$config) {
    $this
      ->validateTextFormats($config, array(
      'body',
    ));
  }
  public function generate() {
    $config = $this->configuration;
    $from = @$config['from'];
    $to = @$config['to'];
    $cc = @$config['cc'];
    $bcc = @$config['bcc'];
    $subject = @$config['subject'];
    $body = @$config['body'];
    $body = $body['value'];
    $config['foreach'] = "*";
    $div = $this
      ->blockDiv($config);
    $this
      ->removeChildren($div);
    $doc = $this
      ->addNode($div, 4, 'div', NULL, array(
      'class' => 'email-document',
    ));
    $header = $this
      ->addNode($doc, 6, 'div', NULL, array(
      'class' => 'email-header',
    ));
    $table = $this
      ->addNode($header, 8, 'table');
    $tr = $this
      ->addNode($table, 10, 'tr');
    $td = $this
      ->addNode($tr, 12, 'th', 'From');
    $td = $this
      ->addNode($tr, 12, 'td', htmlentities($from), array(
      'class' => 'email-header-from',
    ));
    $tr = $this
      ->addNode($table, 10, 'tr');
    $td = $this
      ->addNode($tr, 12, 'th', 'To');
    $td = $this
      ->addNode($tr, 12, 'td', htmlentities($to), array(
      'class' => 'email-header-to',
    ));
    if ($cc) {
      $tr = $this
        ->addNode($table, 10, 'tr');
      $td = $this
        ->addNode($tr, 12, 'th', 'Cc');
      $td = $this
        ->addNode($tr, 12, 'td', htmlentities($cc), array(
        'class' => 'email-header-cc',
      ));
    }
    if ($bcc) {
      $tr = $this
        ->addNode($table, 10, 'tr');
      $td = $this
        ->addNode($tr, 12, 'th', 'Bcc');
      $td = $this
        ->addNode($tr, 12, 'td', htmlentities($bcc), array(
        'class' => 'email-header-bcc',
      ));
    }
    $tr = $this
      ->addNode($table, 10, 'tr');
    $td = $this
      ->addNode($tr, 12, 'th', 'Subject');
    $td = $this
      ->addNode($tr, 12, 'td', $subject, array(
      'class' => 'email-header-subject',
    ));
    $email_body = $this
      ->addNode($doc, 6, 'div', NULL, array(
      'class' => 'email-body',
    ));
    $p = $this
      ->addFragment($email_body, $body);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FrxAPI::app public function Returns containing application service
FrxAPI::currentDataContext public function Get the current data context.
FrxAPI::currentDataContextArray public function
FrxAPI::dataManager public function Returns the data manager service
FrxAPI::dataService public function Return Data Service
FrxAPI::documentManager public function Returns the fornea document manager
FrxAPI::error public function Report an error
FrxAPI::getDataContext public function Get the context of a specific id.
FrxAPI::getDocument public function Get the current document
FrxAPI::getReportFileContents public function Load the contents of a file in the report file system.
FrxAPI::popData public function Pop data off of the stack.
FrxAPI::pushData public function Push data onto the Stack
FrxAPI::report public function Run a report with a particular format. 1
FrxAPI::reportFileSystem public function Get the current report file system.
FrxAPI::setDataContext public function Set Data context by id.
FrxAPI::setDocument public function Change to a specific document type.
FrxAPI::skins public function Get list of skins.
FrxEmailMerge::$email_input_format public property
FrxEmailMerge::$templateName public property
FrxEmailMerge::configForm public function
FrxEmailMerge::configValidate public function
FrxEmailMerge::generate public function Overrides TemplateInterface::generate
FrxEmailMerge::scrapeConfig public function Overrides TemplateInterface::scrapeConfig
FrxEmailMerge::__construct public function
TemplateBase::$columns public property
TemplateBase::$configuration public property @var array Confiuration of template
TemplateBase::$id public property
TemplateBase::$name public property
TemplateBase::$numeric_columns public property
TemplateBase::$xmlns public property
TemplateBase::columns public function Extract a list of columns from the data context.
TemplateBase::configure public function Overrides TemplateInterface::configure
TemplateBase::innerXML public function Return the inside xml of the current node Overrides FrxAPI::innerXML