|
@@ -1,6 +1,13 @@
|
|
|
<?php
|
|
|
/**
|
|
|
- * Provide information to drupal about the node types that we're creating
|
|
|
+ * @file
|
|
|
+ * Implements the organims node content type
|
|
|
+ */
|
|
|
+
|
|
|
+/**
|
|
|
+ * Implements hook_node_info().
|
|
|
+ *
|
|
|
+ * Provide information to drupal about the node types that we're creating
|
|
|
* in this module
|
|
|
*
|
|
|
* @ingroup tripal_organism
|
|
@@ -30,8 +37,9 @@ function tripal_organism_node_info() {
|
|
|
);
|
|
|
return $nodes;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
- * Implement hook_access().
|
|
|
+ * Implement hook_node_access().
|
|
|
*
|
|
|
* This hook allows node modules to limit access to the node types they define.
|
|
|
*
|
|
@@ -78,14 +86,124 @@ function chado_organism_node_access($node, $op, $account) {
|
|
|
}
|
|
|
return NULL;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
- * Implementation of hook_validate
|
|
|
+ * Implement hook_form().
|
|
|
+ *
|
|
|
+ * When editing or creating a new node of type 'chado_organism' we need
|
|
|
+ * a form. This function creates the form that will be used for this.
|
|
|
+ *
|
|
|
+ * @ingroup tripal_organism
|
|
|
+ */
|
|
|
+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;
|
|
|
+
|
|
|
+ // add in the comment since it is a text field and may not be included if too big
|
|
|
+ $organism = chado_expand_var($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,
|
|
|
+ );
|
|
|
+ $organism_id = $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') : '';
|
|
|
+
|
|
|
+ $organism_id = NULL;
|
|
|
+ }
|
|
|
+
|
|
|
+ $form['genus']= array(
|
|
|
+ '#type' => 'textfield',
|
|
|
+ '#title' => t('Genus'),
|
|
|
+ '#required' => TRUE,
|
|
|
+ '#default_value' => $genus,
|
|
|
+ );
|
|
|
+ $form['species']= array(
|
|
|
+ '#type' => 'textfield',
|
|
|
+ '#title' => t('Species'),
|
|
|
+ '#required' => TRUE,
|
|
|
+ '#default_value' => $species,
|
|
|
+ );
|
|
|
+ $form['abbreviation']= array(
|
|
|
+ '#type' => 'textfield',
|
|
|
+ '#title' => t('Abbreviation'),
|
|
|
+ '#required' => TRUE,
|
|
|
+ '#default_value' => $abbreviation,
|
|
|
+ );
|
|
|
+ $form['common_name']= array(
|
|
|
+ '#type' => 'textfield',
|
|
|
+ '#title' => t('Common Name'),
|
|
|
+ '#required' => TRUE,
|
|
|
+ '#default_value' => $common_name,
|
|
|
+ );
|
|
|
+ $form['description']= array(
|
|
|
+ '#type' => 'textarea',
|
|
|
+ '#rows' => 15,
|
|
|
+ '#title' => t('Description'),
|
|
|
+ '#default_value' => $description,
|
|
|
+ );
|
|
|
+ $form['organism_image']= array(
|
|
|
+ '#type' => 'file',
|
|
|
+ '#title' => t('Organism Image'),
|
|
|
+ '#description' => 'Add an image for this organism',
|
|
|
+ '#progress_indicator' => 'bar',
|
|
|
+ );
|
|
|
+
|
|
|
+ // PROPERTIES FORM
|
|
|
+ //---------------------------------------------
|
|
|
+ $details = array(
|
|
|
+ 'property_table' => 'organismprop', // the name of the prop table
|
|
|
+ 'base_foreign_key' => 'organism_id', // the name of the key in your base chado table
|
|
|
+ 'base_key_value' => $organism_id, // the value of organism_id for this record
|
|
|
+ 'cv_name' => 'organism_property' // the cv.name of the cv governing organismprop.type_id
|
|
|
+ );
|
|
|
+ // Adds the form elements to your current form
|
|
|
+ chado_add_node_form_properties($form, $form_state, $details);
|
|
|
+
|
|
|
+ // ADDITIONAL DBXREFS FORM
|
|
|
+ //---------------------------------------------
|
|
|
+ $details = array(
|
|
|
+ 'linking_table' => 'organism_dbxref', // the name of the _dbxref table
|
|
|
+ 'base_foreign_key' => 'organism_id', // the name of the key in your base chado table
|
|
|
+ 'base_key_value' => $organism_id // the value of organism_id for this record
|
|
|
+ );
|
|
|
+ // Adds the form elements to your current form
|
|
|
+ chado_add_node_form_dbxrefs($form, $form_state, $details);
|
|
|
+
|
|
|
+ return $form;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Implementation of hook_validate().
|
|
|
*
|
|
|
* @param $node
|
|
|
* @param $form
|
|
|
* @param $form_state
|
|
|
*
|
|
|
- * @ingroup tripal_organism
|
|
|
+ * @ingroup tripal_organism
|
|
|
*/
|
|
|
function chado_organism_validate($node, $form, &$form_state) {
|
|
|
// remove any white space around values
|
|
@@ -143,7 +261,10 @@ function chado_organism_validate($node, $form, &$form_state) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
+ * Implements hook_insert().
|
|
|
+ *
|
|
|
* When a new chado_organism node is created we also need to add information
|
|
|
* to our chado_organism table. This function is called on insert of a new node
|
|
|
* of type 'chado_organism' and inserts the necessary information.
|
|
@@ -216,8 +337,9 @@ function chado_organism_insert($node) {
|
|
|
// add the image
|
|
|
chado_organism_add_image($node);
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
- * Update organisms
|
|
|
+ * Implements hook_update().
|
|
|
*
|
|
|
* @ingroup tripal_organism
|
|
|
*/
|
|
@@ -267,7 +389,10 @@ function chado_organism_update($node) {
|
|
|
);
|
|
|
chado_update_node_form_dbxrefs($node, $details);
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
+ * Implements hook_delete().
|
|
|
+ *
|
|
|
* Delete organism from both drupal and chado databases. Check dependency before
|
|
|
* deleting from chado.
|
|
|
*
|
|
@@ -309,7 +434,12 @@ function chado_organism_delete($node) {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Add an image to an organims node
|
|
|
+ *
|
|
|
+ * @param $node
|
|
|
+ * The node to add an image to
|
|
|
*
|
|
|
+ * The file is specified in the $_FILES array created by Drupal
|
|
|
*
|
|
|
* @ingroup tripal_organism
|
|
|
*/
|
|
@@ -337,115 +467,9 @@ function chado_organism_add_image($node) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
- * When editing or creating a new node of type 'chado_organism' we need
|
|
|
- * a form. This function creates the form that will be used for this.
|
|
|
+ * Implements hook_load().
|
|
|
*
|
|
|
- * @ingroup tripal_organism
|
|
|
- */
|
|
|
-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;
|
|
|
-
|
|
|
- // add in the comment since it is a text field and may not be included if too big
|
|
|
- $organism = chado_expand_var($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,
|
|
|
- );
|
|
|
- $organism_id = $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') : '';
|
|
|
-
|
|
|
- $organism_id = NULL;
|
|
|
- }
|
|
|
-
|
|
|
- $form['genus']= array(
|
|
|
- '#type' => 'textfield',
|
|
|
- '#title' => t('Genus'),
|
|
|
- '#required' => TRUE,
|
|
|
- '#default_value' => $genus,
|
|
|
- );
|
|
|
- $form['species']= array(
|
|
|
- '#type' => 'textfield',
|
|
|
- '#title' => t('Species'),
|
|
|
- '#required' => TRUE,
|
|
|
- '#default_value' => $species,
|
|
|
- );
|
|
|
- $form['abbreviation']= array(
|
|
|
- '#type' => 'textfield',
|
|
|
- '#title' => t('Abbreviation'),
|
|
|
- '#required' => TRUE,
|
|
|
- '#default_value' => $abbreviation,
|
|
|
- );
|
|
|
- $form['common_name']= array(
|
|
|
- '#type' => 'textfield',
|
|
|
- '#title' => t('Common Name'),
|
|
|
- '#required' => TRUE,
|
|
|
- '#default_value' => $common_name,
|
|
|
- );
|
|
|
- $form['description']= array(
|
|
|
- '#type' => 'textarea',
|
|
|
- '#rows' => 15,
|
|
|
- '#title' => t('Description'),
|
|
|
- '#default_value' => $description,
|
|
|
- );
|
|
|
- $form['organism_image']= array(
|
|
|
- '#type' => 'file',
|
|
|
- '#title' => t('Organism Image'),
|
|
|
- '#description' => 'Add an image for this organism',
|
|
|
- '#progress_indicator' => 'bar',
|
|
|
- );
|
|
|
-
|
|
|
- // PROPERTIES FORM
|
|
|
- //---------------------------------------------
|
|
|
- $details = array(
|
|
|
- 'property_table' => 'organismprop', // the name of the prop table
|
|
|
- 'base_foreign_key' => 'organism_id', // the name of the key in your base chado table
|
|
|
- 'base_key_value' => $organism_id, // the value of organism_id for this record
|
|
|
- 'cv_name' => 'organism_property' // the cv.name of the cv governing organismprop.type_id
|
|
|
- );
|
|
|
- // Adds the form elements to your current form
|
|
|
- chado_add_node_form_properties($form, $form_state, $details);
|
|
|
-
|
|
|
- // ADDITIONAL DBXREFS FORM
|
|
|
- //---------------------------------------------
|
|
|
- $details = array(
|
|
|
- 'linking_table' => 'organism_dbxref', // the name of the _dbxref table
|
|
|
- 'base_foreign_key' => 'organism_id', // the name of the key in your base chado table
|
|
|
- 'base_key_value' => $organism_id // the value of organism_id for this record
|
|
|
- );
|
|
|
- // Adds the form elements to your current form
|
|
|
- chado_add_node_form_dbxrefs($form, $form_state, $details);
|
|
|
-
|
|
|
- return $form;
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
* When a node is requested by the user this function is called to allow us
|
|
|
* to add auxiliary data to the node object.
|
|
|
*
|
|
@@ -469,11 +493,14 @@ function chado_organism_load($nodes) {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Implements hook_node_presave(). Acts on all content types.
|
|
|
*
|
|
|
* @param $node
|
|
|
+ * The node to be saved
|
|
|
+ *
|
|
|
+ * @ingroup tripal_organism
|
|
|
*/
|
|
|
function tripal_organism_node_presave($node) {
|
|
|
- print_r($node->organism);
|
|
|
switch ($node->type) {
|
|
|
case 'chado_organism':
|
|
|
// for a form submission the 'genus' field will be set,
|
|
@@ -489,9 +516,11 @@ function tripal_organism_node_presave($node) {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
+ * Implements hook_node_view().
|
|
|
*
|
|
|
- * @ingroup tripal_feature
|
|
|
+ * @ingroup tripal_organism
|
|
|
*/
|
|
|
function tripal_organism_node_view($node, $view_mode, $langcode) {
|
|
|
switch ($node->type) {
|
|
@@ -522,4 +551,4 @@ function tripal_organism_node_view($node, $view_mode, $langcode) {
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
-}
|
|
|
+}
|