You are here

function forena_parameter_form in Forena Reports 7

Same name and namespace in other branches
  1. 6.2 forena.common.inc \forena_parameter_form()
  2. 7.5 forena.module \forena_parameter_form()
  3. 7.2 forena.common.inc \forena_parameter_form()
  4. 7.3 forena.module \forena_parameter_form()
  5. 7.4 forena.module \forena_parameter_form()

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.

1 string reference to 'forena_parameter_form'
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 646
Common functions used throughout the project but loaded in this file to keep the module file lean.

Code

function forena_parameter_form($formid, &$form_state) {
  $parms = $_GET;
  unset($parms['q']);
  $form = array();
  $r = forena_report_object();
  if ($r) {
    drupal_set_title($r->title);
    $head = $r->rpt_xml->head;
    $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'];
      $value = isset($parms[$id]) ? $parms[$id] : (string) $node['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 'select':
          $list = array(
            '--select--',
          );
          break;
        case 'radios':
          $list = array(
            '--choose--',
          );
          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);
      }
      $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']['submit'] = array(
      '#type' => 'submit',
      '#value' => 'Submit',
    );
  }
  return $form;
}