Skip to content
Snippets Groups Projects
Select Git revision
  • 7.x-3.7
  • 7.x-4.x default
  • 8.x-1.x
  • 8.x-dev-ui
  • 7.x-5.x
  • 7.x-3.x
  • 6.x-2.x
  • 7.x-2.x
  • 6.x-1.x
  • 7.x-1.x
  • master
  • 7.x-4.12
  • 7.x-4.11
  • 7.x-4.10
  • 7.x-4.9
  • 7.x-4.8
  • 7.x-4.7
  • 7.x-4.6
  • 7.x-4.5
  • 7.x-4.4
  • 7.x-4.3
  • 7.x-4.2
  • 7.x-4.1
  • 7.x-4.0
  • 7.x-4.0-beta4
  • 7.x-4.0-beta3
  • 7.x-4.0-beta2
  • 7.x-4.0-beta1
  • 7.x-4.0-alpha8
  • 7.x-4.0-alpha7
  • 7.x-4.0-alpha6
31 results

FrxRenderer.inc

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    FrxRenderer.inc 3.97 KiB
    <?php
    /**
     * @file FrxRenderer.inc
     * Base class for Frx custom renderers
     * @author davidmetzler
     *
     */
    class FrxRenderer {
      public $teng;           // Token replacement engine.
      public $reportDocDomNode; //A Dom node version of the element.  This is important if you want to walk text nodes.
      public $reportDocNode;  // SimpleXML Report Document Node -- The node of the report we are rendering
      public $frxAttributes;  // Frx Attributes of the node we are rendering.
      public $htmlAttributes;  // Html attributes of the node that we are rendering
      public $dataProvider;   // An FrxData instance that provides the data assiated with the report.
      public $name;
      public $id;
      public $format;
      public $frxReport;  // The report object being used.
    
    
      public function __construct($domNode = NULL, $teng = NULL, $frxReport = NULL) {
        if ($domNode) {
          $this->initReportNode($domNode, $teng);
        }
      }
    
      public function initReportNode($domNode, $frxReport, $format='web') {
        $this->format= $format;
        $this->reportDocDomNode = $domNode;
        $this->dataProvider = Frx::Data();
        $this->reportDocNode = simplexml_import_dom($domNode);
        $node = $this->reportDocNode;
        $this->name = $node->getName();
        $this->htmlAttributes = $node->attributes();
        $this->id = (string)$this->htmlAttributes['id'];
        $this->frxAttributes = $node->attributes(FRX_NS);
        $this->teng = $frxReport->teng;
        $this->frxReport = $frxReport;
      }
    
      public function replaceTokens($text, $raw_mode=FALSE) {
        return $this->teng->replace($text, $raw_mode);
      }
    
      public function render() {
        // Get the data that we're working with
        $xml = $this->dataProvider->getCurrentContext();
        $node = $this->nodes;
        // We can render so lets do it.
        $text = $this->xmlNode->asXML();
        $o = $this->teng->replace($text);
        return $o;
      }
    
      public static function addAttributes(&$attributes, $key, $value) {
        @list($part, $suff) = explode('_', $key);
        // If we have _0 _1 _2 attributes convert them into arrays.
        if ((int)$suff || $suff === '0') {
          $attributes[$part][] = (string)$value;
        }
        else {
          $attributes[$key] = (string)$value;
        }
      }
    
      /**
       * Standard php array containing merged attributes
       * Enter description here ...
       */
      public function mergedAttributes() {
        $attributes = array();
        if (isset($this->frxAttributes)) foreach ($this->frxAttributes as $key => $data) {
          FrxRenderer::addAttributes($attributes, $key, $data);
        }
        if (isset($this->htmlAttributes)) foreach ($this->htmlAttributes as $key => $data) {
          FrxRenderer::addAttributes($attributes, $key, $data);
        }
        $skin_data = Frx::Data()->getContext('skin');
        $class = get_class($this);
        if (isset($skin_data[$class])) {
          $attributes = array_merge($attributes, $skin_data[$class]);
        }
        $classes = class_parents($this);
        array_pop($classes);
        if ($classes) foreach ($classes as $class) {
          if (isset($skin_data[$class])) {
            $attributes = array_merge($attributes, $skin_data[$class]);
          }
        }
        return $attributes;
      }
    
      public function replacedAttributes() {
        $attributes = array();
        if (isset($this->frxAttributes)) foreach ($this->frxAttributes as $key => $data) {
          $attributes[$key] =  $this->teng->replace((string)$data, TRUE);
        }
        if (isset($this->htmlAttributes)) foreach ($this->htmlAttributes as $key => $data) {
          $attributes[$key] = $this->teng->replace((string)$data, TRUE);
        }
        return $attributes;
      }
    
      /**
       * Return the inside xml of the current node
       *
       */
      public function innerXML() {
        $xml = $this->reportDocNode;
        $tag = $xml->getName();
        $text = '';
        if (is_object($xml) && is_object($xml->$tag)) {
          $text = $xml->asXML();
          $text = preg_replace("/<\/?" . $tag . "(.|\s)*?>/", "", $text);
        }
        return $text;
      }
    
      /**
       * Render a drupal form in a forena template
       * @param $form array
       */
      public function drupalRender($form) {
        $output = drupal_render($form);
        return $output;
      }
    
    
    }