You are here

public function FrxReportFile::reportsByCategory in Forena Reports 7.4

Generate an ordered list of reports by category

Parameters

$categories:

Return value

array Categories

File

./FrxReportFile.inc, line 125

Class

FrxReportFile

Code

public function reportsByCategory($categories = array()) {
  global $language;
  $this
    ->validateAllCache();
  $data = $this
    ->allReports();
  $reports = array();
  if ($data) {
    foreach ($data as $base_name => $obj) {
      if ($obj->cache && @$obj->cache['category'] && !$obj->cache['hidden']) {
        $cache = $obj->cache;
        if (!$categories || array_search($cache['category'], $categories) !== FALSE) {

          // Check each callback function to see if we have an error.
          $access = FALSE;
          if (@$cache['access']) {
            foreach ($cache['access'] as $provider => $callbacks) {
              if (user_access('access ' . $provider . ' data')) {
                foreach ($callbacks as $callback => $args) {
                  if ($callback) {
                    foreach ($args as $arg) {
                      if (function_exists($callback) && $arg) {
                        $a = $callback($arg);
                        if ($a) {
                          $access = TRUE;
                        }
                      }
                      else {
                        $access = TRUE;
                      }
                    }
                  }
                  else {
                    $access = TRUE;
                  }
                }
              }
            }
          }
          if ($access) {
            $reports[$cache['category']][] = array(
              'title' => $cache['title'],
              'category' => $cache['category'],
              'report_name' => $base_name,
            );
          }
        }
      }
    }
  }
  $sort = defined('SORT_NATURAL') ? SORT_NATURAL : SORT_REGULAR;

  // Sort the reports
  if ($reports) {
    foreach ($reports as $category => $list) {
      uasort($reports[$category], 'FrxReportFile::reportTitleCompare');
    }
  }
  ksort($reports, $sort);
  return $reports;
}