You are here

function forena_get_categories in Forena Reports 7

Same name and namespace in other branches
  1. 8 forena_ui/forena.admin.inc \forena_get_categories()
  2. 6.2 forena.admin.inc \forena_get_categories()
  3. 6 forena.admin.inc \forena_get_categories()
  4. 7.5 forena.admin.inc \forena_get_categories()
  5. 7.2 forena.admin.inc \forena_get_categories()
  6. 7.3 forena.admin.inc \forena_get_categories()
  7. 7.4 forena.admin.inc \forena_get_categories()

Auto complete function for categories Checks access for security as well.

Parameters

$string = string to be matched against categories:

Return value

An array containing all matching categories

1 call to forena_get_categories()
forena_categories_autocomplete in ./forena.module
Auto complete for categories

File

./forena.admin.inc, line 1443

Code

function forena_get_categories($string = '') {
  $result = db_query("SELECT * FROM {forena_reports} where hidden=0 AND category LIKE :category ORDER BY category, title asc", array(
    ':category' => $string . '%',
  ));
  $categories = array();
  foreach ($result as $row) {
    $access = TRUE;
    $cache = $row->cache;
    if ($cache) {
      $cache = unserialize($cache);

      // Check each callback function to see if we have an error.
      if ($cache['access']) {
        foreach ($cache['access'] as $callback => $args) {
          if ($callback) {
            foreach ($args as $arg) {
              $access = FALSE;
              if (function_exists($callback)) {
                $a = $callback($arg);
              }
              if ($a) {
                $access = TRUE;
              }
            }
          }
          else {
            $access = TRUE;
          }
        }
      }
    }
    if ($access && !$categories[$row->category]) {
      $categories[$row->category] = $row->category;
    }
  }
  return $categories;
}