You are here

public function FrxReportEditor::save_attributes_by_id in Forena Reports 7.2

Same name and namespace in other branches
  1. 6.2 FrxReportEditor.inc \FrxReportEditor::save_attributes_by_id()
  2. 6 FrxReportEditor.inc \FrxReportEditor::save_attributes_by_id()
  3. 7 FrxReportEditor.inc \FrxReportEditor::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

./FrxReportEditor.inc, line 445

Class

FrxReportEditor
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;
            }
          }
        }
      }
    }
  }
}