You are here

function matrix_compact_table in Matrix field 6.2

1 call to matrix_compact_table()
matrix_format_prepare in ./matrix.module
Prepare the data to be rendered.

File

./matrix.module, line 1065
Defines simple matrix field types.

Code

function matrix_compact_table(&$data, $empty_value) {
  if (count($data)) {
    $empty_cols = array_fill(1, count($data[0]) - 1, TRUE);

    // Start from data rows
    foreach ($data as $row_id => $row) {
      $empty_row = TRUE;
      foreach ($row as $col_id => $cell) {

        // Style first col
        if ($col_id == 1) {
          $data[$row_id][$col_id] = array(
            'class' => 'matrix-second-col',
            'data' => $data[$row_id][$col_id],
          );
        }
        if ($col_id == 0) {
        }
        else {
          if ($cell != $empty_value) {
            $empty_row = FALSE;
            if ($row_id != 0) {
              $empty_cols[$col_id] = FALSE;
            }
          }
        }
      }

      // Whipe Empty Cols
      if ($empty_row) {
        unset($data[$row_id]);
      }
    }

    // Whipe Empty Rows
    foreach ($data as $row_id => $row) {
      foreach ($row as $col_id => $cell) {
        if ($empty_cols[$col_id]) {
          unset($data[$row_id][$col_id]);
        }
      }
    }
  }
}