You are here

private function FrxReportEditor::parse_ids in Forena Reports 6.2

Same name and namespace in other branches
  1. 6 FrxReportEditor.inc \FrxReportEditor::parse_ids()
  2. 7 FrxReportEditor.inc \FrxReportEditor::parse_ids()
  3. 7.2 FrxReportEditor.inc \FrxReportEditor::parse_ids()

Make sure all xml elements have ids

1 call to FrxReportEditor::parse_ids()
FrxReportEditor::get_attributes_by_id in ./FrxReportEditor.inc
Get the attributes by

File

./FrxReportEditor.inc, line 379

Class

FrxReportEditor
Wrapper XML class for working with DOM object. It provides helper Enter description here ... @author metzlerd

Code

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

          // Make sure every element has an id
          $i++;
          $id = 'forena-' . $i;
          if (!(string) $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(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;
  }
}