You are here

function forena_get_report in Forena Reports 7

Same name and namespace in other branches
  1. 6 forena.common.inc \forena_get_report()

Accepts the name of a file

Returns a xml object of the file.

5 calls to forena_get_report()
forena_data_block_delete in ./forena.admin.inc
Delete submit handler to delete report blocks
forena_data_block_form_submit in ./forena.admin.inc
The Preview submit handler for forena_add_block_form Renders datablock into a report
forena_parameters_report in ./forena.module
Calls forena_parameter_form in forena.common.inc
forena_report in ./forena.module
Load and render a report based on a drupal path. In this function the arglist is used to get the full path to the report.
_forena_filter_process in ./forena.module
Process tag replacement for xml filters

File

./forena.common.inc, line 359
Common functions used throughout the project but loaded in this file to keep the module file lean.

Code

function forena_get_report($report_name, $data = array()) {
  $r = null;
  if ($report_name) {
    $report_path = forena_report_path();
    $filename = $report_path . '/' . $report_name . '.frx';
    if (file_exists($filename)) {
      $r_text = file_get_contents($filename);
      $modified = filemtime($filename);
      $result = db_query("SELECT report_name, modified FROM {forena_reports} WHERE report_name=:report_name", array(
        ':report_name' => $report_name,
      ));
      $save = FALSE;

      // If the file modification time has changed then save.
      if ($rpt = $result
        ->fetchObject()) {
        if ($rpt->modified != $modified) {
          $save = TRUE;
        }
      }
      else {
        $save = TRUE;
      }
      try {
        $r = forena_report_object($r_text, $data);
      } catch (Exception $e) {
        forena_error('Unable to read report', $e
          ->getMessage());
      }
      if ($save) {
        require_once 'forena.admin.inc';
        forena_save_report($report_name, $r_text, FALSE);
      }
    }
    return $r;
  }
}