You are here

public function FrxReport::__construct in Forena Reports 7

Same name and namespace in other branches
  1. 6.2 FrxReport.inc \FrxReport::__construct()
  2. 6 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 28
Basic report provider. Controls the rendering of the report.

Class

FrxReport

Code

public function __construct($xhtml, $data = array()) {
  $this->teng = new FrxSyntaxEngine(FRX_TOKEN_EXP, '{}', $this);
  $this->access = array();
  $this->parameters = array();
  $this->options = array();
  $this->root_data = $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->cur_data = $data;
    $this->teng
      ->push_data($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 '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;
        }
      }
    }
  }
}