Commit 7fca73b8 authored by metzlerd's avatar metzlerd
Browse files

Implemented ability to include reports based on context parameters.

parent 24b2b27f
......@@ -210,7 +210,7 @@ class Frx {
}
/**
* Factory for SQL Query builder object
* Facotry for SQL Query builder object
* @param $new Boolean value that forces a new object
* @return FrxSQLQueryBuilder
*/
......@@ -223,15 +223,100 @@ class Frx {
return $o;
}
/**
* Factory method to return instance object
* @param unknown_type $parent
* @param unknown_type $key
* @return object
*/
public static function PluginInstance($parent, $key) {
static $objects='';
$o = NULL;
if (!$objects) {
$objects = array();
}
$plugins = Frx::plugins($parent);
if (isset($plugins[$key])) {
$class = @$plugins[$key]['class'];
if (!isset($objects[$class])) {
if (class_exists($class)) $objects[$class] = new $class();
}
$o = $objects[$class];
}
return $o;
}
/**
* Factory object to get the context based on a name. IF the context doesn't
* exist we assume the default data context (FrxData).
* @param $context string
* @return FrxContext
*/
public static function Context($context) {
$o = NULL;
if ($context) {
// Instantiate the class if it exists
if ($context) {
$o = Frx::PluginInstance('FrxContext', $context);
}
// Otherwise instantiate the data class.
if (!$o) {
$o = Frx::Data();
Frx::Data();
}
return $o;
}
/**
* Loads all of the include files that
*/
public static function plugins( $parent = '') {
static $plugins = '';
if (!$plugins) {
$plugins = array();
foreach (module_list() as $module) {
$function = $module . '_forena_plugins';
if (function_exists($function)) {
$returned_plugins = $function();
if ($returned_plugins) foreach ((array)$returned_plugins as $key=>$p) {
$p['module'] = $module;
if (@$p['path']) {
$p['file'] = rtrim($p['path'],'/') . '/' . $p['file'];
}
else {
$p['file'] = drupal_get_path('module' , $p['module']) . '/' . $p['file'];
}
if (is_int($key)) {
$plugins[]=$p;
}
else {
$plugins[$key] = $p;
}
}
}
}
foreach ($plugins as $p) {
if ($p['file'] ) {
include_once( trim($p['file'], '/'));
}
}
}
// Return the plugins if a parent was requested.
$ret_plugins = array();
if ($parent) {
foreach($plugins as $key => $p) {
if (@$p[parent] == $parent) {
$ret_plugins[$key] = $p;
}
}
}
return $ret_plugins;
}
}
\ No newline at end of file
......@@ -181,34 +181,6 @@ class FrxDrupalApplication {
}
}
/**
* Invokes the hooks required for forena plugin registration.
* Each module returns an array structure that defines multiple plugins
*
* class - Indicates the name of the class that will be used to define the plugins behaviors.
*
*/
function plugins() {
static $plugins = '';
if (!$plugins) {
$plugins = array();
foreach (module_list() as $module) {
$function = $module . '_forena_plugins';
if (function_exists($function)) {
$returned_plugins = $function();
if ($returned_plugins) foreach ((array)$returned_plugins as $p) {
$p['module'] = $module;
$p['file'] = drupal_get_path('module' , $p['module']) . '/' . $p['file'];
$plugins[]=$p;
}
}
}
}
return $plugins;
}
/**
* Builds a global array of available controls
* and returns the array.
......
......@@ -11,35 +11,6 @@ class FrxRepoMan {
private $repository;
/**
* Loads all of the include files that
*/
private function define_plugins( $class='') {
static $plugins = '';
if (!$plugins) {
$plugins = array();
foreach (module_list() as $module) {
$function = $module . '_forena_plugins';
if (function_exists($function)) {
$returned_plugins = $function();
if ($returned_plugins) foreach ((array)$returned_plugins as $p) {
$p['module'] = $module;
$p['file'] = drupal_get_path('module' , $p['module']) . '/' . $p['file'];
$plugins[]=$p;
}
}
}
}
foreach ($plugins as $p) {
if (($class=='' || $class==$p['class'])) {
if ($p['file'] ) {
include_once( trim($p['file'], '/'));
}
}
}
}
//Determine data sources.
public function __construct() {
global $_forena_repositories;
......@@ -143,7 +114,7 @@ class FrxRepoMan {
*/
public function load_provider($conf, $repo_path, $repos_name) {
@$name = isset($conf['data provider'])? $conf['data provider'] : $conf['data_engine'];
$this->define_plugins();
Frx::plugins('FrxDataSource');
// Instantiate the path
if (class_exists($name)) {
$o = new $name($conf, $repo_path, $repos_name);
......
......@@ -58,7 +58,7 @@ class FrxSyntaxEngine {
protected function get_value( $key, $raw=FALSE) {
$context = '';
if ($key && strpos($key, '.')) {
@list($key, $path) = explode('.', $key, 2);
@list($context, $key) = explode('.', $key, 2);
$o = Frx::Context($context);
}
else {
......
......@@ -800,8 +800,8 @@ function forena_report($name_in, $parms = array(), $print = TRUE) {
require_once('forena.common.inc');
$desc = Frx::Menu()->parseURL($name_in);
if (!$desc['exists']) {
drupal_not_found();
exit;
drupal_set_message(t('Report %s not found', array('%s' => $name_in)), 'error', FALSE);
return '';
}
......@@ -950,40 +950,47 @@ function forena_render_report($report, $format='', $data='', $options= array(),
function forena_forena_plugins() {
$path = drupal_get_path('module', 'forena');
$plugins[] = array('file' => 'plugins/FrxPDO.inc',
$plugins['FrxPDO'] = array('file' => 'plugins/FrxPDO.inc',
'parent' => 'FrxDataSource',
'class' => 'FrxPDO',
'path' => $path,
);
$plugins[] = array('file' => 'plugins/FrxOracle.inc',
$plugins['FrxOracle'] = array('file' => 'plugins/FrxOracle.inc',
'parent' => 'FrxDataSource',
'class' => 'FrxOracle',
'path' => $path,
);
$plugins[] = array(
$plugins['FrxDrupal'] = array(
'file' => 'plugins/FrxDrupal.inc',
'parent' => 'FrxDataSource',
'class' => 'FrxDrupal',
'path' => $path,
);
$plugins[] = array('file' => 'plugins/FrxFiles.inc',
$plugins['FrxFiles'] = array('file' => 'plugins/FrxFiles.inc',
'parent' => 'FrxDataSource',
'class' => 'FrxFiles',
);
$plugins[] = array('file' => 'plugins/FrxPostgres.inc',
$plugins['FrxPostgres'] = array('file' => 'plugins/FrxPostgres.inc',
'class' => 'FrxPostgres',
'parent' => 'FrxDataSource'
);
$plugins[] = array('file' => 'plugins/FrxMSSQL.inc',
$plugins['FrxMSSQL'] = array('file' => 'plugins/FrxMSSQL.inc',
'parent' => 'FrxDataSource',
'class' => 'FrxMSSQL',
'path' => $path,
);
// Normally you wouldn't do this but I wanted to make the FrxReport sytax work.
$plugins['FrxReport'] = array(
'file' => 'plugins/FrxReportContext.inc',
'parent' => 'FrxContext',
'class' => 'FrxReportContext',
'path' => $path,
);
return $plugins;
}
......
<?php
/**
* Special report embedder
* @author davidmetzler
*
*/
class FrxReportContext {
// Get report based on current context and embed it.
public function getValue($key, $context) {
$output = forena_report($key, NULL, FALSE);
return $output;
}
// Undo setter, no possibility to override.
public function setValue($value) {
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment