You are here

class FrxDataProvider in Forena Reports 6

Same name and namespace in other branches
  1. 6.2 FrxDataProvider.inc \FrxDataProvider
  2. 7 FrxDataProvider.inc \FrxDataProvider
  3. 7.2 FrxDataProvider.inc \FrxDataProvider

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

Hierarchy

Expanded class hierarchy of FrxDataProvider

File

./FrxDataProvider.inc, line 7
Class that defines default methods for access control in an FrxDataProvider

View source
class FrxDataProvider {
  public $conf;
  public $block_path;
  public $comment_prefix;
  public $comment_suffix;
  public $block_ext;
  protected $te;
  public function __construct($conf, $repos_path) {
    $this->conf = $conf;
    $this->comment_prefix = '--';
    $this->block_ext = 'sql';
    $this->block_path = $repos_path;
  }

  /**
   * Implements the basic default security check of calling
   * an access method.
   *
   * @param unknown_type $arg
   * @return unknown
   */
  public function access($arg) {
    $f = $this->conf['access callback'];
    if ($f && is_callable($f)) {
      return $f($arg);
    }
    elseif (isset($this->conf['access block'])) {
      $block = $this->conf['access block'];
      if (isset($this->conf['access path'])) {
        $path = $this->conf['access path'];
      }
      return forena_block_access($block, $path, $arg);
    }
    else {
      return user_access('access content');
    }
  }

  /**
   * Default block load
   * Loads the data block based on the block name from the file system.  The classes that
   * are derived from this will set the block_ext property, which in most cases is .sql but
   * might be something different.   The load of the block file should return data, access and
   * probably parameters to.
   * @param unknown_type $block_name
   * @return unknown
   */
  public function load_block($block_name, $clause = '') {
    $filename = $this->block_path . '/' . $block_name . '.' . $this->block_ext;
    $block = forena_load_block_file($filename, $this->comment_prefix, $this->comment_suffix);

    // If we have a regular expression token parser, then get the tokens out of the block.
    if ($this->te) {
      $tokens = $this->te
        ->tokens($block['source']);

      //drupal_set_message("tokens: ". print_r($tokens, 1));

      //check tokens in the where clause
      if ($clause) {
        $clause_tokens = $this->te
          ->tokens($clause);

        //drupal_set_message("clause tokens: ". print_r($clause_tokens, 1));
        $temp = array();
        $temp = array_merge($tokens, $clause_tokens);

        //check for duplicates in block tokens
        if ($clause_tokens) {
          foreach ($clause_tokens as $ct) {
            if (!$temp[$ct]) {
              array_push($tokens, $ct);
            }
          }
        }
      }
      $block['tokens'] = $tokens;
    }
    return $block;
  }

  /**
   * Find all the blocks matching a provided search string
   *
   * @param string $search part block names to search for
   * @return unknown
   */
  public function list_blocks($search, $subdir = '', $this_list = array()) {
    $block_list = $this_list;

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

    // 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;
        }
        $block_list[] = str_replace($this->block_path . '/', '', $block_name);
      }
    }

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

}

Members

Namesort descending Modifiers Type Description Overrides
FrxDataProvider::$block_ext public property
FrxDataProvider::$block_path public property
FrxDataProvider::$comment_prefix public property
FrxDataProvider::$comment_suffix public property
FrxDataProvider::$conf public property
FrxDataProvider::$te protected property
FrxDataProvider::access public function Implements the basic default security check of calling an access method.
FrxDataProvider::list_blocks public function Find all the blocks matching a provided search string
FrxDataProvider::load_block public function Default block load Loads the data block based on the block name from the file system. The classes that are derived from this will set the block_ext property, which in most cases is .sql but might be something different. The load of the block file…
FrxDataProvider::__construct public function 6