| 1 |
<?php
|
| 2 |
// $Id: matrix.inc,v 1.3 2008/10/27 00:17:02 aaron1234nz Exp $
|
| 3 |
|
| 4 |
/*
|
| 5 |
* Implementation of hook_elements
|
| 6 |
*/
|
| 7 |
function fusioncharts_elements() {
|
| 8 |
$type['matrixfield'] = array(
|
| 9 |
'#attributes' => array('class' => 'matrixfield'),
|
| 10 |
'#input' => TRUE,
|
| 11 |
'#default_value' => array()
|
| 12 |
);
|
| 13 |
return $type;
|
| 14 |
}
|
| 15 |
|
| 16 |
// function borrowed from the matrix module
|
| 17 |
function theme_matrix_table_form($form) {
|
| 18 |
$rows = array();
|
| 19 |
$header = $form['header']['#value'];
|
| 20 |
|
| 21 |
foreach ($form['matrix'] as $row_key => $fields) {
|
| 22 |
if (!empty($form['first_col']['#value'][$row_key])) {
|
| 23 |
$row = array();
|
| 24 |
$row[] = $form['first_col']['#value'][$row_key];
|
| 25 |
foreach ($fields as $col_key => $field) {
|
| 26 |
if ($field['#type'] == 'textfield') {
|
| 27 |
$row[] = drupal_render($form['matrix'][$row_key][$col_key]);
|
| 28 |
}
|
| 29 |
}
|
| 30 |
$rows[] = $row;
|
| 31 |
}
|
| 32 |
}
|
| 33 |
|
| 34 |
drupal_render($form['header']);
|
| 35 |
drupal_render($form['first_col']);
|
| 36 |
$output .= theme('table', $header, $rows, array('class' => 'matrix'));
|
| 37 |
return $output;
|
| 38 |
}
|
| 39 |
|
| 40 |
// function borowed from the matrix module
|
| 41 |
function theme_matrix_table_view($node_field, $field) {
|
| 42 |
$header[] = '';
|
| 43 |
for ($i=1; $i<= MATRIX_NUMBER; $i++) {
|
| 44 |
if (!empty($field['label_column_'. $i])) {
|
| 45 |
$header[] = $field['label_column_'. $i];
|
| 46 |
}
|
| 47 |
$rows = NULL;
|
| 48 |
if (!empty($field['label_row_'. $i])) {
|
| 49 |
$rows[] = $field['label_row_'. $i];
|
| 50 |
for ($j=1; $j<= MATRIX_NUMBER; $j++) {
|
| 51 |
if (!empty($node_field[$i][$j])) {
|
| 52 |
$rows[] = $node_field[$i][$j];
|
| 53 |
}
|
| 54 |
elseif (!empty($field['label_column_'. $j])) {
|
| 55 |
$rows[] = '-';
|
| 56 |
}
|
| 57 |
}
|
| 58 |
}
|
| 59 |
if ($rows) $row[] = $rows;
|
| 60 |
}
|
| 61 |
return theme('table', $header, $row, array('style' => 'width:auto'));
|
| 62 |
}
|
| 63 |
|
| 64 |
function theme_matrixfield($element) {
|
| 65 |
$header = array();
|
| 66 |
$header[0] = '';
|
| 67 |
$first_col = array();
|
| 68 |
$rows_count = count($element['#rows']);
|
| 69 |
$cols_count = count($element['#cols']);
|
| 70 |
array_unshift($element['#rows'], '');
|
| 71 |
array_unshift($element['#cols'], '');
|
| 72 |
for ($i=0; $i< $rows_count; $i++) {
|
| 73 |
$first_col[$i] = $element['#rows'][$i+1];
|
| 74 |
for ($j=0; $j< $cols_count; $j++) {
|
| 75 |
$header[$j+1] = $element['#cols'][$j+1];
|
| 76 |
$form['matrix'][$i][$j] = array(
|
| 77 |
'#type' => 'textfield',
|
| 78 |
'#size' => 5,
|
| 79 |
'#parents' => array(
|
| 80 |
0 => $element['#name'],
|
| 81 |
1 => 'matrix',
|
| 82 |
2 => $i,
|
| 83 |
3 => $j,
|
| 84 |
),
|
| 85 |
'#name' => "{$element['#name']}[matrix][$i][$j]",
|
| 86 |
'#id' => "edit-field-{$element['#name']}-matrix-$i-$j",
|
| 87 |
'#value' => isset($element['#default_value'][$i][$j]) ? $element['#default_value'][$i][$j] : '',
|
| 88 |
);
|
| 89 |
}
|
| 90 |
}
|
| 91 |
$form['header'] = array('#value' => $header);
|
| 92 |
$form['first_col'] = array('#value' => $first_col);
|
| 93 |
$output = theme('matrix_table_form', $form);
|
| 94 |
return theme('form_element', $element, $output);
|
| 95 |
}
|