You are here

public function FrxEditor::save_attributes_by_id in Forena Reports 7.3

Same name and namespace in other branches
  1. 7.4 FrxEditor.inc \FrxEditor::save_attributes_by_id()

Save attributes based on id match

Parameters

array $attributes:

The attributes array should be of the form array( element_id => array( key1 => value1, key2 => value2) The function restores the attributes based on the element id.

File

./FrxEditor.inc, line 503
FrxEditor.inc Wrapper XML class for working with DOM object. It provides helper Enter description here ... @author metzlerd

Class

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

Code

public function save_attributes_by_id($attributes) {
  $rpt_xml = $this->simplexml;
  if ($attributes) {
    foreach ($attributes as $id => $att_list) {
      $id_search_path = '//*[@id="' . $id . '"]';
      $fnd = $rpt_xml
        ->xpath($id_search_path);
      if ($fnd) {
        $node = $fnd[0];

        // Start attribute replacement
        $frx_attributes = $node
          ->Attributes(FRX_NS);
        foreach ($att_list as $key => $value) {
          if (!$frx_attributes[$key]) {
            if ($value) {
              $node['frx:' . $key] = $value;
            }
          }
          else {
            unset($frx_attributes[$key]);
            if ($value) {
              $node['frx:' . $key] = $value;
            }
          }
        }
      }
    }
  }
}