You are here

public function Report::parse_ids in Forena Reports 8

Same name and namespace in other branches
  1. 7.5 src/Report.php \Drupal\forena\Report::parse_ids()

Make sure all xml elements have ids

File

src/Report.php, line 480
Basic report provider. Controls the rendering of the report.

Class

Report

Namespace

Drupal\forena

Code

public function parse_ids() {
  $i = 0;
  if ($this->rpt_xml) {
    $this->rpt_xml
      ->registerXPathNamespace('frx', Report::FRX_NS);
    $frx_attributes = array();
    $frx_nodes = $this->rpt_xml
      ->xpath('body//*[@frx:*]');
    if ($frx_nodes) {
      foreach ($frx_nodes as $node) {
        $attr_nodes = $node
          ->attributes(Report::FRX_NS);
        if ($attr_nodes) {

          // Make sure every element has an id
          $i++;
          $id = 'forena-' . $i;
          if (!isset($node['id'])) {
            $node
              ->addAttribute('id', $id);
          }
          else {
            if (strpos((string) $node['id'], 'forena-') === 0) {

              // Reset the id to the numerically generated one
              $node['id'] = $id;
            }
            else {

              // Use the id of the element
              $id = (string) $node['id'];
            }
          }

          // Save away the frx attributes in case we need them later.
          $attr_nodes = $node
            ->attributes(Report::FRX_NS);
          $attrs = array();
          if ($attr_nodes) {
            foreach ($attr_nodes as $key => $value) {
              $attrs[$key] = (string) $value;
            }
          }

          // Save away the attributes
          $frx_attributes[$id] = $attrs;
        }
      }
    }
    $this->frx_attributes = $frx_attributes;
  }
}