You are here

public function ReportManager::report in Forena Reports 8

Generate a forena report

Parameters

$base_name:

Return value

array | string Report or doucment.

File

src/ReportManager.php, line 74
Implements \Drupal\forena\File\ReportFileSystem

Class

ReportManager
Access to Report rendering engine.

Namespace

Drupal\forena

Code

public function report($report_name, $parms = []) {
  $format = $this
    ->formatFromPath($report_name);
  $base_name = $report_name;

  //@TODO: report loading based on language
  $content = NULL;
  $file_name = str_replace('.', '/', $report_name) . '.frx';
  $r = ReportFileSystem::instance();

  // Find out if the report exists
  if ($r
    ->exists($file_name)) {
    $metaData = $r
      ->getMetaData($file_name);
    $frx = $r
      ->contents($file_name);
    $r = new Report($frx);
    if ($this
      ->checkAccess($r->access)) {
      DocManager::instance()
        ->setDocument($format);
      $dataSvc = DataManager::instance()->dataSvc;
      $dataSvc
        ->setContext('report', $metaData);
      $dataSvc
        ->setContext('site', AppService::instance()->siteContext);
      if (isset($_COOKIE)) {
        $dataSvc
          ->setContext('cookie', $_COOKIE);
      }
      $doc = DocManager::instance()
        ->getDocument();
      $doc
        ->clear();
      $doc
        ->header();
      $parms = array_merge($r
        ->getDefaultParameters(), $parms);
      $dataSvc
        ->push($parms, 'parm');
      $doc
        ->setSkin($r->skin);
      DocManager::instance()
        ->setFilename($base_name);
      $r
        ->render($format);
      $doc->title = $r->title;
      $doc
        ->footer();
      $dataSvc
        ->pop();
      $r
        ->buildParametersForm();
      $content = $doc
        ->flush();
    }
    else {
      $content = FALSE;
    }
  }
  return $content;
}