function forena_parameters_form in Forena Reports 6
Form to edit parameters Extra features: In the parameters section of the report are new attributes frx:parm: @data_source = data block for the parameter to values from @data_field = specific field of the data block to recieve values from. if no field is specified then the first column is arbitrarily chosen. @type = The form element that will display the values: select, radios are supported default is textfield.
This function will evaluate each parameter, determine its type, data_source, and data_field and display those values appropriately.
2 string references to 'forena_parameters_form'
- forena_parameters_report in ./
forena.module - Calls forena_parameter_form in forena.common.inc
- forena_report in ./
forena.module - 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.
File
- ./
forena.common.inc, line 644 - Common functions used throughout the project but loaded in this file to keep the module file lean.
Code
function forena_parameters_form($form_state) {
$parms = $_GET;
unset($parms['q']);
$r = forena_report_object();
if ($r) {
drupal_set_title($r->title);
$head = $r->rpt_xml->head;
$form = array();
$form['params'] = array(
'#tree' => TRUE,
'#title' => 'Parameters',
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => $r->blocks_loaded,
);
$nodes = $head
->xpath('frx:parameters/frx:parm');
foreach ($nodes as $node) {
$label = (string) $node['label'];
$id = (string) $node['id'];
$data_source = (string) $node['data_source'];
$data_field = (string) $node['data_field'];
$type = (string) $node['type'];
if (isset($parms[$id])) {
$value = $parms[$id];
}
else {
$value = (string) $node;
if (strpos($value, '|') !== FALSE) {
$value = explode('|', $value);
}
}
$desc = (string) $node['desc'];
$label_field = (string) $node['label_field'];
strcmp((string) $node['require'], "1") == 0 ? $required = TRUE : ($required = FALSE);
//Determine the form element type to be displayed
//If select or radios is chosen then begin a $list array for display values.
switch ($type) {
case 'multiselect':
$type = 'select';
$multiselect = TRUE;
break;
case 'checkboxes':
case 'select':
case 'radios':
break;
default:
$type = 'textfield';
$list = '';
}
//If a data_source attr was found then create an array of
//returned values filtered against data_field attr.
if ($data_source) {
$list = forena_get_data_block_params($data_source, $data_field, $label_field);
if (!$required) {
$list = array(
'' => '',
) + $list;
}
}
$form['params'][$id] = array(
'#type' => $type,
'#title' => $label ? t($label) : t($id),
'#default_value' => $value,
'#required' => $required,
'#description' => $desc,
);
//if $list is not empty then push options
//onto the array. options will cause an error for
//textfield elements.
if ($type != 'textfield') {
$form['params'][$id]['#options'] = $list;
$form['params'][$id]['#multiple'] = $multiselect;
}
}
$form['params']['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
);
}
return $form;
}