function FrxReportGenerator::report in Forena Reports 7.4
Same name and namespace in other branches
- 6.2 FrxReportGenerator.inc \FrxReportGenerator::report()
- 7.2 FrxReportGenerator.inc \FrxReportGenerator::report()
- 7.3 FrxReportGenerator.inc \FrxReportGenerator::report()
Load and render a report based on a drupal path. In this function the arglist is used to get the full path to the report.
Return value
unknown
File
- ./
FrxReportGenerator.inc, line 203 - Common functions used throughout the project but loaded in this file to keep the module file lean.
Class
Code
function report($name_in, $parms = array(), $print = TRUE) {
global $user;
$output = '';
$desc = Frx::Menu()
->parseURL($name_in);
$name = $desc['name'];
$format = isset($desc['format']) ? $desc['format'] : '';
$filename = $desc['filename'];
// Determine the data to get.
if (!$parms) {
$parms = array_merge($_GET, $_POST);
unset($parms['q']);
}
else {
$parms = (array) $parms;
}
if ($name) {
$r = @$this
->get_report($name, $parms);
if (!$r || !$r->rpt_xml) {
$this->app
->error('Could not load report. Check for invalid XML in ' . $name);
return '';
}
// When doing outputs lets check to make sure
// we have access to the reports. If not throw an error.
if ($print) {
$cache = forena_load_cache($r->rpt_xml);
$access = forena_check_all_access($cache['access']);
if (!$access) {
drupal_access_denied();
exit;
}
}
//check for default parameters
$r
->processParameters();
Frx::Skin()
->load($r->skin);
Frx::Skin()
->merge($r->skin_override);
Frx::Skin()
->loadSkinFiles($name);
$cached_data = FALSE;
$cache = array();
// Check for cache data
if ($r->cache) {
$cid = 'forena:report:' . $name . ':' . drupal_http_build_query($parms);
if (@$r->cache['per_user'] && $user) {
$cid .= ':' . $user->uid;
}
if (@$r->cache['per_doctype']) {
@($cid .= ':' . $format);
}
$cache = cache_get($cid, 'cache');
if (!$cache || isset($r->cache['duration']) && $cache->expire < time()) {
$r
->render($format, $print);
$time = null;
if (isset($r->cache['duration'])) {
try {
$time = @new DateTime($r->cache['duration']);
} catch (Exception $e) {
drupal_set_message('Invalid Cache Duration', 'error', TRUE);
}
if ($time) {
$time = $time
->getTimeStamp();
}
}
if (!$time) {
$time = CACHE_PERMANENT;
}
cache_set($cid, $r->cache, 'cache', $time);
}
$r
->render($format, $print, $cache->data);
}
else {
$r
->render($format, $print);
}
$o = Frx::Document($format);
if ($o) {
$output = $o
->render($r, $format, array());
if ($print) {
$printed = $o
->output($output);
}
else {
$printed = FALSE;
}
if (!$printed) {
return $output;
}
}
}
}