private function remote__data_formatter::createTable

3.x remote__data_formatter.inc private remote__data_formatter::createTable($item, &$pkey = '', &$rows = array(), $depth = 0)

A recursive function for displaying an item in a table.

Parameters

$item: An item from the $items array passed to the view() function.

Return value

An HTML formatted Table.

1 call to remote__data_formatter::createTable()
remote__data_formatter::view in tripal_ws/includes/TripalFields/remote__data/remote__data_formatter.inc
Provides the display for a field

File

tripal_ws/includes/TripalFields/remote__data/remote__data_formatter.inc, line 235

Class

remote__data_formatter

Code

private function createTable($item, &$pkey = '', &$rows = array(), $depth = 0) {
  foreach ($item as $key => $value) {
    // Skip JSON-LD keys.
    if (preg_match('/^\@/', $key)) {
      continue;
    }
    $key = preg_replace('/_/', ' ', $key);
    $key = ucwords($key);
    if ($pkey) {
      $key = $pkey . ' ' . $key;
    }
    if (is_array($value)) {
      $this->createTable($value, $key, $rows, $depth + 1);
    }
    else {
      $rows[] = array(
        'data' => array(
          $key,
          $value
        ),
        'no_striping' => TRUE,
      );
    }
  }
  if ($depth == 0) {
    $headers = array('Data Type', 'Value');
    return theme_table(array(
      'header' => $headers,
      'rows' => $rows,
      'attributes' => array(
        'class' => 'tripal-remote--data-field-table',
      ),
      'sticky' => FALSE,
      'caption' => "",
      'colgroups' => array(),
      'empty' => 'There are no results.',
    ));
  }
}