You are here

public function DriverBase::listDataBlocks in Forena Reports 8

Find all the blocks matching a provided search string

@TODO: MOve toDat Manageer

Parameters

string $search : partial block names to search for

array $block_list: List of blocks to build

string $subdir: Subdirectory being examined. Used primarily for recursion.

File

src/FrxPlugin/Driver/DriverBase.php, line 193
Class that defines default methods for access control in an DriverBase

Class

DriverBase

Namespace

Drupal\forena\FrxPlugin\Driver

Code

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

  // First find files that match the search string
  $path = $this->fileSvc->includes[0] . '/';
  if ($subdir) {
    $path .= $subdir . '/';
  }
  $block_path = $path . '*' . $search . '*';

  // Find sql files
  // @TODO: Refactor to use file service to list 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($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($apth . '/', '', $block_name);
          }
      }
    }
  }
  $count++;

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

  // Date
  if (!$subdir && \Drupal::moduleHandler()
    ->moduleExists('forena_query')) {
    $this
      ->listDBBlocks($search, $block_list);
  }
}