Browse Source

Added documentation and re-organized the install file for easier reading (moved schema defn. to the bottom, each in their own function for easy documentation.

Lacey Sanderson 10 năm trước cách đây
mục cha
commit
7ce3982520
2 tập tin đã thay đổi với 496 bổ sung381 xóa
  1. 481 379
      tripal_entities/tripal_entities.install
  2. 15 2
      tripal_entities/tripal_entities.module

+ 481 - 379
tripal_entities/tripal_entities.install

@@ -4,306 +4,186 @@
  * Install for a tripal data entity - creates the base table for our entity.
  */
 
+/**
+ * Implements hook_install().
+ */
 function tripal_entities_install() {
 
-  // add any custom tables. For this case we will add an 'file' table to the
-  // chado schema
-  tripal_entities_add_custom_tables();
-
-
+  // Create a number of Chado custom tables to keep track of vocabularies and terms
+  // that are available for use with entities.
+  // @TODO: Ask Stephen why these are chado instead of drupal tables...
+  chado_create_custom_table(
+    'tripal_vocabulary', 
+    tripal_entities_tripal_vocabulary_schema(), 
+    TRUE
+  );
+  chado_create_custom_table(
+    'tripal_vocabulary_usage', 
+    tripal_entities_tripal_vocabulary_usage_schema(), 
+    TRUE
+  );
+  chado_create_custom_table(
+    'tripal_term', 
+    tripal_entities_tripal_term_schema(), 
+    TRUE
+  );
+  chado_create_custom_table(
+    'tripal_term_usage', 
+    tripal_entities_tripal_term_usage_schema(), 
+    TRUE
+  );
+  chado_create_custom_table(
+    'tripal_term_relationship', 
+    tripal_entities_tripal_term_relationship_schema(), 
+    TRUE
+  );
 }
 
-
 /**
- *
+ * Implements hook_schema().
  */
-function tripal_entities_add_custom_tables() {
-  tripal_entities_add_tripal_vocabulary_table();
-  tripal_entities_add_tripal_vocabulary_usage_table();
-  tripal_entities_add_tripal_term_table();
-  tripal_entities_add_tripal_term_usage_table();
-  tripal_entities_add_tripal_term_relationship_table();
-}
+function tripal_entities_schema() {
 
-/**The current Entity Example (Genes) requires the Sequence Ontology.                                     [warning]
+  // Biological Data
+  $schema['tripal_entity'] = tripal_entities_tripal_entity_schema();
 
- *
- */
-function tripal_entities_add_tripal_vocabulary_table() {
-  $schema = array (
-    'table' => 'tripal_vocabulary',
-    'fields' => array (
-      'vocabulary_id' => array(
+  // Biological Data Types
+  $schema['tripal_bundle'] = tripal_entities_tripal_bundle_schema();
+
+  // Links Biological Data Entities to the chado "base" table the data is stored in.
+  $schema['chado_entity'] = tripal_entities_chado_entity_schema();
+
+  // @TODO: Move these tables into the tripal_fields_layout module.
+  $schema['tripal_panels'] = array(
+    'description' => 'The list of panels into which fields can be placed.',
+    'fields' => array(
+      'panel_id' => array(
+        'description' => 'The primary identifier for this table.',
         'type' => 'serial',
-        'not null' => TRUE
+        'unsigned' => TRUE,
+        'not null' => TRUE,
       ),
-      'cv_id' => array (
+      'bundle_id' => array(
+        'description' => 'A bundle ID from the tripal_bundle table.',
         'type' => 'int',
-        'not null' => TRUE
+        'not null' => TRUE,
       ),
-      'db_id' => array (
-        'type' => 'int',
-        'not null' => TRUE
+      'name' => array(
+        'description' => 'The computer readable name for the panel. This name must only have alphanumerical characters and underscores and must not begin with a number. ',
+        'type' => 'varchar',
+        'length' => 128,
+        'not null' => TRUE,
+        'default' => '',
       ),
-      'publish' => array (
-        'type' => 'int',
+      'label' => array(
+        'description' => 'A human readable name for panel. This name will be shown to users in the sidebar menu.',
+        'type' => 'varchar',
+        'length' => 128,
         'not null' => TRUE,
+        'default' => '',
+      ),
+      'settings' => array(
+        'description' => 'Contains a serialized array tripal_fields_layoutof settings for the panel.',
+        'type' => 'text',
+        'not null' => FALSE,
+      ),
+      'weight' => array(
+        'type' => 'int',
+        'not null' => FALSE,
         'default' => 0
       ),
     ),
-    'primary key' => array (
-      0 => 'vocabulary_id'
+    'indexes' => array(
+      'bundle_id' => array('bundle_id'),
     ),
-    'foreign keys' => array (
-      'cv' => array (
-        'table' => 'cv',
-        'columns' => array (
-          'cv_id' => 'cv_id'
-        )
-      ),
-      'db' => array (
-        'table' => 'db',
-        'columns' => array (
-          'db_id' => 'db_id'
-        )
-      ),
+    'unique keys' => array(
+      'bundle_panel' => array('bundle_id', 'name'),
     ),
-    'unique keys' => array (
-      'tripal_vocabulary_cvdb' => array (
-        'cv_id', 'db_id'
+    'foreign keys' => array(
+      'tripal_bundle' => array(
+        'table' => 'tripal_bundle',
+        'columns' => array(
+          'bundle_id' => 'id',
+        ),
       ),
     ),
-    'indexes' => array(
-      'tripal_vocabulary_cv_id' => array('cv_id'),
-      'tripal_vocabulary_db_id' => array('db_id'),
-    )
+    'primary key' => array('panel_id'),
   );
-  chado_create_custom_table('tripal_vocabulary', $schema, TRUE);
-}
-/**
- *
- */
-function tripal_entities_add_tripal_term_table() {
-  $schema = array (
-    'table' => 'tripal_term',
-    'fields' => array (
-      'term_id' => array(
+  $schema['tripal_panel_fields'] = array(
+    'description' => 'The list of panels into which fields can be placed.',
+    'fields' => array(
+      'panel_field_id' => array(
+        'description' => 'The primary identifier for this table.',
         'type' => 'serial',
-        'not null' => TRUE
-      ),
-      'vocabulary_id' => array (
-        'type' => 'int',
-        'not null' => TRUE
+        'unsigned' => TRUE,
+        'not null' => TRUE,
       ),
-      'cvterm_id' => array (
+      'panel_id' => array(
+        'description' => 'The primary identifier for this table.',
         'type' => 'int',
-        'not null' => TRUE
+        'not null' => TRUE,
       ),
-      'publish' => array (
+      'field_id' => array(
+        'description' => 'A bundle ID from the tripal_bundle table.',
         'type' => 'int',
         'not null' => TRUE,
-        'default' => 0
-      ),
-    ),
-    'primary key' => array (
-      0 => 'term_id'
-    ),
-    'foreign keys' => array (
-      'cvterm' => array (
-        'table' => 'cvterm',
-        'columns' => array (
-          'cvterm_id' => 'cvterm_id'
-        )
-      ),
-      'tripal_vocabulary' => array (
-        'table' => 'tripal_vocabulary',
-        'columns' => array (
-          'vocabulary_id' => 'vocabulary_id'
-        )
-      ),
-    ),
-    'unique keys' => array (
-      'tripal_term_unq' => array (
-        'vocabulary_id', 'cvterm_id'
       ),
     ),
     'indexes' => array(
-      'tripal_term_vocabulary_id' => array('vocabulary_id'),
-      'tripal_term_cvterm_id' => array('cvterm_id'),
-    ),
-  );
-  chado_create_custom_table('tripal_term', $schema, TRUE);
-}
-/**
- *
- */
-function tripal_entities_add_tripal_vocabulary_usage_table(){
-  $schema = array (
-    'table' => 'tripal_vocabulary_usage',
-    'fields' => array (
-      'vocabulary_usage_id' => array(
-        'type' => 'serial',
-        'not null' => TRUE
-      ),
-      'vocabulary_id' => array (
-        'type' => 'int',
-        'not null' => TRUE
-      ),
-      'data_table' => array (
-        'type' => 'varchar',
-        'length' => 128,
-        'not null' => TRUE
-      ),
-      'type_table' => array (
-        'type' => 'varchar',
-        'length' => 128,
-        'not null' => TRUE
-      ),
-      'field' => array (
-        'type' => 'varchar',
-        'length' => 128,
-        'not null' => TRUE
-      ),
+      'panel_id' => array('panel_id'),
+      'field_id' => array('field_id'),
     ),
-    'primary key' => array (
-      0 => 'vocabulary_usage_id'
+    'unique keys' => array(
+      'panel_field' => array('panel_id', 'field_id'),
     ),
-    'foreign keys' => array (
-      'tripal_vocabulary' => array (
-        'table' => 'tripal_vocabulary',
-        'columns' => array (
-          'vocabulary_id' => 'vocabulary_id'
+    'foreign keys' => array(
+      'tripal_panel' => array(
+        'table' => 'tripal_panel',
+        'columns' => array(
+          'panel_id' => 'panel_id',
         ),
       ),
-    ),
-    'unique keys' => array (
-      'tripal_vocabulary_ridbase' => array (
-        'vocabulary_id', 'data_table'
+      'field_config' => array(
+        'table' => 'field_config',
+        'columns' => array(
+          'field_id' => 'id',
+        ),
       ),
     ),
-    'indexes' => array(
-      'tripal_vocabulary_vocabulary_id' => array('vocabulary_id'),
-      'tripal_vocabulary_data_table' => array('data_table'),
-      'tripal_vocabulary_type_table' => array('type_table'),
-    ),
+    'primary key' => array('panel_field_id'),
   );
-  chado_create_custom_table('tripal_vocabulary_usage', $schema, TRUE);
+  
+  return $schema;
 }
+
 /**
+ * Implements hook_uninstall().
  *
+ * At uninstall time we'll notify field.module that the entity was deleted
+ * so that attached fields can be cleaned up.
  */
-function tripal_entities_add_tripal_term_usage_table(){
-  $schema = array (
-    'table' => 'tripal_term_usage',
-    'fields' => array (
-      'term_usage_id' => array(
-        'type' => 'serial',
-        'not null' => TRUE
-      ),
-      'term_id' => array (
-        'type' => 'int',
-        'not null' => TRUE
-      ),
-      'data_table' => array (
-        'type' => 'varchar',
-        'length' => 128,
-        'not null' => TRUE
-      ),
-      'type_table' => array (
-        'type' => 'varchar',
-        'length' => 128,
-        'not null' => TRUE
-      ),
-      'field' => array (
-        'type' => 'varchar',
-        'length' => 128,
-        'not null' => TRUE
-      ),
-    ),
-    'primary key' => array (
-      0 => 'term_usage_id'
-    ),
-    'foreign keys' => array (
-      'tripal_term' => array (
-        'table' => 'tripal_term',
-        'columns' => array (
-          'term_id' => 'term_id'
-        ),
-      ),
-    ),
-    'unique keys' => array (
-      'tripal_term_usage_ridbase' => array (
-        'term_id', 'type_table', 'field'
-      ),
-    ),
-    'indexes' => array(
-      'tripal_term_usage_term_id' => array('term_id'),
-    ),
-  );
-  chado_create_custom_table('tripal_term_usage', $schema, TRUE);
+function tripal_entities_uninstall() {
+  $terms = chado_generate_var('tripal_term', array('publish' => 1), array('return_array' => 1));
+  foreach ($terms as $term) {
+    $bundle_id = $term->cvterm_id->dbxref_id->db_id->name . '_' . $term->cvterm_id->dbxref_id->accession;
+    field_attach_delete_bundle('BioData', $bundle_id);
+  }
 }
+
 /**
- *
+ * @section
+ * Schema Definitions.
  */
-function tripal_entities_add_tripal_term_relationship_table(){
-  $schema = array (
-    'table' => 'tripal_term_relationship',
-    'fields' => array (
-      'relationship_id' => array(
-        'type' => 'serial',
-        'not null' => TRUE
-      ),
-      'subject_id' => array (
-        'type' => 'int',
-        'not null' => TRUE
-      ),
-      'type_id' => array (
-        'type' => 'int',
-        'not null' => TRUE
-      ),
-      'object_id' => array (
-        'type' => 'int',
-        'not null' => FALSE
-      ),
-      'fieldname' => array(
-        'type' => 'varchar',
-        'length' => 128,
-        'not null' => FALSE,
-      )
-    ),
-    'primary key' => array (
-      0 => 'relationship_id'
-    ),
-    'foreign keys' => array (
-      'tripal_term' => array (
-        'table' => 'tripal_term',
-        'columns' => array (
-          'subject_id' => 'term_id',
-          'object_id'  => 'term_id',
-        ),
-      ),
-    ),
-    'unique keys' => array (
-      'tripal_term_relationship_unq' => array (
-        'subject_id', 'type_id', 'object_id'
-      ),
-    ),
-    'indexes' => array(
-      'tripal_term_relationship_subject_id' => array('subject_id'),
-      'tripal_term_relationship_object_id' => array('object_id'),
-      'tripal_term_relationship_type_id' => array('type_id'),
-    ),
-  );
-  chado_create_custom_table('tripal_term_relationship', $schema, TRUE);
-}
+
 /**
- * Implements hook_schema().
+ * The base table for Biological Data Entities.
  *
- * @ingroup entity_example
+ * This contains the actual data. For example, if you have a 5 genes and 10 mRNA then
+ * this table will have 15 records and include both genes and mRNA's.
  */
-function tripal_entities_schema() {
+function tripal_entities_tripal_entity_schema() {
 
-  $schema['tripal_entity'] = array(
+  $schema = array(
     'description' => 'The base table for Tripal Vocabulary-based entities.',
     'fields' => array(
       'id' => array(
@@ -373,8 +253,18 @@ function tripal_entities_schema() {
     ),
     'primary key' => array('id'),
   );
+  return $schema;
+}
 
-  $schema['tripal_bundle'] = array(
+/**
+ * The base table for Biological Data Type Entites.
+ * This table contains a list of Biological Data Types. 
+ * For the example above (5 genes and 10 mRNAs), there would only be two records in 
+ * this table one for "gene" and another for "mRNA".
+ */
+function tripal_entities_tripal_bundle_schema() {
+
+  $schema = array(
     'description' => 'Stores information about defined tripal data types.',
     'fields' => array(
       'id' => array(
@@ -410,185 +300,397 @@ function tripal_entities_schema() {
         'size' => 'tiny',
         'description' => 'The weight of this tripal data type in relation to others.',
       ),
-      'data' => array(
-        'type' => 'text',
-        'not null' => FALSE,
-        'size' => 'big',
-        'serialize' => TRUE,
-        'description' => 'A serialized array of additional data related to this tripal data type.',
+      'data' => array(
+        'type' => 'text',
+        'not null' => FALSE,
+        'size' => 'big',
+        'serialize' => TRUE,
+        'description' => 'A serialized array of additional data related to this tripal data type.',
+      ),
+    ) + entity_exportable_schema_fields(),
+    'primary key' => array('id'),
+    'unique keys' => array(
+      'bundle' => array('bundle'),
+    ),
+  );
+  return $schema;
+}
+
+/**
+ * Links Biological Data Entities to the chado "base" table the data is stored in.
+ * This is where we would specify that a particular gene maps to the record in the
+ * chado.feature table with a feature_id=2432;
+ */
+function tripal_entities_chado_entity_schema() {
+
+  $schema = array(
+    'description' => 'The linker table that associates an enitity from the public.tripal_entity table with a "base" record in Chado',
+    'fields' => array(
+      'chado_entity_id' => array(
+        'description' => 'The primary identifier for this table.',
+        'type' => 'serial',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+      ),
+      'entity_id' => array(
+        'description' => 'The unique entity id.',
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'record_id' => array(
+        'description' => 'The unique numerical identifier for the record that this entity is associated with (e.g. feature_id, stock_id, library_id, etc.).',
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'data_table' => array(
+        'description' => 'Indicates the table in Chado that this term services (e.g. feature, stock, library, etc.)',
+        'type' => 'varchar',
+        'length' => 128,
+        'not null' => TRUE,
+        'default' => '',
+      ),
+      'type_table' => array(
+        'description' => 'Sometimes the record in the data table doesn’t have a field that specifies  the record type.  For example, an analysis type is stored in the analysisprop table.  If the data_table does have a type field then this value will be the same as the data_table.',
+        'type' => 'varchar',
+        'length' => 128,
+        'not null' => TRUE,
+        'default' => '',
+      ),
+      'field' => array(
+        'description' => 'The name of the field in the typetable that contains the cvterm record.',
+        'type' => 'varchar',
+        'length' => 128,
+        'not null' => FALSE,
+        'default' => ''
+      ),
+    ),
+    'indexes' => array(
+      'record_id' => array('record_id'),
+      'entity_id' => array('entity_id'),
+      'data_table' => array('data_table'),
+    ),
+    'unique keys' => array(
+      'record' => array('data_table', 'record_id'),
+      'entity_id' => array('entity_id'),
+    ),
+    'primary key' => array('chado_entity_id'),
+  );
+  return $schema;
+}
+
+/**
+ * A list of published vocabularies.
+ *
+ * Usage: This table will be used by the Entity type admin page that lets the site admin 
+ *   specify which vocabularies should be used as entity types.  This table will only be 
+ *   populated with vocabularies that are actually used within the Chado database.  This 
+ *   table will also be used by web services to provide a list of all of the entity types 
+ *   that are available for access.
+ */
+function tripal_entities_tripal_vocabulary_schema() {
+
+  $schema = array (
+    'table' => 'tripal_vocabulary',
+    'fields' => array (
+      'vocabulary_id' => array(
+        'type' => 'serial',
+        'not null' => TRUE
+      ),
+      'cv_id' => array (
+        'type' => 'int',
+        'not null' => TRUE
+      ),
+      'db_id' => array (
+        'type' => 'int',
+        'not null' => TRUE
+      ),
+      'publish' => array (
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0
+      ),
+    ),
+    'primary key' => array (
+      0 => 'vocabulary_id'
+    ),
+    'foreign keys' => array (
+      'cv' => array (
+        'table' => 'cv',
+        'columns' => array (
+          'cv_id' => 'cv_id'
+        )
+      ),
+      'db' => array (
+        'table' => 'db',
+        'columns' => array (
+          'db_id' => 'db_id'
+        )
+      ),
+    ),
+    'unique keys' => array (
+      'tripal_vocabulary_cvdb' => array (
+        'cv_id', 'db_id'
+      ),
+    ),
+    'indexes' => array(
+      'tripal_vocabulary_cv_id' => array('cv_id'),
+      'tripal_vocabulary_db_id' => array('db_id'),
+    )
+  );
+  return $schema;
+}
+
+/**
+ * A list of published terms.
+ *
+ * Usage: This table is used by web services to provide a list of all of the bundles 
+ *   (i.e. vocabulary terms) that have data in the site.   It is also used by the Entity 
+ *   administrative pages to allow the site admin to specify which terms should be 
+ *   publishable (i.e. used as bundles).
+ */
+function tripal_entities_tripal_term_schema() {
+
+  $schema = array (
+    'table' => 'tripal_term',
+    'fields' => array (
+      'term_id' => array(
+        'type' => 'serial',
+        'not null' => TRUE
+      ),
+      'vocabulary_id' => array (
+        'type' => 'int',
+        'not null' => TRUE
+      ),
+      'cvterm_id' => array (
+        'type' => 'int',
+        'not null' => TRUE
+      ),
+      'publish' => array (
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0
+      ),
+    ),
+    'primary key' => array (
+      0 => 'term_id'
+    ),
+    'foreign keys' => array (
+      'cvterm' => array (
+        'table' => 'cvterm',
+        'columns' => array (
+          'cvterm_id' => 'cvterm_id'
+        )
+      ),
+      'tripal_vocabulary' => array (
+        'table' => 'tripal_vocabulary',
+        'columns' => array (
+          'vocabulary_id' => 'vocabulary_id'
+        )
+      ),
+    ),
+    'unique keys' => array (
+      'tripal_term_unq' => array (
+        'vocabulary_id', 'cvterm_id'
       ),
-    ) + entity_exportable_schema_fields(),
-    'primary key' => array('id'),
-    'unique keys' => array(
-      'bundle' => array('bundle'),
+    ),
+    'indexes' => array(
+      'tripal_term_vocabulary_id' => array('vocabulary_id'),
+      'tripal_term_cvterm_id' => array('cvterm_id'),
     ),
   );
+  return $schema;
+}
 
-  $schema['chado_entity'] = array(
-    'description' => 'The linker table that associates an enitity from the public.tripal_entity table with a "base" record in Chado',
-    'fields' => array(
-      'chado_entity_id' => array(
-        'description' => 'The primary identifier for this table.',
+/**
+ * 
+ *
+ * Specifies the source table in Chado where this entity will pull data.  Because 
+ * vocabularies can be used in multiple tables there could be many entries here for each 
+ * vocabulary.
+ *
+ * Usage: This table is used by web services when querying for all of the records of a 
+ * given type.  Web services must know where to look for records of a given term.
+ */
+function tripal_entities_tripal_vocabulary_usage_schema(){
+
+  $schema = array (
+    'table' => 'tripal_vocabulary_usage',
+    'fields' => array (
+      'vocabulary_usage_id' => array(
         'type' => 'serial',
-        'unsigned' => TRUE,
-        'not null' => TRUE,
-      ),
-      'entity_id' => array(
-        'description' => 'The unique entity id.',
-        'type' => 'int',
-        'not null' => TRUE,
+        'not null' => TRUE
       ),
-      'record_id' => array(
-        'description' => 'The unique numerical identifier for the record that this entity is associated with (e.g. feature_id, stock_id, library_id, etc.).',
+      'vocabulary_id' => array (
         'type' => 'int',
-        'not null' => TRUE,
+        'not null' => TRUE
       ),
-      'data_table' => array(
-        'description' => 'Indicates the table in Chado that this term services (e.g. feature, stock, library, etc.)',
+      'data_table' => array (
         'type' => 'varchar',
         'length' => 128,
-        'not null' => TRUE,
-        'default' => '',
+        'not null' => TRUE
       ),
-      'type_table' => array(
-        'description' => 'Sometimes the record in the data table doesn’t have a field that specifies  the record type.  For example, an analysis type is stored in the analysisprop table.  If the data_table does have a type field then this value will be the same as the data_table.',
+      'type_table' => array (
         'type' => 'varchar',
         'length' => 128,
-        'not null' => TRUE,
-        'default' => '',
+        'not null' => TRUE
       ),
-      'field' => array(
-        'description' => 'The name of the field in the typetable that contains the cvterm record.',
+      'field' => array (
         'type' => 'varchar',
         'length' => 128,
-        'not null' => FALSE,
-        'default' => ''
+        'not null' => TRUE
       ),
     ),
-    'indexes' => array(
-      'record_id' => array('record_id'),
-      'entity_id' => array('entity_id'),
-      'data_table' => array('data_table'),
+    'primary key' => array (
+      0 => 'vocabulary_usage_id'
     ),
-    'unique keys' => array(
-      'record' => array('data_table', 'record_id'),
-      'entity_id' => array('entity_id'),
+    'foreign keys' => array (
+      'tripal_vocabulary' => array (
+        'table' => 'tripal_vocabulary',
+        'columns' => array (
+          'vocabulary_id' => 'vocabulary_id'
+        ),
+      ),
+    ),
+    'unique keys' => array (
+      'tripal_vocabulary_ridbase' => array (
+        'vocabulary_id', 'data_table'
+      ),
+    ),
+    'indexes' => array(
+      'tripal_vocabulary_vocabulary_id' => array('vocabulary_id'),
+      'tripal_vocabulary_data_table' => array('data_table'),
+      'tripal_vocabulary_type_table' => array('type_table'),
     ),
-    'primary key' => array('chado_entity_id'),
   );
+  return $schema;
+}
 
-  $schema['tripal_panels'] = array(
-    'description' => 'The list of panels into which fields can be placed.',
-    'fields' => array(
-      'panel_id' => array(
-        'description' => 'The primary identifier for this table.',
+/**
+ *
+ *
+ * Specifies the source table in Chado where this bundle will pull data.  Because terms 
+ * can be used in multiple tables there could be many entries here for each term. 
+ * 
+ * Note: this table contains the list of tables where a particular cvterm is used, 
+ * whereas, the tripal_entity_type_source just provides a list of where cvterms from a 
+ * particular vocabulary might be found.
+ */
+function tripal_entities_tripal_term_usage_schema() {
+
+  $schema = array (
+    'table' => 'tripal_term_usage',
+    'fields' => array (
+      'term_usage_id' => array(
         'type' => 'serial',
-        'unsigned' => TRUE,
-        'not null' => TRUE,
+        'not null' => TRUE
       ),
-      'bundle_id' => array(
-        'description' => 'A bundle ID from the tripal_bundle table.',
+      'term_id' => array (
         'type' => 'int',
-        'not null' => TRUE,
+        'not null' => TRUE
       ),
-      'name' => array(
-        'description' => 'The computer readable name for the panel. This name must only have alphanumerical characters and underscores and must not begin with a number. ',
+      'data_table' => array (
         'type' => 'varchar',
         'length' => 128,
-        'not null' => TRUE,
-        'default' => '',
+        'not null' => TRUE
       ),
-      'label' => array(
-        'description' => 'A human readable name for panel. This name will be shown to users in the sidebar menu.',
+      'type_table' => array (
         'type' => 'varchar',
         'length' => 128,
-        'not null' => TRUE,
-        'default' => '',
-      ),
-      'settings' => array(
-        'description' => 'Contains a serialized array tripal_fields_layoutof settings for the panel.',
-        'type' => 'text',
-        'not null' => FALSE,
+        'not null' => TRUE
       ),
-      'weight' => array(
-        'type' => 'int',
-        'not null' => FALSE,
-        'default' => 0
+      'field' => array (
+        'type' => 'varchar',
+        'length' => 128,
+        'not null' => TRUE
       ),
     ),
-    'indexes' => array(
-      'bundle_id' => array('bundle_id'),
-    ),
-    'unique keys' => array(
-      'bundle_panel' => array('bundle_id', 'name'),
+    'primary key' => array (
+      0 => 'term_usage_id'
     ),
-    'foreign keys' => array(
-      'tripal_bundle' => array(
-        'table' => 'tripal_bundle',
-        'columns' => array(
-          'bundle_id' => 'id',
+    'foreign keys' => array (
+      'tripal_term' => array (
+        'table' => 'tripal_term',
+        'columns' => array (
+          'term_id' => 'term_id'
         ),
       ),
     ),
-    'primary key' => array('panel_id'),
+    'unique keys' => array (
+      'tripal_term_usage_ridbase' => array (
+        'term_id', 'type_table', 'field'
+      ),
+    ),
+    'indexes' => array(
+      'tripal_term_usage_term_id' => array('term_id'),
+    ),
   );
+  return $schema;
+}
 
-  $schema['tripal_panel_fields'] = array(
-    'description' => 'The list of panels into which fields can be placed.',
-    'fields' => array(
-      'panel_field_id' => array(
-        'description' => 'The primary identifier for this table.',
+/**
+ *
+ *
+ * Specifies the predicates used for the semantic web for all properties of a bundle.
+ *
+ * Usage: When fields are added to an entity then there must be some “relationship” term 
+ * (i.e. predicate) that indicates the meaning of the relationship.  This predicate must 
+ * itself be a cvterm from a vocabulary.  For all fields that are automatically added to 
+ * bundles by tripal there should be a record here.  The site admin should be able to 
+ * change these if desired, but there should be some sort of default set by Tripal 
+ * itself.  This will require that all fields for all tables in Chado have some default 
+ * predicate value.  Also, relationship between two different bundles (whether published 
+ * or not) should also have a relationship predicate.  See the section in the 
+ * specification for how default predicates are set.
+ */
+function tripal_entities_tripal_term_relationship_schema() {
+
+  $schema = array (
+    'table' => 'tripal_term_relationship',
+    'fields' => array (
+      'relationship_id' => array(
         'type' => 'serial',
-        'unsigned' => TRUE,
-        'not null' => TRUE,
+        'not null' => TRUE
       ),
-      'panel_id' => array(
-        'description' => 'The primary identifier for this table.',
+      'subject_id' => array (
         'type' => 'int',
-        'not null' => TRUE,
+        'not null' => TRUE
       ),
-      'field_id' => array(
-        'description' => 'A bundle ID from the tripal_bundle table.',
+      'type_id' => array (
         'type' => 'int',
-        'not null' => TRUE,
+        'not null' => TRUE
       ),
+      'object_id' => array (
+        'type' => 'int',
+        'not null' => FALSE
+      ),
+      'fieldname' => array(
+        'type' => 'varchar',
+        'length' => 128,
+        'not null' => FALSE,
+      )
     ),
-    'indexes' => array(
-      'panel_id' => array('panel_id'),
-      'field_id' => array('field_id'),
-    ),
-    'unique keys' => array(
-      'panel_field' => array('panel_id', 'field_id'),
+    'primary key' => array (
+      0 => 'relationship_id'
     ),
-    'foreign keys' => array(
-      'tripal_panel' => array(
-        'table' => 'tripal_panel',
-        'columns' => array(
-          'panel_id' => 'panel_id',
+    'foreign keys' => array (
+      'tripal_term' => array (
+        'table' => 'tripal_term',
+        'columns' => array (
+          'subject_id' => 'term_id',
+          'object_id'  => 'term_id',
         ),
       ),
-      'field_config' => array(
-        'table' => 'field_config',
-        'columns' => array(
-          'field_id' => 'id',
-        ),
+    ),
+    'unique keys' => array (
+      'tripal_term_relationship_unq' => array (
+        'subject_id', 'type_id', 'object_id'
       ),
     ),
-    'primary key' => array('panel_field_id'),
+    'indexes' => array(
+      'tripal_term_relationship_subject_id' => array('subject_id'),
+      'tripal_term_relationship_object_id' => array('object_id'),
+      'tripal_term_relationship_type_id' => array('type_id'),
+    ),
   );
   return $schema;
 }
-/**
- * Implements hook_uninstall().
- *
- * At uninstall time we'll notify field.module that the entity was deleted
- * so that attached fields can be cleaned up.
- */
-function tripal_entities_uninstall() {
-  $terms = chado_generate_var('tripal_term', array('publish' => 1), array('return_array' => 1));
-  foreach ($terms as $term) {
-    $bundle_id = $term->cvterm_id->dbxref_id->db_id->name . '_' . $term->cvterm_id->dbxref_id->accession;
-    field_attach_delete_bundle('BioData', $bundle_id);
-  }
-}
-

+ 15 - 2
tripal_entities/tripal_entities.module

@@ -60,6 +60,7 @@ function tripal_entities_menu() {
 
 /**
  * Implements hook_admin_paths().
+ * Define administrative paths.
  */
 function tripal_entities_admin_paths() {
   if (variable_get('node_admin_theme')) {
@@ -72,11 +73,14 @@ function tripal_entities_admin_paths() {
     return $paths;
   }
 }
+
 /**
  * Implements hook_menu_local_tasks_alter().
+ * Used to add action links to pages.
  */
 function tripal_entities_menu_local_tasks_alter(&$data, $router_item, $root_path) {
-  // Add action link to 'BioData/add' on 'admin/content/BioData' page.
+
+  // Add an "Add Biological Data" action link to the Admin > Content > Biological Data page.
   if ($root_path == 'admin/content/BioData') {
     $item = menu_get_item('BioData/add');
     if ($item['access']) {
@@ -89,8 +93,15 @@ function tripal_entities_menu_local_tasks_alter(&$data, $router_item, $root_path
 }
 
 /**
+ * Implements hook_shortcut_default_set().
+ * Modify the shortcut menu to include Biological data links.
+ *
+ * @param object $account
+ *   The user account whose default shortcut set will be returned. If not provided, the 
+ *   function will return the currently logged-in user's default shortcut set.
  *
- * @param unknown $account
+ * @return
+ *   An object representing the default shortcut set.
  */
 function tripal_entities_shortcut_default_set($account) {
   $sets = shortcut_sets();
@@ -142,6 +153,7 @@ function tripal_entities_shortcut_default_set($account) {
  * Implements hook_permission().
  */
 function tripal_entities_permission() {
+
   // We set up permisssions to manage entity types, manage all entities and the
   // permissions for each individual entity
   $permissions = array(
@@ -154,6 +166,7 @@ function tripal_entities_permission() {
       'description' => t('Edit and delete all tripal data'),
     ),
   );
+  
   return $permissions;
 }