Suggestions asked about: 'dynamic tables module' idea
I'm trying to make a module or CCK field type to solve problem of data related to a pair of node (in stead of just one)
Imagine following problem:
cycling news site
content types:
- cyclists containing name and description (+ other CCK fields)
- race containing name and description (+ other CCK fields: date of the race, sponsors, ...)
Next we want to add the race result of each cyclist for each race. Being his position and the points he earned.
This information belongs to a pair of nodes (the result of a cyclist in a race), not to the cyclist or the race by itself.
you can't attach the points to the cyclist (he probably races multiple races) nor the race.
One would typically store this in a table like: race - cyclist - result - points. Where the 'race - cyclist' pair is the key for this table.
How to solve this in drupal?
METHOD 1:
- create a new CCK content type called race result with 4 fields: race (a node reference), cyclist (a node reference), result (new data), points earned (also new data)
PROBLEM: to create a race result, you have to create race result nodes for each contestant of the race manually. (using editview might simplify this a little, but you'd still have to select the race and racers)
METHOD 2:
- create a new CCK fieldtype, a table
METHOD 3:
- create a new content type
ENDRESULT
The result should allow following workflow:
1. user clicks 'create new race result'
2. user is asked for the key pair: race and cyclist --> like selecting fields in views
3. user is asked which pairs to create
3a. manually select race cyclist pairs
3b. use a filter to select pairs automatically (like all cyclists that were in this race -> if this data is available
eg. from a contestants field in the 'race content type')
3c. load the pairs from a table (allow user to load/save a table of pairs)
4. user can enter the additional data (result and points earned) for every selected pair (in a table like layout)
5. store the data to a table
6. The display is simply a table with everything filled out
REMARKS
- one could also embed the race result in the race content type. Making the node itself one of the fields in the key pair (race - cyclist)
- next to the filter, one could also add a method to automatically order the pairs (eg. by result or by team)
CONCLUSION
- Would anyone else be interested in this type of functionality?
- Ideas, suggestions how this could be implemented? (maybe there are modules available that i can extend or something).
- Is it possible to achieve this with a new CCK field type?
- How to start?

programmatically adding form fields
I decided to write a new node module, content type is sheet.
I have the following hook_form implementation:
function sheet_form(&$node) {$type = node_get_types('type', $node); /*get configuration info (using title and body ?)*/
// Existing files: title (Errorsheet) and body (Information)
if ($type->has_title) {
$form['title'] = array(
'#type' => 'textfield',
'#title' => check_plain($type->title_label),
'#required' => TRUE,
'#default_value' => $node->title,
'#weight' => -5,
);
}
if ($type->has_body) {
$form['body_field'] = node_body_field(
$node,
$type->body_label,
$type->min_word_count
);
}
Now i want create fieldsets (containing error, amount, remarkfields) programmatically. 1 fieldset for every error that is in a 'layout table'. Something like:
/*get a list of errors that need to be added to the form from the database*/
$errors_for_display = db_query(
'SELECT field_sheetlayout_error_nid FROM {content_field_sheetlayout_error} WHERE vid = 38'
);
/* for every error of this layout, add a fieldset to the form*/
foreach ($errors_for_display as &$value) {
// Our custom fields: errorvid, amount, remark. defined for every error of the layout table.
// (See FAPI docs for specification)
$form[$value]['error'] = array(
'#type' => 'textfield',
'#size' => 50,
'#maxlength' => 127,
'#title' => t('Error'),
'#description' => t('Error reference'),
'#default_value' => isset($node->error) ? $node->error : '',
);
$form[$value]['amount'] = array(
'#type' => 'textfield',
'#title' => t('amount'),
'#size' => 50,
'#maxlength' => 127,
'#description' => t('amount of errors'),
'#default_value' => isset($node->amount) ? $node->amount : '',
);
$form[$value]['remarks'] = array(
'#type' => 'textfield',
'#title' => t('remarks'),
'#size' => 50,
'#maxlength' => 127,
'#description' => t('remarks concerning the error'),
'#default_value' => isset($node->remarks) ? $node->remarks : '',
);
}
unset($value); // break the reference with the last element
return $form;
But my syntax isn't good. limited php knowledge. Anyone can help me out?
- is it the db_query? How can i get an array from this query?
executing following in
executing following in devel
if (db_query("SELECT field_sheetlayout_error_nid FROM {content_field_sheetlayout_error} WHERE vid = 38") == FALSE) {
echo "bad query";
} else {
echo "ok";
}
i get ok. change false to TRUE i get bad query, so apparantly this just returns TRUE???
How to get an array?