DataFileSystem.php in Forena Reports 8
File
src/File/DataFileSystem.php
View source
<?php
namespace Drupal\forena\File;
use Drupal\forena\AppService;
use Drupal\forena\DataManager;
class DataFileSystem extends FileSystemBase {
public $source = '';
public $dmSvc;
public function __construct($source, $path, DataManager $dataManager) {
parent::__construct();
$this->cacheKey = $this->cacheKey . ':' . $source;
$this->dmSvc = $dataManager;
$this->source = $source;
$data_path = AppService::instance()
->dataDirectory();
$this->source = $source;
$this->dir = rtrim($data_path, '/');
$this->includes[] = $path;
}
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 = $this->dmSvc
->repository($obj->cache['provider']);
if ($r && $r
->access($obj->cache['access'])) {
$blocks[$base_name] = $obj;
}
}
}
}
}
uksort($blocks, '\\Drupal\\forena\\File\\DataFile::blockCompare');
return $blocks;
}
public static function blockCompare($a, $b) {
$c = strnatcasecmp($a, $b);
return $c;
}
public function parseSQLFile($object) {
$file = file_get_contents($object->file);
$src = $this->dmSvc
->parseSQL($file);
$metaData = [
'provider' => $this->source,
'name' => $this->source . '/' . $this->base_name,
'access' => @$src['access'],
'options' => @$src['options'],
];
return $metaData;
}
public function extractMetaData(&$object) {
switch ($object->ext) {
case 'sql':
$object->metaData = $this
->parseSQLFile($object);
break;
}
}
}