You are here

public function FrxReport::__construct in Forena Reports 6.2

Same name and namespace in other branches
  1. 6 FrxReport.inc \FrxReport::__construct()
  2. 7 FrxReport.inc \FrxReport::__construct()
  3. 7.2 FrxReport.inc \FrxReport::__construct()
  4. 7.3 FrxReport.inc \FrxReport::__construct()
  5. 7.4 FrxReport.inc \FrxReport::__construct()

File

./FrxReport.inc, line 30
Basic report provider. Controls the rendering of the report.

Class

FrxReport

Code

public function __construct($xhtml, $data = array()) {
  $this->access = array();
  $this->parameters = array();
  $this->options = array();
  $this->root_data = $data;
  $this->frx_data = FrxData::instance();
  $this->frx_data;
  $this->teng = new FrxSyntaxEngine(FRX_TOKEN_EXP, '{}', $this, $this->frx_data);
  if ($xhtml) {
    $dom = $this->dom = new DOMDocument('1.0', 'UTF-8');

    // Old assumption is an ojbect is a simplexml one
    if (is_object($xhtml)) {
      $xhtml = $xhtml
        ->asXML();
    }

    // Load document and simplexml representation
    $dom
      ->loadXML($xhtml);
    $dom->formatOutput = TRUE;
    $rpt_xml = $this->rpt_xml = simplexml_import_dom($dom);

    // Loaod data if its there.
    $this->frx_data
      ->push($data, 'parm');

    // Load header data
    $this->body = $rpt_xml->body;
    if ($rpt_xml->head) {
      $this->title = (string) $rpt_xml->head->title;
      foreach ($rpt_xml->head
        ->children(FRX_NS) as $name => $node) {
        switch ($name) {
          case 'fields':
            $this->fields = $node;
            break;
          case 'category':
            $this->category = (string) $node;
            break;
          case 'descriptor':
            $this->descriptor = (string) $node;
            break;
          case 'options':
            foreach ($node
              ->attributes() as $key => $value) {
              $this->options[$key] = (string) $value;
            }
            break;
          case 'form':
            $this->form = (string) $value;
            break;
          case 'parameters':
            foreach ($node
              ->children(FRX_NS) as $key => $node) {
              $parm = array();
              foreach ($node
                ->attributes() as $akey => $attr) {
                $parm[$akey] = (string) $attr;
              }
              $id = $parm['id'];
              $val = isset($parm['value']) ? $parm['value'] : '';
              $parm['value'] = (string) $node ? (string) $node : $val;
              $this->parameters[$id] = $parm;
            }
            break;
          case 'doctypes':
            $this->doctypes = $value;
            break;
        }
      }
    }
  }
}