You are here

function forena_load_cache in Forena Reports 7.4

Same name and namespace in other branches
  1. 8 forena.common.inc \forena_load_cache()
  2. 6.2 forena.common.inc \forena_load_cache()
  3. 6 forena.common.inc \forena_load_cache()
  4. 7.5 forena.common.inc \forena_load_cache()
  5. 7 forena.common.inc \forena_load_cache()
  6. 7.2 forena.common.inc \forena_load_cache()
  7. 7.3 forena.common.inc \forena_load_cache()

Build cache

Parameters

xhtml $r_xhtml Forena XML report.:

Return value

array data to be stored in the cache field for the report in the database.

4 calls to forena_load_cache()
forena_save_report in ./forena.common.inc
Save the report file to disk
FrxEditor::load in ./FrxEditor.inc
Load report from file system
FrxReportFile::buildCache in ./FrxReportFile.inc
Should load cache data based on that.
FrxReportGenerator::report in ./FrxReportGenerator.inc
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.

File

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

Code

function forena_load_cache($r_xhtml) {
  $conf = array();
  $cache = array();
  $blocks = array();
  $repos = array();
  $nodes = array();
  if (is_object($r_xhtml)) {
    $head = @$r_xhtml->head;
    if ($head) {
      $nodes = $head
        ->xpath('frx:menu');
    }
    $menu = array();
    if ($nodes) {
      $m = $nodes[0];
      $attrs = $m
        ->attributes();
      foreach ($attrs as $key => $value) {
        $menu[$key] = (string) $value;
      }
    }
    if ($menu) {
      $cache['menu'] = $menu;
    }
    $block_xml = $r_xhtml
      ->xpath('//*[@frx:block]');

    // Extract all the blocks and organize by provider
    foreach ($block_xml as $key => $block_node) {
      $attrs = $block_node
        ->attributes('urn:FrxReports');
      foreach ($attrs as $key => $value) {
        if ($key == 'block') {
          @(list($provider, $block) = explode('/', $value, 2));
          $repos[$provider][] = $block;
        }
      }
    }
    if ($repos) {
      foreach ($repos as $provider_key => $blocks) {
        $provider = Frx::RepoMan()
          ->repository($provider_key);
        if (isset($provider->conf)) {
          $conf = $provider->conf;
        }
        $access = array();
        foreach ($blocks as $block_name) {
          if ($provider && $block_name) {
            if (method_exists($provider, 'loadBlock')) {
              $conf = $provider->conf;
              $block = $provider
                ->loadBlock($block_name);
              $obj = @$block['access'];
              if (array_search($obj, $access) === FALSE) {
                $access[] = $obj;
              }
            }
          }
        }
        if (isset($conf['access callback']) && $access) {
          $cache['access'][$provider_key][$conf['access callback']] = $access;
        }
      }
    }
  }
  return $cache;
}