function tripal_feature_edit_ALL_relationships_form_validate
1.x tripal_feature-relationships.inc | tripal_feature_edit_ALL_relationships_form_validate($form, &$form_state) |
Related topics
File
- tripal_feature/
includes/ tripal_feature-relationships.inc, line 343 - @todo Add file header description
Code
function tripal_feature_edit_ALL_relationships_form_validate($form, &$form_state) {
// Only Require if Updating Relationships
if ($form_state['clicked_button']['#value'] == t('Update All Relationships')) {
for ($i = 1; $i <= $form_state['values']['num_relationships']; $i++) {
// check valid stock selected for subject
$criteria = array('unknown' => array('value' => $form_state['values']["subject_id-$i"],
'columns' => array('name', 'uniquename', 'accession', 'synonym')));
$subject_results = get_chado_stocks($criteria, 'ANY', $_SESSION['organism']);
if (sizeof($subject_results) > 1) {
$links = array();
for ($j = 0; $j < sizeof($subject_results); $j++) {
$links[] = l($j + 1, "node/" . $subject_results[$j]->nid);
}
$message = t("Too many features match '%subject'! Please refine your input to
match ONLY ONE feature. <br /> To aid in this process, here are the features that
match your initial input: %features",
array('%subject' => $form_state['values']["subject_id-$i"],
'%features' => join(', ', $links)
)
);
form_set_error("subject_id-$i", $message);
}
elseif (sizeof($subject_results) < 1) {
form_set_error("subject_id-$i", t("There are no features matching your input. Please check your input for typos and/or lookup the <a href='!url'>here</a>", array('!url' => url('features'))));
}
elseif (sizeof($subject_results) == 1) {
$form_state['values']["subject_id-$i"] = $subject_results[0]->stock_id;
}
// check valid stock selected for object
$criteria = array('unknown' => array('value' => $form_state['values']["object_id-$i"],
'columns' => array('name', 'uniquename', 'accession', 'synonym')));
$object_results = get_chado_stocks($criteria, 'ANY', $_SESSION['organism']);
if (sizeof($object_results) > 1) {
$links = array();
for ($j = 0; $j < sizeof($object_results); $j++) {
$links[] = l($j + 1, "node/" . $object_results[$j]->nid);
}
$message = "Too many stocks match '" . $form_state['values']["object_id-$i"] . "'! "
. "Please refine your input to match ONLY ONE stock. <br />"
. "To aid in this process, here are the stocks that match your initial input: "
. join(', ', $links);
form_set_error("object_id-$i", $message);
}
elseif (sizeof($object_results) < 1) {
form_set_error("object_id-$i", t("There are no features matching your input. Please check your input for typos and/or lookup the <a href='!url'>here</a>", array('!url' => url('features'))));
}
elseif (sizeof($object_results) == 1) {
$form_state['values']["object_id-$i"] = $object_results[0]->stock_id;
}
// check valid type selected
if ($form_state['values']["type_id-$i"] == 0) {
form_set_error('type_id', 'Please select a type of relationship.');
}
else {
$tmp_obj = db_fetch_object(chado_query("SELECT count(*) as count FROM {cvterm} WHERE cvterm_id=%d", $form_state['values']["type_id-$i"]));
if ($tmp_obj->count != 1) {
form_set_error("type_id-$i", 'The type you selected is not valid. Please choose another one.');
}
}
// check either subject or object is the current stock
if ($subject_results[0]->nid != $form_state['values']['nid']) {
if ($object_results[0]->nid != $form_state['values']['nid']) {
form_set_error("subject_id-$i", 'Either Subject or Object must be the current stock (' . $form_state['values']['r_stock_uniquename'] . ').');
}
}
} // end of for each relationship
} //end of if updating relationships
}