You are here

function forena_get_formatter in Forena Reports 7

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

Load the formatters for all initialized repositories.

1 call to forena_get_formatter()
forena_format_data in ./forena.common.inc

File

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

Code

function forena_get_formatter($fkey) {

  // Get all repositories
  $repos = forena_repository();
  $formats = array();
  foreach ($repos as $k => $r) {
    $provider = isset($r['data']) ? $r['data'] : NULL;
    if ($provider && method_exists($provider, 'formats')) {
      $f = $provider
        ->formats();
      if (isset($f[$fkey]) && method_exists($provider, $fkey)) {

        // We found an object with the advertised method return it
        return $provider;
      }
    }
  }

  //Did not find the formater in the data provider

  //Look to see if it's in a control class
  $controls = forena_define_controls();
  foreach ($controls as $k => $r) {
    $provider = $r;
    if ($provider && method_exists($provider, 'formats')) {
      $f = $provider
        ->formats();
      if (isset($f[$fkey]) && method_exists($provider, $fkey)) {

        // We found an object with the advertised method return it
        return $provider;
      }
    }
  }
  return $formats;
}