You are here

function _matrix_format_cell in Matrix field 6.2

Format cell for display

Parameters

$element_type string The type of element in the cell in question:

$cell_value string The value of the cell:

$empty string Placeholder for empty cells:

$calc_data array Data used for calculation fields:

Return value

Formatted cell

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

File

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

Code

function _matrix_format_cell($element_type, $cell_value, $empty, $calc_data = NULL) {
  switch ($element_type) {
    case 'textfield':
    case 'select':
    case 'radios':
    default:
      if ($cell_value == '') {
        return $empty;
      }
      else {
        return $cell_value;
      }
    case 'checkbox':
      if ($cell_value == 1) {
        return t('Yes');
      }
      else {
        return t('No');
      }
    case 'calculation':
      switch ($calc_data['calc_method']) {
        case 'sum':
          $sum = 0;
          foreach ($calc_data['data'] as $d) {
            if (is_numeric($d)) {
              $sum = +$d;
            }
          }
          return $sum;
        case 'average':
          $sum = 0;
          foreach ($calc_data['data'] as $d) {
            if (is_numeric($d)) {
              $sum = +$d;
            }
          }
          return round($sum / count($calc_data['data']), 2);
        case 'min':
          return min($calc_data['data']);
        case 'max':
          return max($calc_data['data']);
        case 'mode':
      }
    case 'title':
      return '';
  }
}