Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
forena
Commits
1237c560
Commit
1237c560
authored
Apr 21, 2010
by
metzlerd
Browse files
Saving reports works. New data formatters as well.
parent
93d2e1e7
Changes
6
Hide whitespace changes
Inline
Side-by-side
FrxReport.inc
View file @
1237c560
...
...
@@ -35,7 +35,7 @@ class FrxReport {
// Load header data
$rpt_xml
=
$this
->
rpt_xml
;
$this
->
body
=
$rpt_xml
->
body
;
$this
->
body
=
$rpt_xml
->
body
;
if
(
$rpt_xml
->
head
)
{
$this
->
title
=
(
string
)
$rpt_xml
->
head
->
title
;
...
...
@@ -82,10 +82,8 @@ class FrxReport {
$attrs
=
$node
->
attributes
(
FRX_NS
);
if
(
$attrs
)
foreach
(
$attrs
as
$key
=>
$value
)
{
switch
(
$key
)
{
case
"block"
:
$this
->
get_data
((
string
)
$value
);
case
"block"
:
$this
->
get_data
((
string
)
$value
);
break
;
}
}
...
...
@@ -95,11 +93,9 @@ class FrxReport {
* Recursive report renderer
* Walks the nodes rendering the report.
*/
public
function
render_section
(
SimpleXMLElement
$node
)
{
public
function
render_section
(
SimpleXMLElement
$node
)
{
//drupal_set_message('Rendering Section '. $node->getName());
$cur_data
=
$this
->
cur_data
;
$cur_data
=
$this
->
cur_data
;
$elements
=
count
(
$node
->
xpath
(
'*'
));
$frx
=
$node
->
attributes
(
FRX_NS
);
// Test to see if we have any nodes that are contains data url
...
...
@@ -155,7 +151,7 @@ class FrxReport {
* Render the report
* @return unknown_type
*/
public
function
render
(
$format
)
{
public
function
render
(
$format
)
{
$rpt_xml
=
$this
->
rpt_xml
;
drupal_set_title
(
$this
->
title
);
...
...
@@ -172,7 +168,7 @@ class FrxReport {
* This invokes the field translation engine
*/
public
function
format
(
$value
,
$key
,
$data
)
{
// Determine if there is a field overide entry
// Determine if there is a field overide entry
if
(
$this
->
fields
)
{
$path
=
'frx:field[@id="'
.
$key
.
'"]'
;
$formatters
=
$this
->
fields
->
xpath
(
$path
);
...
...
@@ -191,7 +187,7 @@ class FrxReport {
}
if
(
$format
)
{
$value
=
forena_format_data
(
$value
,
$format
,
$format_str
);
$value
=
forena_format_data
(
$value
,
$format
,
$format_str
);
}
...
...
forena.admin.inc
View file @
1237c560
...
...
@@ -42,7 +42,7 @@ function forena_save_report($report_name, $report, $save_file = FALSE) {
if
(
$report
)
$cache
=
forena_load_cache
(
$report
);
else
$cache
=
''
;
if
(
$cache
)
$rpt_cache
=
serialize
(
$cache
);
//drupal_set_message('saving'.$name. print_r($cache,1));
//drupal_set_message('saving'.$name. print_r($cache,1));
// Set default interpretations of data
$data
[
'enabled'
]
=
$data
[
'enabled'
]
?
1
:
0
;
if
(
!
$data
[
'category'
])
$data
[
'category'
]
=
'All'
;
...
...
@@ -62,7 +62,7 @@ function forena_save_report($report_name, $report, $save_file = FALSE) {
$name
));
}
else
{
//drupal_set_message('insert
n
ig');
//drupal_set_message('inserti
n
g');
db_query
(
"INSERT INTO
{
forena_reports
}
(report_name, title, category, hidden, cache) "
.
"VALUES ('%s', '%s', '%s', %d, '%s')"
,
array
(
$name
,
...
...
@@ -204,6 +204,9 @@ function forena_settings_submit($form, &$form_state) {
menu_cache_clear
();
}
/**
* Form function for the edit report form
* @param $form_state
...
...
forena.common.inc
View file @
1237c560
...
...
@@ -19,7 +19,7 @@ function __forena_load_repository(&$repo) {
}
$repo
[
'data'
]
=
__forena_load_engine
(
$conf
,
$repo
[
'path'
]);
$repo
[
'data'
]
=
__forena_load_engine
(
$conf
,
$repo
[
'path'
]);
//$repo['auth'] = __forena_load_auth($security_provider);
}
...
...
@@ -86,7 +86,7 @@ function forena_repository($name='') {
function
forena_load_cache
(
$r_xhtml
)
{
$blocks
=
array
();
if
(
is_object
(
$r_xhtml
))
{
if
(
is_object
(
$r_xhtml
))
{
$block_xml
=
$r_xhtml
->
xpath
(
'//*[@frx:block]'
);
// Extract all the blocks and organize by provider
foreach
(
$block_xml
as
$key
=>
$block_node
)
{
...
...
@@ -97,8 +97,8 @@ function forena_load_cache($r_xhtml) {
}
}
foreach
(
$repos
as
$provider
=>
$blocks
)
{
$repos
=
forena_repository
(
$provider
);
foreach
(
$repos
as
$provider
=>
$blocks
)
{
$repos
=
forena_repository
(
$provider
);
$engine
=
$repos
[
'data'
];
$conf
=
$engine
->
conf
;
$access
=
array
();
...
...
@@ -150,11 +150,10 @@ function forena_invoke_data_engine($data_block, $parameters=array(), $subquery='
*/
function
forena_get_formatter
(
$fkey
)
{
// Get all repositories
$repos
=
forena_repository
();
$repos
=
forena_repository
();
foreach
(
$repos
as
$k
=>
$r
)
{
$engine
=
$r
[
'data'
];
$engine
=
$r
[
'data'
];
if
(
$engine
&&
method_exists
(
$engine
,
'formats'
))
{
$f
=
$engine
->
formats
();
if
(
$f
[
$fkey
]
&&
method_exists
(
$engine
,
$fkey
))
{
...
...
@@ -163,6 +162,19 @@ function forena_get_formatter($fkey) {
}
}
}
//Did not find the formater in the data engine
//Look to see if it's in a control class
$controls
=
forena_define_controls
();
foreach
(
$controls
as
$k
=>
$r
)
{
$engine
=
$r
;
if
(
$engine
&&
method_exists
(
$engine
,
'formats'
))
{
$f
=
$engine
->
formats
();
if
(
$f
[
$fkey
]
&&
method_exists
(
$engine
,
$fkey
))
{
// We found an object with the advertised method return it
return
$engine
;
}
}
}
return
$formats
;
}
...
...
@@ -282,11 +294,6 @@ function forena_report_path() {
* Invokes the hooks required for forena plugin registration.
* Each module returns an array structure that defines multiple plugins
*
* types - Type of object:
* data - Provides the data methods
* control - implements a rendering control
* formatter - Implments a data formatter that is called when processing token replacements
*
* class - Indicates the name of the class that will be used to define the plugins behaviors.
*
*/
...
...
@@ -304,7 +311,7 @@ function forena_plugins() {
}
}
}
}
}
return
$plugins
;
}
...
...
@@ -313,12 +320,93 @@ function forena_plugins() {
*/
function
forena_define_plugins
(
$class
=
''
)
{
$plugins
=
forena_plugins
();
foreach
(
$plugins
as
$p
)
{
if
((
$class
=
''
||
$class
=
$p
[
'class'
]))
{
if
(
$p
[
'file'
]
&&
$p
[
'module'
])
{
foreach
(
$plugins
as
$p
)
{
if
((
$class
=
=
''
||
$class
=
=
$p
[
'class'
]))
{
if
(
$p
[
'file'
]
&&
$p
[
'module'
])
{
include_once
(
drupal_get_path
(
'module'
,
$p
[
'module'
])
.
'/'
.
trim
(
$p
[
'file'
],
'/'
));
}
}
}
}
/**
* Builds a global array of available controls
* and returns the array.
*/
function
forena_controls
()
{
static
$controls
=
''
;
if
(
!
$controls
)
{
$controls
=
array
();
foreach
(
module_list
()
as
$module
)
{
$function
=
$module
.
'_forena_controls'
;
if
(
function_exists
(
$function
))
{
$returned_controls
=
$function
();
if
(
$returned_controls
)
foreach
((
array
)
$returned_controls
as
$c
)
{
$c
[
'module'
]
=
$module
;
$controls
[]
=
$c
;
}
}
}
}
return
$controls
;
}
/**
* returns a list of instances of the control classes
*/
function
forena_define_controls
(
$class
=
''
)
{
static
$instances
=
''
;
if
(
!
$instances
)
{
$classes
=
forena_controls
();
foreach
(
$classes
as
$c
)
{
if
((
$class
==
''
||
$class
==
$c
[
'class'
]))
{
if
(
$c
[
'file'
]
&&
$c
[
'module'
])
{
include_once
(
drupal_get_path
(
'module'
,
$c
[
'module'
])
.
'/'
.
trim
(
$c
[
'file'
],
'/'
));
$instances
[
$c
[
'class'
]]
=
new
$c
[
'class'
];
}
}
}
}
if
(
$class
&&
$instances
[
$class
]){
return
$instances
[
$class
];
}
return
$instances
;
}
/**
* Form to edit parameters
*/
function
forena_parameters_form
(
$form_state
)
{
$r
=
forena_get_report
(
arg
(
1
));
$head
=
$r
->
rpt_xml
->
head
;
$form
=
array
();
$form
[
'params'
]
=
array
(
'#tree'
=>
true
);
$nodes
=
$head
->
xpath
(
'frx:parameters/frx:parm'
);
foreach
(
$nodes
as
$node
)
{
(
strcmp
((
string
)
$node
[
'require'
],
"1"
)
==
0
)
?
$bool
=
TRUE
:
$bool
=
FALSE
;
$form
[
'params'
][(
string
)
$node
[
'id'
]]
=
array
(
'#type'
=>
'textfield'
,
'#title'
=>
t
((
string
)
$node
[
'label'
]),
'#default_value'
=>
$node
,
'#required'
=>
$bool
,
);
}
$form
[
'submit'
]
=
array
(
'#type'
=>
'submit'
,
'#value'
=>
'Submit'
,
);
return
$form
;
}
function
forena_parameters_form_submit
(
$form
,
&
$form_state
)
{
$values
=
$form_state
[
'values'
];
foreach
(
$values
[
'params'
]
as
$key
=>
$value
)
{
$q
.
=
'&'
.
$key
.
'='
.
urlencode
(
$value
);
}
$q
=
trim
(
$q
,
'&'
);
$form_state
[
'redirect'
]
=
array
(
'reports/'
.
arg
(
1
),
$q
);
}
forena.module
View file @
1237c560
...
...
@@ -41,6 +41,16 @@ function forena_menu() {
'type'
=>
MENU_LOCAL_TASK
,
);
$items
[
'reports/%/parameters'
]
=
array
(
'title'
=>
'Params'
,
'page callback'
=>
'forena_parameters_report'
,
'page arguments'
=>
array
(
1
),
'access arguments'
=>
array
(
'design any report'
),
'description'
=>
t
(
'Edit the parameters of your report'
),
'weight'
=>
-
5
,
'type'
=>
MENU_LOCAL_TASK
,
);
$items
[
'forena'
]
=
array
(
'page callback'
=>
'forena_user_reports'
,
'page arguments'
=>
array
(),
...
...
@@ -53,13 +63,22 @@ function forena_menu() {
}
/**
* Calls forena_edit_form
*
*
in forena.admin.inc
*/
function
forena_edit_report
()
{
require_once
(
'forena.admin.inc'
);
return
drupal_get_form
(
'forena_edit_form'
);
}
/**
* Calls forena_parameter_form
* in forena.admin.inc
*/
function
forena_parameters_report
()
{
require_once
(
'forena.admin.inc'
);
return
drupal_get_form
(
'forena_parameters_form'
);
}
/**
* Implementation of hook_perm
*
...
...
@@ -76,7 +95,12 @@ function forena_perm() {
return
$perms
;
}
/**
* 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 unknown
*/
function
forena_report
()
{
$arg_list
=
func_get_args
();
require_once
(
'forena.common.inc'
);
...
...
@@ -113,40 +137,40 @@ function forena_report() {
return
$output
;
}
function
forena_user_reports
()
{
function
forena_user_reports
()
{
$result
=
db_query
(
'SELECT * FROM {forena_reports} where hidden=0 ORDER BY category,title asc'
);
$categories
=
array
();
while
(
$row
=
db_fetch_object
(
$result
))
{
while
(
$row
=
db_fetch_object
(
$result
))
{
$cache
=
$row
->
cache
;
//drupal_set_message($row->title. print_r('<pre>'.$cache.'</pre>',1));
if
(
$cache
)
{
if
(
$cache
)
{
$cache
=
unserialize
(
$cache
);
$access
=
FALSE
;
// Check each callback function to see if we have an error.
foreach
(
$cache
[
'access'
]
as
$callback
=>
$args
)
{
if
(
$callback
&&
$args
)
foreach
(
$args
as
$arg
)
{
foreach
(
$cache
[
'access'
]
as
$callback
=>
$args
)
{
if
(
$callback
&&
$args
)
foreach
(
$args
as
$arg
)
{
if
(
function_exists
(
$callback
))
{
$a
=
$callback
(
$arg
);
}
if
(
$a
)
$access
=
TRUE
;
if
(
$a
)
$access
=
TRUE
;
}
else
{
else
{
$access
=
FALSE
;
}
}
}
if
(
$access
)
{
}
if
(
$access
)
{
$categories
[
$row
->
category
][]
=
array
(
'title'
=>
$row
->
title
,
'report_name'
=>
$row
->
report_name
,
);
}
}
}
$report_repos
=
variable_get
(
'forena_path'
,
'reports'
);
foreach
(
$categories
as
$category
=>
$reports
)
{
$output
.
=
'<h3>'
.
$category
.
'</h3>'
;
$output
.
=
'<ul>'
;
foreach
(
$reports
as
$r
)
{
...
...
@@ -192,6 +216,15 @@ function forena_forena_plugins() {
return
$plugins
;
}
/**
* Self register controls with forena.
*
*/
function
forena_forena_controls
()
{
$controls
[]
=
array
(
'file'
=>
'plugins/FrxControls.inc'
,
'class'
=>
'FrxControls'
,
);
return
$controls
;
}
plugins/FrxDrupal.inc
View file @
1237c560
...
...
@@ -77,30 +77,11 @@ class FrxDrupal extends FrxDataEngine {
* Below here are formatting types
*/
public
function
formats
()
{
$formats
=
array
(
'drupal_date_format'
=>
'Drupal Date'
,
'drupal_filter'
=>
'Drupal Input Filter'
// 'drupal_node' => 'Node Teaser from node id',
);
$formats
=
array
(
'drupal_filter'
=>
'Drupal Input Filter'
);
return
$formats
;
}
public
function
drupal_date_format
(
$value
,
$format_str
)
{
switch
(
$format_str
)
{
case
'medium'
:
case
'small'
:
case
'large'
:
$type
=
$format_str
;
$format
=
''
;
break
;
default
:
$type
=
'custom'
;
$format
=
$format_str
;
}
return
format_date
(
$value
,
$type
,
$format
);
}
public
function
drupal_filter
(
$nid
,
$bool
)
{
$node
=
node_load
(
$nid
,
NULL
,
TRUE
);
if
(
!
$node
){
...
...
repos/reports/DrupalUserLogs.frx
View file @
1237c560
...
...
@@ -4,7 +4,10 @@
<frx:category>
Drupal Administration
</frx:category>
<frx:options
/>
<frx:parameters
>
<frx:parm
id=
"user"
require=
"1"
label=
"User Name"
>
3
</frx:parm>
<frx:parm
id=
"name"
require=
"1"
label=
"User Name"
>
3
</frx:parm>
</frx:parameters>
<frx:parameters
>
<frx:parm
id=
"search"
require=
"0"
label=
"Search"
>
school
</frx:parm>
</frx:parameters>
<frx:fields>
<frx:field
id=
"details"
link=
"admin/reports/event/{wid}"
>
Details
</frx:field>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment