class ReportFile in Forena Reports 7.5
Hierarchy
- class \Drupal\forena\File\FileBase
- class \Drupal\forena\File\ReportFile
Expanded class hierarchy of ReportFile
File
- src/
File/ ReportFile.php, line 5
Namespace
Drupal\forena\FileView source
class ReportFile extends FileBase {
private $report_cache = array();
/**
* Constructor
* Sets the initial reort directory
*/
public function __construct() {
// Load default directory from configuration.
$report_path = variable_get('forena_report_repos', '');
if (!$report_path) {
$report_path = variable_get('file_' . file_default_scheme() . '_path', conf_path() . '/files/reports');
}
$default_directory = rtrim($report_path, '/');
$directories = module_invoke_all('forena_report_directory');
foreach ($directories as $dir) {
$this->includes[] = rtrim($dir, '/');
}
// Parent constructor.
parent::__construct($default_directory, $directories, array(
'frx',
'skinfo',
'css',
'js',
));
}
/**
* List all the reports for a language.
* @return unknown
*/
public function allReports() {
global $language;
$reports = array();
$this
->validateAllCache();
$data = $this
->getCache('frx');
$def_language = language_default('language');
if ($data) {
foreach ($data as $base_name => $obj) {
if ($obj->cache) {
if ($obj->cache['language'] != 'en') {
$rpt_name = substr($base_name, strlen($obj->cache['language']) + 1);
}
else {
$rpt_name = $base_name;
}
if ($obj->cache['language'] == $language->language) {
$reports[$rpt_name] = $obj;
}
elseif ($obj->cache['language'] == $def_language && (!isset($reports[$rpt_name]) || $reports[$rpt_name]->cache['language'] == 'en')) {
$reports[$rpt_name] = $obj;
}
elseif ($obj->cache['language'] == 'en' && !isset($reports[$rpt_name])) {
$reports[$rpt_name] = $obj;
}
}
}
}
uasort($reports, '\\Drupal\\forena\\File\\ReportFile::reportCompare');
return $reports;
}
/**
* Sort compare function for sorting data by category then title.
* @param unknown $a
* @param unknown $b
* @return number
*/
public static function reportCompare($a, $b) {
$c = strnatcasecmp($a->cache['category'], $b->cache['category']);
if (!$c) {
$c = strnatcasecmp($a->cache['title'], $b->cache['title']);
}
return $c;
}
public static function reportTitleCompare($a, $b) {
$c = strnatcasecmp($a['title'], $b['title']);
return $c;
}
/**
* Get the cached information for a single report.
* @param unknown $name
* @return unknown
*/
public function getReportCacheInfo($name) {
global $language;
$this
->validateAllCache();
$data = $this
->getCache('frx');
if ($language->language != 'en') {
$lang = $language->language;
$name = "{$lang}/{$name}";
}
return @$data[$name];
}
public function menuReports() {
global $language;
$this
->validateAllCache();
$data = $this
->getCache('frx');
$reports = array();
foreach ($data as $base_name => $obj) {
if ($obj->cache && isset($obj->cache['menu']['path']) && ($obj->cache['language'] == $language->language || $obj->cache['language'] == 'en' && !isset($obj->cache['menu']['path']))) {
if ($obj->cache['language'] != 'en') {
$obj->name = substr($base_name, 3);
}
else {
$obj->name = $base_name;
}
$reports[$obj->cache['menu']['path']] = $obj;
}
}
return $reports;
}
/**
* Generate an ordered list of reports by category
* @param $categories
* @return array Categories
*/
public function reportsByCategory($categories = array()) {
global $language;
$this
->validateAllCache();
$data = $this
->allReports();
$reports = array();
if ($data) {
foreach ($data as $base_name => $obj) {
if ($obj->cache && @$obj->cache['category'] && !$obj->cache['hidden']) {
$cache = $obj->cache;
if (!$categories || array_search($cache['category'], $categories) !== FALSE) {
// Check each callback function to see if we have an error.
$access = TRUE;
if (@$cache['access']) {
$access = FALSE;
foreach ($cache['access'] as $provider => $callbacks) {
if (user_access('access ' . $provider . ' data')) {
foreach ($callbacks as $callback => $args) {
if ($callback) {
foreach ($args as $arg) {
if (function_exists($callback) && $arg) {
$a = $callback($arg);
if ($a) {
$access = TRUE;
}
}
else {
$access = TRUE;
}
}
}
else {
$access = TRUE;
}
}
}
}
}
if ($access) {
$reports[$cache['category']][] = array(
'title' => $cache['title'],
'category' => $cache['category'],
'report_name' => $base_name,
);
}
}
}
}
}
$sort = defined('SORT_NATURAL') ? SORT_NATURAL : SORT_REGULAR;
// Sort the reports
if ($reports) {
foreach ($reports as $category => $list) {
uasort($reports[$category], '\\Drupal\\forena\\File\\ReportFile::reportTitleCompare');
}
}
ksort($reports, $sort);
return $reports;
}
public function skins() {
$this
->validateAllCache();
$this
->getCache('skinfo');
$skins = array();
if (isset($this->cache['skinfo'])) {
foreach ($this->cache['skinfo'] as $name => $obj) {
$skins[$name] = isset($obj->cache['name']) ? $obj->cache['name'] : $name;
}
}
return $skins;
}
/**
* Should load cache data based on that.
* @see FrxFile::buildCache()
*/
public function buildCache($ext, $base_name, &$object) {
switch ($ext) {
case 'frx':
// Save language info
$lang = 'en';
if (module_exists('locale')) {
@(list($tlang, $tname) = explode('/', $base_name, 2));
if (array_key_exists($tlang, language_list())) {
$lang = $tlang;
}
}
try {
$r_xml = file_get_contents($object->file);
// Load the report
$r = @new Report($r_xml);
} catch (Exception $e) {
}
if (!$r->rpt_xml) {
$s = t('Unable to load Report %s', array(
'%s' => $object->file,
));
if (user_access('design any report')) {
drupal_set_message($s, 'error', FALSE);
}
}
// Get the security caches from the reports
$cache = isset($r->rpt_xml) ? forena_load_cache($r->rpt_xml) : NULL;
if ($r->rpt_xml) {
$cache['title'] = $r->title;
$cache['language'] = $lang;
$cache['category'] = $r->category;
$cache['hidden'] = @$r->options['hidden'];
}
$object->cache = $cache;
if ($r) {
$r
->__destruct();
}
unset($r);
break;
case 'skinfo':
$object->cache = drupal_parse_info_format(file_get_contents($object->file));
break;
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FileBase:: |
protected | property | ||
FileBase:: |
public | property | ||
FileBase:: |
protected | property | ||
FileBase:: |
public | property | ||
FileBase:: |
public | property | ||
FileBase:: |
protected | property | ||
FileBase:: |
protected | property | ||
FileBase:: |
public | property | ||
FileBase:: |
protected | property | ||
FileBase:: |
public | property | ||
FileBase:: |
public | function | Return the contents of a file located in the report directory | |
FileBase:: |
public | function | Delete a file from the directory. | |
FileBase:: |
private | function | ||
FileBase:: |
public | function | Return the directory portioin of a report filename. | |
FileBase:: |
public | function | Return whether the file exists. | |
FileBase:: |
public | function | ||
FileBase:: |
public | function | Returns the cache entry based on a filename. | |
FileBase:: |
public | function | Determine if the file exists in the include path. | |
FileBase:: |
public | function | ||
FileBase:: |
public | function | ||
FileBase:: |
public | function | Return an indicator as to whether the file is savable. New files can be saved if the directory is writabel. | |
FileBase:: |
public | function | Return the full path to the filename | 1 |
FileBase:: |
public | function | Retrieve path info | |
FileBase:: |
public | function | Revert an individual report | |
FileBase:: |
public | function | Save a file into the report directory. | |
FileBase:: |
public | function | 1 | |
FileBase:: |
private | function | ||
FileBase:: |
protected | function | Parse a drectory | |
FileBase:: |
private | function | ||
FileBase:: |
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. | |
FileBase:: |
public | function | Validate a single cache entry | |
FileBase:: |
function | |||
FileBase:: |
private | function | ||
ReportFile:: |
private | property | ||
ReportFile:: |
public | function | List all the reports for a language. | |
ReportFile:: |
public | function |
Should load cache data based on that. Overrides FileBase:: |
|
ReportFile:: |
public | function | Get the cached information for a single report. | |
ReportFile:: |
public | function | ||
ReportFile:: |
public static | function | Sort compare function for sorting data by category then title. | |
ReportFile:: |
public | function | Generate an ordered list of reports by category | |
ReportFile:: |
public static | function | ||
ReportFile:: |
public | function | ||
ReportFile:: |
public | function |
Constructor
Sets the initial reort directory Overrides FileBase:: |