function matrix_field in Matrix field 5
Same name and namespace in other branches
- 6.2 matrix.module \matrix_field()
- 6 matrix.module \matrix_field()
Implementation of hook_field().
File
- ./
matrix.module, line 62
Code
function matrix_field($op, &$node, $field, &$node_field, $teaser, $page) {
switch ($op) {
case 'load':
$result = db_query("SELECT value, row, col FROM {node_field_matrix_data} WHERE vid = %d AND field_name = '%s'", $node->vid, $field['field_name']);
$values = array();
while ($data = db_fetch_array($result)) {
$values[$data["row"]][$data["col"]] = $data['value'];
}
$additions = array(
$field['field_name'] => $values,
);
return $additions;
case 'update':
db_query("DELETE FROM {node_field_matrix_data} WHERE vid = %d and field_name= '%s'", $node->vid, $field['field_name']);
case 'insert':
$rows = trim($field['rows']);
$cols = trim($field['cols']);
$rows = explode("\n", $rows);
$cols = explode("\n", $cols);
$i = 0;
foreach ($rows as $row) {
if ($row) {
$j = 0;
foreach ($cols as $col) {
if ($col) {
db_query("INSERT INTO {node_field_matrix_data} (nid, vid, field_name, row, col, value)\n VALUES (%d, %d, '%s', %d, %d, '%s')", $node->nid, $node->vid, $field['field_name'], $i, $j, $node_field[$i][$j]);
$j++;
}
}
$i++;
}
}
break;
}
}