Commit d12bea80 authored by metzlerd's avatar metzlerd
Browse files

Code formatting

Initial forena auery module. 
parent dcad9485
<?php
class ForenaViewsPlugin extends views_plugin_style {
/**
* @file ForenaViewsPlugin.inc
* Views plugin to use forena report as a views renderer.
* @author davidmetzler
*
*/
class ForenaViewsPlugin extends views_plugin_style {
function option_definition() {
$options = parent::option_definition();
$options['report_name'] = array('default' => 'reports/test');
$options['report_name'] = array('default' => 'reports/test');
return $options;
}
/**
* Select forena report to use for renderig
*/
function options_form(&$form, &$form_state) {
function options_form(&$form, &$form_state) {
$form['report_name'] = array(
'#title' => t('Create from report'),
'#type' => 'textfield',
'#autocomplete_path' => 'forena/reports/autocomplete',
'#default_value' => $this->options['report_name'],
'#required' => TRUE,
'#required' => TRUE,
);
}
public function render() {
public function render() {
// Group the rows according to the grouping instructions, if specified.
$sets = $this->render_grouping(
$this->view->result,
$this->options['grouping'],
TRUE
);
$filename = $this->options['report_name'] . '.frx';
$filename = $this->options['report_name'] . '.frx';
if (Frx::File()->exists($filename)) {
$output = forena_report($this->options['report_name'], $this->rendered_fields, FALSE);
$output = forena_report($this->options['report_name'], $this->rendered_fields, FALSE);
}
return $output;
return $output;
}
}
\ No newline at end of file
<?php
/**
* @file Frx.incL
* General Forena Reporting Class
*/
define('FRX_TOKEN_EXP', '/\{[^\n^\r^}]+}/');
define('FRX_SQL_TOKEN', '/:([a-z]|[0-9]|{A-Z]|[_\.])+/');
class Frx {
class Frx {
/**
* Skin Factory
* @return FrxSkin
*/
public static function Skin() {
static $o = '';
if (!$o) {
public static function Skin() {
static $o = '';
if (!$o) {
require_once 'FrxSkin.inc';
$o = new FrxSkin();
$o = new FrxSkin();
}
return $o;
return $o;
}
/**
* Data Factory
*/
public static function Data() {
static $o = '';
if (!$o) {
require_once 'FrxData.inc';
$o = new FrxData();
static $o = '';
if (!$o) {
require_once 'FrxData.inc';
$o = new FrxData();
}
return $o;
return $o;
}
/**
* File singleton factory
*/
public static function File() {
static $o = '';
if (!$o) {
static $o = '';
if (!$o) {
require_once 'FrxFile.inc';
$o = new FrxFile();
$o = new FrxFile();
}
return $o;
return $o;
}
/**
......@@ -49,48 +50,48 @@ class Frx {
* @return FrxMenu
*/
public static function Menu() {
static $o = '';
if (!$o) {
static $o = '';
if (!$o) {
require_once 'FrxMenu.inc';
$o = new FrxMenu();
$o = new FrxMenu();
}
return $o;
return $o;
}
/**
*
*
* Enter description here ...
* @param unknown_type $type
* @return FrxDocument
*/
public static function Document($type='web') {
static $doc_types = '';
static $objects = '';
// Invoke doc_type hook to see which document types are there.
if (!$doc_types) $doc_types = module_invoke_all('forena_document_types');
static $doc_types = '';
static $objects = '';
// Invoke doc_type hook to see which document types are there.
if (!$doc_types) $doc_types = module_invoke_all('forena_document_types');
if (!$type) $type = 'web';
if (isset($doc_types[$type]) && class_exists(@$doc_types[$type]['class'])) {
if (!@$doc_types[$type]['object']) {
$o = new $doc_types[$type]['class'];
$o->format = $type;
$doc_types[$type]['object'] = $o;
if (isset($doc_types[$type]) && class_exists(@$doc_types[$type]['class'])) {
if (!@$doc_types[$type]['object']) {
$o = new $doc_types[$type]['class'];
$o->format = $type;
$doc_types[$type]['object'] = $o;
}
else {
$o = $doc_types[$type]['object'];
else {
$o = $doc_types[$type]['object'];
}
return $o;
}
else {
drupal_set_message('Unsupported document type: '. $type, 'error');
return $o;
}
else {
drupal_set_message(t('Unsupported document type:') . $type, 'error');
}
}
public static function Controls( $class='') {
static $instances = '';
static $classes = '';
static $classes = '';
if (!$instances) {
$classes = FrxReportGenerator::instance()->app->controls();
foreach ($classes as $c) {
......@@ -108,21 +109,22 @@ class Frx {
}
return $instances;
}
/**
* Forena Repository manager
* Forena Repository manager
* Class factory
* @return FrxRepoMan
*/
public static function RepoMan() {
static $o = '';
if (!$o) {
public static function RepoMan() {
static $o = '';
if (!$o) {
require_once 'FrxDataSource.inc';
require_once 'FrxRepoMan.inc';
$o = new FrxRepoMan();
$o = new FrxRepoMan();
}
return $o;
}
/**
* General wrapper procedure for reporting erros
*
......@@ -137,7 +139,7 @@ class Frx {
watchdog('forena', $log, NULL, WATCHDOG_ERROR);
}
}
/**
* Debug handler
* Enter description here ...
......@@ -152,10 +154,10 @@ class Frx {
drupal_set_message(check_markup($short_message));
}
}
public static function SyntaxEngine($regexp, $trim) {
public static function SyntaxEngine($regexp, $trim) {
require_once 'FrxSyntaxEngine.inc';
return new FrxSyntaxEngine($regexp, $trim);
return new FrxSyntaxEngine($regexp, $trim);
}
}
\ No newline at end of file
<?php
/**
* @file FrxData.inc
* The FrxData class holds all of the data contexts during the report rendering process.
* The general idea is that during the report render, data objects are pushed on the stack with the id's of the block or foreach objects that invoke them.
* Rendering controls may then get current data contexts, and push data onto the stack or pop data onto the stack. They may also use this method to get the current data
* context from the stack.
*
* The static instance function of this object acts as a factory method that allows other code in forena to always be able to operate on the current context of the class.
* @var unknown_type
*/
class FrxData {
/**
* The FrxData class holds all of the data contexts during the report rendering process.
* The general idea is that during the report render, data objects are pushed on the stack with the id's of the block or foreach objects that invoke them.
* Rendering controls may then get current data contexts, and push data onto the stack or pop data onto the stack. They may also use this method to get the current data
* context from the stack.
*
* The static instance function of this object acts as a factory method that allows other code in forena to always be able to operate on the current context of the class.
* @var unknown_type
*/
public $id;
private $cur_context; // The data of the xml;
private $data_sources = array();
public $id;
private $cur_context; // The data of the xml;
private $data_sources = array();
private $data_stack = array();
private $id_stack = array();
// For backward compatibility.
public static function instance() {
return Frx::Data();
// For backward compatibility.
public static function instance() {
return Frx::Data();
}
/**
* Return the current data context
*
*/
public function currentContext() {
return $this->cur_context;
}
/**
* Return the current data context
*
*/
public function currentContext() {
return $this->cur_context;
}
/**
* Allows override of a value for the current context.
* @param String $key
* @param String $value
*/
/**
* Allows override of a value for the current context.
* @param String $key
* @param String $value
*/
public function setValue($key, $value) {
if (is_array($this->cur_context)) {
$this->cur_context[$key] = $value;
}
elseif (is_object($this->cur_context)) {
if (strpos($key, '@')===0) {
$this->cur_context[$key] = $value;
}
else {
if (strpos($key, '@')===0) {
$this->cur_context[$key] = $value;
}
else {
$this->cur_context->$key = $value;
}
}
}
}
......@@ -58,14 +59,14 @@ class FrxData {
* @return unknown_type
*/
public function push($data, $id='') {
$this->data_stack[] = $this->cur_context;
$this->id_stack[] = $this->id;
$this->data_stack[] = $this->cur_context;
$this->id_stack[] = $this->id;
$this->id = $id;
$this->cur_context = $data;
if ($id) {
/* if (@is_array($this->data_sources[$id]) && is_array($data)) {
$data = array_merge($this->data_sources[$id], $data);
$data = array_merge($this->data_sources[$id], $data);
}
*/
$this->data_sources[$id] = $data;
......@@ -73,7 +74,7 @@ class FrxData {
}
public function setContext($id, $data) {
$this->data_sources[$id] = $data;
$this->data_sources[$id] = $data;
}
/**
......@@ -83,7 +84,7 @@ class FrxData {
* @return mixed
*/
public function pop() {
$this->id = array_pop($this->id_stack);
$this->id = array_pop($this->id_stack);
$this->cur_context = array_pop($this->data_stack);
}
......@@ -94,10 +95,10 @@ class FrxData {
* @return boolean
*/
public function contextExists($id) {
if (array_key_exists($id, $this->data_sources)){
return TRUE;
}
else return FALSE;
if (array_key_exists($id, $this->data_sources)) {
return TRUE;
}
else return FALSE;
}
/**
......@@ -106,7 +107,7 @@ class FrxData {
* @param unknown_type $id
*/
public function getContext($id) {
return @$this->data_sources[$id];
return @$this->data_sources[$id];
}
}
\ No newline at end of file
......@@ -23,7 +23,7 @@ class FrxDataSource{
$this->block_ext = 'sql';
$this->block_path = $repos_path;
$this->app = FrxReportGenerator::instance()->app;
$this->block_extensions = array('inc','sql','xml');
$this->block_extensions = array('inc', 'sql', 'xml');
}
/**
......@@ -120,19 +120,19 @@ class FrxDataSource{
$d = glob($block_path);
if ($d) foreach ($d as $file_name) {
// Split off the extention
$p = strripos($file_name, '.');
// Split off the extention
$p = strripos($file_name, '.');
if ($p!==FALSE) {
$ext = substr($file_name, $p+1);
$block_name = substr($file_name, 0, $p);
$ext = substr($file_name, $p+1);
$block_name = substr($file_name, 0, $p);
}
else {
$ext = '';
$block_name = $file_name;
$ext = '';
$block_name = $file_name;
}
if (array_search($ext, $this->block_extensions)!==FALSE) {
$block_list[] = str_replace($this->block_path . '/', '', $block_name);
$block_list[] = str_replace($this->block_path . '/', '', $block_name);
}
}
......@@ -148,16 +148,16 @@ class FrxDataSource{
}
public function debug($msg='', $log='') {
FrxReportGenerator::instance()->app->debug($msg, $log);
FrxReportGenerator::instance()->app->debug($msg, $log);
}
public function error($msg='', $log='') {
FrxReportGenerator::instance()->app->error($msg, $log);
FrxReportGenerator::instance()->app->error($msg, $log);
}
public function parseXMLFile($contents) {
$comment = $this->comment_prefix;
$trim = $this->comment_suffix;
$comment = $this->comment_prefix;
$trim = $this->comment_suffix;
$lines = explode("\n", $contents);
$cnt = count($lines);
$access = '';
......@@ -172,11 +172,11 @@ class FrxDataSource{
list($a, $o) = explode('=', $c, 2);
$a = trim($a);
if ($a && $o) {
switch ($a) {
case 'ACCESS':
$access = trim($o);
break;
default:
switch ($a) {
case 'ACCESS':
$access = trim($o);
break;
default:
}
......@@ -194,8 +194,8 @@ class FrxDataSource{
public function parseSQLFile($contents) {
$comment = $this->comment_prefix;
$trim = $this->comment_suffix;
$comment = $this->comment_prefix;
$trim = $this->comment_suffix;
$lines = explode("\n", $contents);
$cnt = count($lines);
$access = '';
......@@ -212,19 +212,19 @@ class FrxDataSource{
@list($a, $o) = explode('=', $c, 2);
$a = trim($a);
if (($a && $o) || $c == 'END' || $c == 'ELSE' ) {
switch ($a) {
case 'ACCESS':
$access = trim($o);
break;
case 'IF':
$skip = !$this->te->test(trim($o));
break;
case 'END':
$skip = FALSE;
break;
case 'ELSE':
$skip = !$skip;
break;
switch ($a) {
case 'ACCESS':
$access = trim($o);
break;
case 'IF':
$skip = !$this->te->test(trim($o));
break;
case 'END':
$skip = FALSE;
break;
case 'ELSE':
$skip = !$skip;
break;
}
}
......
<?php
/**
/**
* @file FrxDocument.inc
* Given a report, render the appropriate output given the document format.
* @author davidmetzler
*
*/
class FrxDocument {
public $format;
public $content_type='';
public function loadCSSFIles($format) {
class FrxDocument {
public $format;
public $content_type='';
public function loadCSSFIles($format) {
// Add css files
$css = '';
foreach (Frx::Skin()->stylesheets as $type=>$sheets) {
foreach ($sheets as $sheet) {
switch ($type) {
case 'all':
case $format:
$css .= Frx::File()->contents($sheet);
break;
$css = '';
foreach (Frx::Skin()->stylesheets as $type => $sheets) {
foreach ($sheets as $sheet) {
switch ($type) {
case 'all':
case $format:
$css .= Frx::File()->contents($sheet);
break;
}
}
}
return $css;
return $css;
}
// All document objects must implement this method.
public function render($r, $format, $options = array()) {
// All document objects must implement this method.
public function render($r, $format, $options = array()) {
$header = '<h1>' . $r->title . '</h1>';
$output = $header . $output;
$css_text = '';
$r_text = '';
$stylesheets = Frx::Skin()->stylesheets;
foreach ($stylesheets as $type=>$sheets) {
foreach($sheets as $sheet) {
switch ($type) {
case 'all':
foreach ($stylesheets as $type => $sheets) {
foreach ($sheets as $sheet) {
switch ($type) {
case 'all':
case $this->format:
$css_file[] = $sheet;
break;
$css_file[] = $sheet;
break;
}
}
}
if ($css_files) foreach ($css_files as $css_file) {
$css_text .= file_get_contents($css_file);
}
......@@ -52,26 +53,26 @@ class FrxDocument {
'xml' => $r_text,
'title' => $title,
);
$output = $this->generate_doc($format, $output, $options, $print);
if ($format!='email') {
print $output;
}
}
public function output($output) {
if ($this->content_type) {
header('Content-Type: '. $this->content_type);
public function output($output) {
if ($this->content_type) {
header('Content-Type: ' . $this->content_type);
header('Cache-Control:');
header('Pragma:');
header('Cache-Control: must-revalidate');
print $output;
return TRUE;
print $output;
return TRUE;
}
else {
return FALSE;
else {
return FALSE;
}
}
}
\ No newline at end of file
<?php
global $forena_application_class;
$forena_application_class = 'FrxDrupalApplication';
global $_forena_application_class;