You are here

function tablefield_rationalize_table in TableField 6

Same name and namespace in other branches
  1. 7 tablefield.module \tablefield_rationalize_table()
2 calls to tablefield_rationalize_table()
tablefield_field in ./tablefield.module
Implementation of hook_field().
tablefield_process in ./tablefield.module
Process the tablefield

File

./tablefield.module, line 439
This module provides a set of fields that can be used to store tabular data with a node. The implementation uses a custom CCK widget.

Code

function tablefield_rationalize_table($tablefield) {
  $count_cols = $tablefield['count_cols'];
  unset($tablefield['count_cols']);
  $count_rows = $tablefield['count_rows'];
  unset($tablefield['count_rows']);
  unset($tablefield['rebuild']);

  // Rationalize the table data
  if (!empty($tablefield)) {
    foreach ($tablefield as $key => $value) {
      preg_match('/cell_(.*)_(.*)/', $key, $cell);

      // $cell[1] is row count $cell[2] is col count
      if ((int) $cell[1] < $count_rows && $cell['2'] < $count_cols) {
        $tabledata[$cell[1]][$cell[2]] = $value;
      }
    }
  }
  return $tabledata;
}