You are here

class DocumentBase in Forena Reports 8

Hierarchy

Expanded class hierarchy of DocumentBase

4 files declare their use of DocumentBase
DocRaptorPDF.php in forena_pdf/src/FrxPlugin/Document/DocRaptorPDF.php
PrincePDF
FrxAPI.php in src/FrxAPI.php
FrxAPI.incL General Forena Reporting Class
MPDF.php in forena_pdf/src/FrxPlugin/Document/MPDF.php
MPDF.inc PDF document via MPDF Library @author davidmetzler
PrincePDF.php in forena_pdf/src/FrxPlugin/Document/PrincePDF.php
PrincePDF

File

src/FrxPlugin/Document/DocumentBase.php, line 15
DocumentBase.inc Given a report, render the appropriate output given the document format. @author davidmetzler

Namespace

Drupal\forena\FrxPlugin\Document
View source
class DocumentBase implements DocumentInterface {
  use FrxAPI;
  public $format = '';
  public $buffer = TRUE;
  protected $filename = '';
  public $parameters_form = [];

  // Reort Write buffer.
  protected $write_buffer;

  // Contains CSS and Java script libraries
  public $libraries;

  // Page or report title
  public $title;

  // Ajax Commands
  protected $commands;

  // Skin definition
  protected $skin;

  // Skin assocatiated with the report
  protected $skin_name;
  public $file_name;
  public $content_type = '';
  public $charset = 'UTF-8';
  public $headers;
  public function clear() {
    $this->write_buffer = '';
    $this->pre_commands = [];
    $this->parameters_form = [];
    $this->commands = [];
  }

  /**
   * Default implementation to put in content type based headers.
   */
  public function header() {
    $this->write_buffer = '';
    if ($this->content_type) {
      $this->headers = [];
      $this->headers['Content-Type'] = $this->content_type . ' ;charset=' . $this->charset;
      $this->headers['Cache-Control'] = '';
      $this->headers['Pragma'] = '';

      //$file_name = basename($_GET['q']);
      if ($this->file_name) {
        $this->headers['Content-Disposition:'] = 'attachment; filename="' . $this->file_name . '"';
      }
    }
  }

  /**
   * @param string $skin_name
   *   name/path of the skin to load.
   */
  public function setSkin($skin_name) {
    $this->skin_name = $skin_name;
    $this->skin = Skin::instance($skin_name);
  }
  public function setFilename($filename) {
    $this->file_name = $filename;
  }

  // All document objects must implement this method.
  public function flush() {
    return $this->write_buffer;
  }
  public function write($buffer) {
    if ($this->buffer) {
      $this->write_buffer .= $buffer;
    }
  }

  /**
   * Wrapper function for check output to default the right type.
   * @param string $output
   */
  public function check_markup($output) {
    return check_markup($output, \Drupal::config('forena.settings')
      ->get('input_format'));
  }

  /**
   * Perform character set conversion
   * @param $data
   * @param string $default_encoding
   * @return string
   */
  public function convertCharset($data, $default_encoding = 'UTF-8') {
    if (isset($_SERVER['HTTP_ACCEPT_CHARSET'])) {
      $parts = @explode(';', $_SERVER['HTTP_ACCEPT_CHARSET']);
      $parts = @explode(',', $parts[0]);
      $to_encoding = @$parts[0];
    }
    else {
      $to_encoding = $default_encoding;
    }
    if ($to_encoding != 'UTF-8') {
      $this->charset = $to_encoding;
      $data = mb_convert_encoding($data, $to_encoding, 'UTF-8');
    }
    return $data;
  }

  /**
   * @param array $ajax
   *   The Array of coommand objects
   * @param string $event
   *   'pre' implies pre replacement firing of events.
   */
  public function addAjaxCommand($ajax, $event) {
    $command = $ajax['command'];
    $plugins = AppService::instance()
      ->getAjaxPlugins();
    if (isset($plugins[$command])) {
      $class = $plugins[$command];

      /** @var AjaxCommandInterface $command */
      $command = new $class();
      $ajax_command = $command
        ->commandFromSettings($ajax);
      if ($ajax_command) {
        $this->commands[$event][] = $ajax_command;
      }
    }
  }

  /**
   * @return array
   *   Array of ajax commands that are built.
   */
  public function getAjaxCommands() {
    return $this->commands;
  }

  /**
   * No default footer.
   */
  public function footer() {
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DocumentBase::$buffer public property
DocumentBase::$charset public property
DocumentBase::$commands protected property
DocumentBase::$content_type public property
DocumentBase::$filename protected property
DocumentBase::$file_name public property
DocumentBase::$format public property
DocumentBase::$headers public property
DocumentBase::$libraries public property
DocumentBase::$parameters_form public property
DocumentBase::$skin protected property
DocumentBase::$skin_name protected property
DocumentBase::$title public property
DocumentBase::$write_buffer protected property
DocumentBase::addAjaxCommand public function
DocumentBase::check_markup public function Wrapper function for check output to default the right type.
DocumentBase::clear public function Clear the buffer Overrides DocumentInterface::clear
DocumentBase::convertCharset public function Perform character set conversion
DocumentBase::flush public function Write the output to disk. Overrides DocumentInterface::flush 9
DocumentBase::footer public function No default footer. Overrides DocumentInterface::footer 1
DocumentBase::getAjaxCommands public function
DocumentBase::header public function Default implementation to put in content type based headers. Overrides DocumentInterface::header 8
DocumentBase::setFilename public function Overrides DocumentInterface::setFilename
DocumentBase::setSkin public function Overrides DocumentInterface::setSkin
DocumentBase::write public function Write Overrides DocumentInterface::write
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::innerXML function Enter description here... 1
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.