|
@@ -281,9 +281,16 @@ function tripal_organism_permission() {
|
|
|
* @ingroup tripal_organism
|
|
|
*/
|
|
|
function chado_organism_validate($node, $form, &$form_state) {
|
|
|
+ // remove any white space around values
|
|
|
+ $node->genus = trim($node->genus);
|
|
|
+ $node->species = trim($node->species);
|
|
|
+ $node->abbreviation = trim($node->abbreviation);
|
|
|
+ $node->common_name = trim($node->common_name);
|
|
|
+ $node->description = trim($node->description);
|
|
|
+
|
|
|
// if this is an update, we want to make sure that a different organism doesn't
|
|
|
// already have this genus and speces
|
|
|
- if ($node->organism_id) {
|
|
|
+ if (property_exists($node, 'organism_id')) {
|
|
|
$sql = "
|
|
|
SELECT *
|
|
|
FROM {organism} O
|
|
@@ -328,6 +335,12 @@ function chado_organism_validate($node, $form, &$form_state) {
|
|
|
* @ingroup tripal_organism
|
|
|
*/
|
|
|
function chado_organism_insert($node) {
|
|
|
+ // remove any white space around values
|
|
|
+ $node->genus = trim($node->genus);
|
|
|
+ $node->species = trim($node->species);
|
|
|
+ $node->abbreviation = trim($node->abbreviation);
|
|
|
+ $node->common_name = trim($node->common_name);
|
|
|
+ $node->description = trim($node->description);
|
|
|
|
|
|
$values = array(
|
|
|
'genus' => $node->genus,
|
|
@@ -336,10 +349,11 @@ function chado_organism_insert($node) {
|
|
|
'common_name' => $node->common_name,
|
|
|
'comment' => $node->description
|
|
|
);
|
|
|
+
|
|
|
// if there is an organism_id in the $node object then this must be a sync so
|
|
|
// we can skip adding the organism as it is already there, although
|
|
|
// we do need to proceed with the rest of the insert
|
|
|
- if (!$node->organism_id) {
|
|
|
+ if (!property_exists($node,'organism_id')) {
|
|
|
$organism = tripal_core_chado_insert('organism', $values);
|
|
|
if (!$organism) {
|
|
|
drupal_set_message(t('Unable to add organism.', 'warning'));
|
|
@@ -355,13 +369,13 @@ function chado_organism_insert($node) {
|
|
|
|
|
|
// Make sure the entry for this organism doesn't already exist in the
|
|
|
// chado_organism table if it doesn't exist then we want to add it.
|
|
|
-
|
|
|
- if (!chado_get_id_for_node('organism', $node->nid) ) {
|
|
|
- // next add the item to the drupal table
|
|
|
- $sql = "INSERT INTO {chado_organism} (nid, vid, organism_id) " .
|
|
|
- "VALUES (:nid, :vid, :organism_id)";
|
|
|
- $args = array(':nid' => $node->nid, ':vid' => $node->vid, ':organism_id' => $organism_id);
|
|
|
- db_query($sql, $args);
|
|
|
+ $check_org_id = chado_get_id_for_node('organism', $node->nid);
|
|
|
+ if (!$check_org_id) {
|
|
|
+ $record = new stdClass();
|
|
|
+ $record->nid = $node->nid;
|
|
|
+ $record->vid = $node->vid;
|
|
|
+ $record->organism_id = $organism_id;
|
|
|
+ drupal_write_record('chado_organism', $record);
|
|
|
}
|
|
|
|
|
|
// set the title for the node
|
|
@@ -380,6 +394,13 @@ function chado_organism_insert($node) {
|
|
|
* @ingroup tripal_organism
|
|
|
*/
|
|
|
function chado_organism_update($node) {
|
|
|
+ // remove any white space around values
|
|
|
+ $node->genus = trim($node->genus);
|
|
|
+ $node->species = trim($node->species);
|
|
|
+ $node->abbreviation = trim($node->abbreviation);
|
|
|
+ $node->common_name = trim($node->common_name);
|
|
|
+ $node->description = trim($node->description);
|
|
|
+
|
|
|
if ($node->revision) {
|
|
|
// there is no way to handle revisions in Chado but leave
|
|
|
// this here just to make not we've addressed it.
|
|
@@ -497,29 +518,42 @@ function chado_organism_add_image($node) {
|
|
|
*
|
|
|
* @ingroup tripal_organism
|
|
|
*/
|
|
|
-function chado_organism_form($node, $param) {
|
|
|
- $organism = $node->organism;
|
|
|
-
|
|
|
- // add in the comment since it is a text field and may not be included if too big
|
|
|
- $organism = tripal_core_expand_chado_vars($organism, 'field', 'organism.comment');
|
|
|
-
|
|
|
- // get form defaults
|
|
|
- $abbreviation = property_exists($node, 'abbreviation') ? property_exists($node, 'abbreviation') : $organism->abbreviation;
|
|
|
- $genus = property_exists($node, 'genus') ? property_exists($node, 'genus') : $organism->genus;
|
|
|
- $species = property_exists($node, 'species') ? property_exists($node, 'species') : $organism->species;
|
|
|
- $common_name = property_exists($node, 'common_name') ? property_exists($node, 'common_name') : $organism->common_name;
|
|
|
- $description = property_exists($node, 'description') ? property_exists($node, 'description') : $organism->comment;
|
|
|
- $organism_image = property_exists($node, 'organism_image') ? property_exists($node, 'organism_image') : '';
|
|
|
-
|
|
|
+function chado_organism_form($node, $form_state) {
|
|
|
$form = array();
|
|
|
+
|
|
|
+ // we have a file upload element on the form soe we need the multipart encoding type
|
|
|
$form['#attributes']['enctype'] = 'multipart/form-data';
|
|
|
+
|
|
|
+ // if the organism is part of the node object then we are editing. If not we are inserting
|
|
|
+ if (property_exists($node, 'organism')) {
|
|
|
+ $organism = $node->organism;
|
|
|
|
|
|
- // keep track of the organism id if we have one. If we do have one then
|
|
|
- // this would indicate an update as opposed to an insert.
|
|
|
- $form['organism_id'] = array(
|
|
|
- '#type' => 'value',
|
|
|
- '#value' => $organism->organism_id,
|
|
|
- );
|
|
|
+ // add in the comment since it is a text field and may not be included if too big
|
|
|
+ $organism = tripal_core_expand_chado_vars($organism, 'field', 'organism.comment');
|
|
|
+
|
|
|
+ // get form defaults
|
|
|
+ $abbreviation = property_exists($node, 'abbreviation') ? property_exists($node, 'abbreviation') : $organism->abbreviation;
|
|
|
+ $genus = property_exists($node, 'genus') ? property_exists($node, 'genus') : $organism->genus;
|
|
|
+ $species = property_exists($node, 'species') ? property_exists($node, 'species') : $organism->species;
|
|
|
+ $common_name = property_exists($node, 'common_name') ? property_exists($node, 'common_name') : $organism->common_name;
|
|
|
+ $description = property_exists($node, 'description') ? property_exists($node, 'description') : $organism->comment;
|
|
|
+ $organism_image = property_exists($node, 'organism_image') ? property_exists($node, 'organism_image') : '';
|
|
|
+
|
|
|
+ // set the organism_id in the form
|
|
|
+ $form['organism_id'] = array(
|
|
|
+ '#type' => 'value',
|
|
|
+ '#value' => $organism->organism_id,
|
|
|
+ );
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ // get form defaults
|
|
|
+ $abbreviation = property_exists($node, 'abbreviation') ? property_exists($node, 'abbreviation') : '';
|
|
|
+ $genus = property_exists($node, 'genus') ? property_exists($node, 'genus') : '';
|
|
|
+ $species = property_exists($node, 'species') ? property_exists($node, 'species') : '';
|
|
|
+ $common_name = property_exists($node, 'common_name') ? property_exists($node, 'common_name') : '';
|
|
|
+ $description = property_exists($node, 'description') ? property_exists($node, 'description') : '';
|
|
|
+ $organism_image = property_exists($node, 'organism_image') ? property_exists($node, 'organism_image') : '';
|
|
|
+ }
|
|
|
|
|
|
$form['abbreviation']= array(
|
|
|
'#type' => 'textfield',
|