You are here

class FrxDataFile in Forena Reports 7.4

Hierarchy

Expanded class hierarchy of FrxDataFile

File

./FrxDataFile.inc, line 4

View source
class FrxDataFile extends FrxFile {
  private $report_cache = array();

  /**
   * Constructor
   *   Sets the initial reort directory
   */
  public function __construct() {

    // Load default directory from configuration.
    $report_path = variable_get('forena_query_data_path', '');
    if (!$report_path) {
      $report_path = drupal_realpath('private://data');
      if ($report_path) {
        if (!file_exists($report_path)) {
          @mkdir($report_path);
        }
      }
      if (!$report_path) {
        $report_path = conf_path() . '/data';
      }
    }

    // Add directories for data  repos.
    $default_directory = rtrim($report_path, '/');
    $repositories = Frx::RepoMan()->repositories;
    $directories = array();
    foreach ($repositories as $k => $repos) {
      $directories[$k] = $repos['path'];
    }
    foreach ($directories as $dir) {
      $this->includes[$k] = rtrim($dir, '/');
    }

    // Parent constructor.
    parent::__construct($default_directory, $directories, array(
      'sql',
      'xml',
      'inc',
    ));
  }

  /**
   * List all the reports for a language.
   * @return unknown
   */
  public function userBlocks($search = '*') {
    $blocks = array();
    $this
      ->validateAllCache();
    $sql = $this
      ->getCache('sql');
    $inc = $this
      ->getCache('inc');
    $xml = $this
      ->getCache('xml');
    $data = array_merge($xml, $sql, $inc);
    if ($data) {
      foreach ($data as $base_name => $obj) {
        if ($search == '*' || drupal_match_path($base_name, $search)) {
          if ($obj->cache) {
            $r = Frx::RepoMan()
              ->repository($obj->cache['provider']);
            if ($r && $r
              ->access($obj->cache['access'])) {
              $blocks[$base_name] = $obj;
            }
          }
        }
      }
    }
    uksort($blocks, 'FrxDataFile::blockCompare');
    return $blocks;
  }

  /**
   * Return the full path to the filename
   *   @param $filename
   */
  public function path($filename, $use_include = TRUE) {
    $path = $this->dir . '/' . $filename;
    if ($use_include && !file_exists($path)) {
      foreach ($this->includes as $prefix => $dir) {
        if (strpos($filename, $prefix) === 0) {
          $inc_file = substr($filename, strlen($prefix) + 1);
          if (file_exists($dir . '/' . $inc_file)) {
            $path = $dir . '/' . $inc_file;
          }
        }
      }
    }
    return $path;
  }
  public function scan($prefix = '') {
    if ($this->needScan) {

      // Add the base report files.
      $this
        ->scanInclude($this->dir, '');

      // Now add the module provided ones.
      if ($this->includes) {
        foreach ($this->includes as $repos => $directory) {
          $this
            ->scanInclude($directory, $repos . '/');
        }
      }
      $this->needScan = FALSE;
    }
  }

  /**
   * Sort compare function for sorting data by category then title.
   * @param unknown $a
   * @param unknown $b
   * @return number
   */
  public static function blockCompare($a, $b) {
    $c = strnatcasecmp($a, $b);
    return $c;
  }

  /**
   * Should load cache data based on that.
   * @see FrxFile::buildCache()
   */
  public function buildCache($ext, $base_name, &$object) {
    if ($base_name) {
      $block_name = $base_name;
      $parts = explode('/', $base_name);
      $provider = array_shift($parts);
      $block = Frx::RepoMan()
        ->loadBlock($block_name);
      $object->cache = array(
        'provider' => $provider,
        'name' => $block_name,
        'access' => @$block['access'],
        'type' => @$block['type'],
        'options' => @$block['options'],
      );
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FrxDataFile::$report_cache private property
FrxDataFile::blockCompare public static function Sort compare function for sorting data by category then title.
FrxDataFile::buildCache public function Should load cache data based on that. Overrides FrxFile::buildCache
FrxDataFile::path public function Return the full path to the filename Overrides FrxFile::path
FrxDataFile::scan public function Overrides FrxFile::scan
FrxDataFile::userBlocks public function List all the reports for a language.
FrxDataFile::__construct public function Constructor Sets the initial reort directory Overrides FrxFile::__construct
FrxFile::$cache protected property
FrxFile::$cached_extensions public property
FrxFile::$cacheKey protected property
FrxFile::$dir public property
FrxFile::$includes public property
FrxFile::$needSave protected property
FrxFile::$needScan protected property
FrxFile::$use_includes public property
FrxFile::$validated protected property
FrxFile::$writable public property
FrxFile::contents public function Return the contents of a file located in the report directory
FrxFile::delete public function Delete a file from the directory.
FrxFile::deleteMissingEntries private function
FrxFile::directory public function Return the directory portioin of a report filename.
FrxFile::exists public function Return whether the file exists.
FrxFile::getCache public function
FrxFile::getCacheEntry public function Returns the cache entry based on a filename.
FrxFile::includeExists public function Determine if the file exists in the include path.
FrxFile::isCustom public function
FrxFile::isOverriden public function
FrxFile::isWritable public function Return an indicator as to whether the file is savable. New files can be saved if the directory is writabel.
FrxFile::pathinfo public function Retrieve path info
FrxFile::revert public function Revert an individual report
FrxFile::save public function Save a file into the report directory.
FrxFile::scanDirectory private function
FrxFile::scanInclude protected function Parse a drectory
FrxFile::setFilesToDelete private function
FrxFile::validateAllCache public function Called anytime we want to make sure the include cache is good and complete. Any file modifications will cause cache to be rebuild to be rebuilt.
FrxFile::validateCache public function Validate a single cache entry
FrxFile::verifyDirectory function
FrxFile::_validateAllCache private function