You are here

function forena_load_cache in Forena Reports 7.2

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.3 forena.common.inc \forena_load_cache()
  7. 7.4 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.

1 call to forena_load_cache()
forena_save_report in ./forena.admin.inc
Save the report file to disk

File

./forena.common.inc, line 60
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();
  if (is_object($r_xhtml)) {
    $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 => $blocks) {
        $repos = FrxReportGenerator::instance()
          ->repository($provider);
        $provider = $repos['data'];
        if (isset($provider->conf)) {
          $conf = $provider->conf;
        }
        $access = array();
        foreach ($blocks as $block_name) {
          if ($provider && $block_name) {
            if (method_exists($provider, 'load_block')) {
              $conf = $provider->conf;
              $block = $provider
                ->load_block($block_name);
              if (isset($block['access']) && array_search($block['access'], $access) === FALSE) {
                $access[] = $block['access'];
              }
            }
          }
          else {

            //drupal_set_message('no provider found', 'error');
          }
        }
        if (isset($conf['access callback']) && $access) {
          $cache['access'][$conf['access callback']] = $access;
        }
      }
    }
  }
  return $cache;
}