You are here

public function FrxDataSource::list_blocks in Forena Reports 7.3

Same name and namespace in other branches
  1. 7.4 FrxDataSource.inc \FrxDataSource::list_blocks()

Find all the blocks matching a provided search string

Parameters

string $search part block names to search for:

Return value

unknown

File

./FrxDataSource.inc, line 190
Class that defines default methods for access control in an FrxDataSource

Class

FrxDataSource
@file Class that defines default methods for access control in an FrxDataSource

Code

public function list_blocks($search, &$block_list, $subdir = '') {
  static $count = 0;

  // First find files that match the search string
  if ($count > 100) {
    return;
  }
  $path = $this->block_path . '/';
  if ($subdir) {
    $path .= $subdir . '/';
  }
  $block_path = $path . '*' . $search . '*';

  // Find sql files
  $d = glob($block_path);
  if ($d) {
    foreach ($d as $file_name) {

      // Split off the extention
      $p = strripos($file_name, '.');
      if ($p !== FALSE) {
        $ext = substr($file_name, $p + 1);
        $block_name = substr($file_name, 0, $p);
      }
      else {
        $ext = '';
        $block_name = $file_name;
      }
      switch ($ext) {
        case 'inc':
          require_once $file_name;
          $class = str_replace($this->block_path . '/', '', $block_name);
          $methods = get_class_methods($class);
          if ($methods) {
            foreach ($methods as $method) {
              if ($method != 'tokens') {
                $block_list[] = $class . '.' . $method;
              }
            }
          }
          break;
        default:
          if (array_search($ext, $this->block_extensions) !== FALSE) {
            $block_list[] = str_replace($this->block_path . '/', '', $block_name);
          }
      }
    }
  }
  $count++;

  // Find directories
  $d = glob($path . '*');
  if ($d) {
    foreach ($d as $dir_name) {
      if (is_dir($dir_name)) {
        $dir_name = str_replace($this->block_path . '/', '', $dir_name);
        $this
          ->list_blocks($search, $block_list, $dir_name);
      }
    }
  }

  // Date
  if (!$subdir && module_exists('forena_query')) {
    $this
      ->listDBBlocks($search, $block_list);
  }
}