Ver Fonte

Dynamically generated the 'entity types' and 'bundles'.

Chun-Huai Cheng há 9 anos atrás
pai
commit
743bbfbcdb

+ 12 - 6
tripal_entities/includes/TripalDataUIController.inc

@@ -17,7 +17,7 @@ class TripalDataUIController extends EntityDefaultUIController {
     $plural_label = isset($this->entityInfo['plural label']) ? $this->entityInfo['plural label'] : $this->entityInfo['label'] . 's';
 
     $items[$this->path] = array(
-      'title' => $plural_label,
+      'title' => 'Biological Data',
       'page callback' => 'drupal_get_form',
       'page arguments' => array($this->entityType . '_overview_form', $this->entityType),
       'description' => 'Manage ' . $plural_label . '.',
@@ -212,6 +212,10 @@ function tripal_data_form($form, &$form_state, $entity = NULL) {
       '#type'  => 'hidden',
       '#value' => $cv_id,
     );
+    $form['entity_type'] = array(
+      '#type'  => 'hidden',
+      '#value' => $cvterm->dbxref_id->db_id->name,
+    );
     $form['term_name'] = array(
       '#type'  => 'hidden',
       '#value' => $term_name,
@@ -325,8 +329,8 @@ function tripal_data_form($form, &$form_state, $entity = NULL) {
 */
     // If the entity doesn't exist then create one.
     if (!$entity) {
-      $entity = entity_get_controller('tripal_data')->create(array('type' => $bundle_id));
-      field_attach_form('tripal_data', $entity, $form, $form_state);
+      $entity = entity_get_controller($cvterm->dbxref_id->db_id->name)->create(array('type' => $bundle_id));
+      field_attach_form($cvterm->dbxref_id->db_id->name, $entity, $form, $form_state);
 
       $form['submit'] = array(
         '#type' => 'submit',
@@ -336,7 +340,7 @@ function tripal_data_form($form, &$form_state, $entity = NULL) {
       );
     }
     else {
-      field_attach_form('tripal_data', $entity, $form, $form_state);
+      field_attach_form($cvterm->dbxref_id->db_id->name, $entity, $form, $form_state);
 
       $form['submit'] = array(
         '#type' => 'submit',
@@ -396,7 +400,9 @@ function tripal_data_form_submit($form, &$form_state) {
       $form_state['clicked_button']['#name'] == 'add_data') {
     // Use the Entity API to get the entity from the form state, then
     // attach the fields and save.
-    $entity = entity_ui_controller('tripal_data')->entityFormSubmitBuildEntity($form, $form_state);
+    $entity_type = $form_state['values']['entity_type'];
+    dpm($form_state);
+    $entity = entity_ui_controller($entity_type)->entityFormSubmitBuildEntity($form, $form_state);
     $entity->save();
     $form_state['redirect'] = "data/$entity->id";
   }
@@ -475,7 +481,7 @@ function tripal_data_set_breadcrumb() {
  * @see hook_entity_view_alter()
  */
 function tripal_data_view($entity, $view_mode = 'full') {
-  $controller = entity_get_controller('tripal_data');
+  $controller = entity_get_controller($entity->type);
   $content = $controller->view(array($entity->id => $entity));
   drupal_set_title($entity->title);
   return $content;

+ 83 - 121
tripal_entities/includes/tripal_entities.admin.inc

@@ -6,14 +6,15 @@
  * @ingroup tripal_feature
  */
 function tripal_entities_admin_view() {
-  $output = '';
+  
+  $output = drupal_render(drupal_get_form('tripal_entities_admin_data_types_form')) . "<br>[ Image Place Holder for Data Type Summary ]<br>";
 
   // set the breadcrumb
   $breadcrumb = array();
   $breadcrumb[] = l('Home', '<front>');
   $breadcrumb[] = l('Administration', 'admin');
   $breadcrumb[] = l('Tripal', 'admin/tripal');
-  $breadcrumb[] = l('Manage Data types', 'admin/tripal/data_types');
+  $breadcrumb[] = l('Biological Data', 'admin/tripal/data_types');
   drupal_set_breadcrumb($breadcrumb);
 
 /*   // Add the view
@@ -44,6 +45,78 @@ function tripal_entities_admin_view() {
   return $output;
 }
 
+/**
+ *
+ * @param unknown $form
+ * @param unknown $form_state
+ * @return multitype:
+ */
+function tripal_entities_admin_data_types_form($form, &$form_state) {
+  $form = array();
+
+  // Set the defaults.
+  $cv_id = NULL;
+  $term_name = NULL;
+
+  // Set defaults using the form state.
+  if (array_key_exists('values', $form_state)) {
+    $cv_id = array_key_exists('cv_id', $form_state['values']) ? $form_state['values']['cv_id'] : NULL;
+    $term_name = array_key_exists('term_name', $form_state['values']) ? $form_state['values']['term_name'] : NULL;
+  }
+
+  // Let the user select the vocabulary and tripal_data but only if they haven't
+  // already selected a tripal_data.
+  $sql = "
+    SELECT CV.cv_id, CV.name
+    FROM {cv} CV 
+    ORDER BY CV.name
+  ";
+  $vocabs = chado_query($sql);
+  $cvs = array();
+  while ($vocab = $vocabs->fetchObject()) {
+    $cvs[$vocab->cv_id] = $vocab->name;
+  }
+  $form['cv_id'] = array(
+    '#type' => 'select',
+    '#title' => t('Vocabulary'),
+    '#options' => $cvs,
+    '#required' => FALSE,
+    '#description' => t('Select a vocabulary to view potential data types in the chart below. Limit the chart to only published data types by selecting the checkbox.'),
+    '#default_value' => $cv_id,
+    '#ajax' => array(
+      'callback' => "tripal_entities_admin_data_types_form_ajax_callback",
+      'wrapper' => 'tripal_entities_admin_data_types_form',
+      'effect' => 'fade',
+      'method' => 'replace'
+    )
+  );
+
+  $form['refresh_data_types'] = array(
+    '#type' => 'submit',
+    '#value' => t('Refresh Data Types'),
+    '#submit' => array('tripal_entity_admin_data_types_form_submit_refresh_data_types'),
+  );
+  
+  $form['publish_new_data'] = array(
+    '#type' => 'submit',
+    '#value' => t('Publish New Data'),
+    '#submit' => array('tripal_entity_admin_data_types_form_submit_publish_new_data'),
+  );
+
+  $form['#prefix'] = '<div id="tripal_entities_admin_data_type_form">';
+  $form['#suffix'] = '</div>';
+  return $form;
+}
+
+/**
+ * Submit a job to populate the entity tables 
+ * This operation makes available data types in the database publishable
+ */
+function tripal_entity_admin_data_types_form_submit_refresh_data_types () {
+  global $user;
+  tripal_add_job('Create publishable data types', 'tripal_entity', 'tripal_entities_populate_entity_tables', array(), $user->uid);
+}
+
 /**
  *
  * @param unknown $form
@@ -67,7 +140,7 @@ function tripal_entities_admin_publish_form($form, &$form_state) {
   // already selected a tripal_data.
   $sql = "
     SELECT CV.cv_id, CV.name
-    FROM {tripal_entity_type} TET
+    FROM {tripal_vocabulary} TET
       INNER JOIN {cv} CV on CV.cv_id = TET.cv_id
     ORDER BY CV.name
   ";
@@ -143,7 +216,7 @@ function tripal_entities_admin_publish_form_validate($form, &$form_state) {
   $values = array(
     'cvterm_id' => $type->cvterm_id,
   );
-  $bundles = chado_select_record('tripal_entity_bundle', array('bundle_id'), $values);
+  $bundles = chado_select_record('tripal_term', array('term_id'), $values);
   if (count($bundles) == 0) {
     form_set_error('term_name', t("The data type, %type, is not associated with data on this site and thus cannot be set as publishable.", array('%type' => $term_name)));
   }
@@ -153,7 +226,7 @@ function tripal_entities_admin_publish_form_validate($form, &$form_state) {
     'cvterm_id' => $type->cvterm_id,
     'publish' => 1,
   );
-  $bundles = chado_select_record('tripal_entity_bundle', array('bundle_id'), $values);
+  $bundles = chado_select_record('tripal_term', array('term_id'), $values);
   if (count($bundles) > 0) {
     form_set_error('term_name', t("This data type is already set as publishable."));
   }
@@ -180,7 +253,7 @@ function tripal_entities_admin_publish_form_submit($form, &$form_state) {
     // Mark this entity as published.
     $match = array('cv_id' => $cv_id);
     $values = array('publish' => 1);
-    $success = chado_update_record('tripal_entity_type', $match, $values);
+    $success = chado_update_record('tripal_vocabulary', $match, $values);
     if (!$success) {
       throw new Exception('Cannot set the vocabulary as publishable');
     }
@@ -189,20 +262,20 @@ function tripal_entities_admin_publish_form_submit($form, &$form_state) {
     // as a bundle. So, if we're here we can enable it.
     $match = array('cvterm_id' => $type->cvterm_id);
     $values = array('publish' => 1);
-    $success = chado_update_record('tripal_entity_bundle', $match, $values);
+    $success = chado_update_record('tripal_term', $match, $values);
     if (!$success) {
       throw new Exception('Cannot set the data type as publishable');
     }
 
     // Get the bundle
-    $records = chado_select_record('tripal_entity_bundle', array('*'), $match);
+    $records = chado_select_record('tripal_term', array('*'), $match);
     $bundle = $records[0];
     $bundle_name = $type->dbxref_id->db_id->name . '_' . $type->dbxref_id->accession;
     $entity_type_name = $type->dbxref_id->db_id->name;
 
     // Get the list of tables where this cvterm is used.
-    $values = array('bundle_id' => $bundle->bundle_id);
-    $tables = chado_select_record('tripal_entity_bundle_source', array('*'), $values);
+    $values = array('term_id' => $bundle->term_id);
+    $tables = chado_select_record('tripal_term_usage', array('*'), $values);
 
     // Iterate through the tables.
     foreach ($tables as $table) {
@@ -392,114 +465,3 @@ function tripal_entities_admin_access_form($form, &$form_state) {
 
   return $form;
 }
-
-/**
- * This function populates the Tripal entity tables using existing
- * data in the database.
- */
-function tripal_entities_populate_entity_tables() {
-  // Get the cvterm table and look for all of the tables that link to it.
-  $schema = chado_get_schema('cvterm');
-  $referring = $schema['referring_tables'];
-
-  // Perform this action in a transaction
-  $transaction = db_transaction();
-  print "\nNOTE: Populating of tripal entity tables is performed using a database transaction. \n" .
-    "If the load fails or is terminated prematurely then the entire set of \n" .
-    "insertions/updates is rolled back and will not be found in the database\n\n";
-  try {
-
-    // Iterate through the referring tables to see what records are there.
-    foreach ($referring as $tablename) {
-
-      // We only want to look at base tables.
-      if ($tablename == 'cvterm_dbxref' || $tablename == 'cvterm_relationship' ||
-          $tablename == 'cvtermpath' || $tablename == 'cvtermprop' || $tablename == 'chadoprop' ||
-          $tablename == 'cvtermsynonym' || preg_match('/_relationship$/', $tablename) ||
-          preg_match('/_cvterm$/', $tablename)) {
-        continue;
-      }
-
-      print "Examining $tablename...\n";
-      $ref_schema = chado_get_schema($tablename);
-      $fkeys = $ref_schema['foreign keys'];
-      foreach ($fkeys['cvterm']['columns'] as $local_id => $remote_id) {
-
-        // Get the list of cvterm_ids from existing records in the table.
-        $sql = "
-          SELECT $local_id
-          FROM { " . $tablename . "}
-          GROUP BY $local_id
-        ";
-        $results = chado_query($sql);
-        while ($cvterm_id = $results->fetchField()) {
-
-          // Get the CV term details and add it to the tripal_entity_type table if
-          // it doesn't already exist.
-          $cvterm = chado_generate_var('cvterm', array('cvterm_id' => $cvterm_id));
-
-          // First add a record to the tripal_entity_type table.
-          $values = array(
-            'cv_id' => $cvterm->cv_id->cv_id,
-            'db_id' => $cvterm->dbxref_id->db_id->db_id,
-            'publish' => 0,
-          );
-          $entity_type_id = 0;
-          $entity_type = chado_select_record('tripal_entity_type', array('entity_type_id'), $values);
-          if (count($entity_type) == 0) {
-            $entity_type = chado_insert_record('tripal_entity_type', $values);
-            $entity_type_id = $entity_type['entity_type_id'];
-          }
-          else {
-            $entity_type_id = $entity_type[0]->entity_type_id;
-          }
-
-          // Next add a record to the tripal_entity_bundle table.
-          $values = array(
-            'entity_type_id' => $entity_type_id,
-            'cvterm_id' => $cvterm_id,
-            'publish' => 0
-          );
-          $bundle_id = 0;
-          $bundle = chado_select_record('tripal_entity_bundle', array('bundle_id'), $values);
-          if (count($bundle) == 0) {
-            $bundle = chado_insert_record('tripal_entity_bundle', $values);
-            $bundle_id = $bundle['bundle_id'];
-          }
-          else {
-            $bundle_id = $bundle[0]->bundle_id;
-          }
-
-          // Add the table where the records are found.
-          $values = array(
-            'bundle_id' => $bundle_id,
-            'data_table' => $tablename,
-            'type_table' => $tablename,
-            'field' => $local_id
-          );
-          if (!chado_select_record('tripal_entity_bundle_source', array('bundle_source_id'), $values, array('has_record' => TRUE))) {
-            chado_insert_record('tripal_entity_bundle_source', $values);
-          }
-
-          // Add the table where the records are found.
-          $values = array(
-            'entity_type_id' => $entity_type_id,
-            'data_table' => $tablename,
-            'type_table' => $tablename,
-            'field' => $local_id
-          );
-          if (!chado_select_record('tripal_entity_type_source', array('entity_type_id'), $values, array('has_record' => TRUE))) {
-            chado_insert_record('tripal_entity_type_source', $values);
-          }
-        }
-      }
-    }
-  }
-  catch (Exception $e) {
-    print "\n"; // make sure we start errors on new line
-    $transaction->rollback();
-    watchdog_exception('tripal_ws', $e);
-    print "FAILED: Rolling back database changes...\n";
-  }
-  print "\nDone.\n";
-}

+ 112 - 0
tripal_entities/includes/tripal_entities.tables.inc

@@ -0,0 +1,112 @@
+<?php 
+
+/**
+ * This function populates the Tripal entity tables using existing
+ * data in the database.
+ */
+function tripal_entities_populate_entity_tables() {
+  // Get the cvterm table and look for all of the tables that link to it.
+  $schema = chado_get_schema('cvterm');
+  $referring = $schema['referring_tables'];
+
+  // Perform this action in a transaction
+  $transaction = db_transaction();
+  print "\nNOTE: Populating of tripal entity tables is performed using a database transaction. \n" .
+      "If the load fails or is terminated prematurely then the entire set of \n" .
+      "insertions/updates is rolled back and will not be found in the database\n\n";
+  try {
+
+    // Iterate through the referring tables to see what records are there.
+    foreach ($referring as $tablename) {
+
+      // We only want to look at base tables.
+      if ($tablename == 'cvterm_dbxref' || $tablename == 'cvterm_relationship' ||
+          $tablename == 'cvtermpath' || $tablename == 'cvtermprop' || $tablename == 'chadoprop' ||
+          $tablename == 'cvtermsynonym' || preg_match('/_relationship$/', $tablename) ||
+          preg_match('/_cvterm$/', $tablename)) {
+            continue;
+          }
+
+          print "Examining $tablename...\n";
+          $ref_schema = chado_get_schema($tablename);
+          $fkeys = $ref_schema['foreign keys'];
+          foreach ($fkeys['cvterm']['columns'] as $local_id => $remote_id) {
+
+            // Get the list of cvterm_ids from existing records in the table.
+            $sql = "
+            SELECT $local_id
+            FROM { " . $tablename . "}
+            GROUP BY $local_id
+            ";
+            $results = chado_query($sql);
+            while ($cvterm_id = $results->fetchField()) {
+
+              // Get the CV term details and add it to the tripal_vocabulary table if
+              // it doesn't already exist.
+              $cvterm = chado_generate_var('cvterm', array('cvterm_id' => $cvterm_id));
+
+              // First add a record to the tripal_vocabulary table.
+              $values = array(
+                'cv_id' => $cvterm->cv_id->cv_id,
+                'db_id' => $cvterm->dbxref_id->db_id->db_id,
+                'publish' => 0,
+              );
+              $entity_type_id = 0;
+              $entity_type = chado_select_record('tripal_vocabulary', array('vocabulary_id'), $values);
+              if (count($entity_type) == 0) {
+                $entity_type = chado_insert_record('tripal_vocabulary', $values);
+                $entity_type_id = $entity_type['vocabulary_id'];
+              }
+              else {
+                $entity_type_id = $entity_type[0]->vocabulary_id;
+              }
+
+              // Next add a record to the tripal_term table.
+              $values = array(
+                'vocabulary_id' => $entity_type_id,
+                'cvterm_id' => $cvterm_id,
+                'publish' => 0
+              );
+              $bundle_id = 0;
+              $bundle = chado_select_record('tripal_term', array('term_id'), $values);
+              if (count($bundle) == 0) {
+                $bundle = chado_insert_record('tripal_term', $values);
+                $bundle_id = $bundle['term_id'];
+              }
+              else {
+                $bundle_id = $bundle[0]->term_id;
+              }
+
+              // Add the table where the records are found.
+              $values = array(
+                'term_id' => $bundle_id,
+                'data_table' => $tablename,
+                'type_table' => $tablename,
+                'field' => $local_id
+              );
+              if (!chado_select_record('tripal_term_usage', array('bundle_source_id'), $values, array('has_record' => TRUE))) {
+                chado_insert_record('tripal_term_usage', $values);
+              }
+
+              // Add the table where the records are found.
+              $values = array(
+                'vocabulary_id' => $entity_type_id,
+                'data_table' => $tablename,
+                'type_table' => $tablename,
+                'field' => $local_id
+              );
+              if (!chado_select_record('tripal_vocabulary_usage', array('vocabulary_id'), $values, array('has_record' => TRUE))) {
+                chado_insert_record('tripal_vocabulary_usage', $values);
+              }
+            }
+          }
+    }
+  }
+  catch (Exception $e) {
+    print "\n"; // make sure we start errors on new line
+    $transaction->rollback();
+    watchdog_exception('tripal_ws', $e);
+    print "FAILED: Rolling back database changes...\n";
+  }
+  print "\nDone.\n";
+}

+ 59 - 59
tripal_entities/tripal_entities.install

@@ -27,21 +27,21 @@ function tripal_entities_install() {
  *
  */
 function tripal_entities_add_custom_tables() {
-  tripal_entities_add_tripal_entity_type_table();
-  tripal_entities_add_tripal_entity_type_source_table();
-  tripal_entities_add_tripal_entity_bundle_table();
-  tripal_entities_add_tripal_entity_bundle_source_table();
-  tripal_entities_add_tripal_entity_relationship_table();
+  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_add_tripal_entity_type_table() {
+function tripal_entities_add_tripal_vocabulary_table() {
   $schema = array (
-    'table' => 'tripal_entity_type',
+    'table' => 'tripal_vocabulary',
     'fields' => array (
-      'entity_type_id' => array(
+      'vocabulary_id' => array(
         'type' => 'serial',
         'not null' => TRUE
       ),
@@ -60,7 +60,7 @@ function tripal_entities_add_tripal_entity_type_table() {
       ),
     ),
     'primary key' => array (
-      0 => 'entity_type_id'
+      0 => 'vocabulary_id'
     ),
     'foreign keys' => array (
       'cv' => array (
@@ -77,29 +77,29 @@ function tripal_entities_add_tripal_entity_type_table() {
       ),
     ),
     'unique keys' => array (
-      'tripal_entity_type_cvdb' => array (
+      'tripal_vocabulary_cvdb' => array (
         'cv_id', 'db_id'
       ),
     ),
     'indexes' => array(
-      'tripal_entity_type_cv_id' => array('cv_id'),
-      'tripal_entity_type_db_id' => array('db_id'),
+      'tripal_vocabulary_cv_id' => array('cv_id'),
+      'tripal_vocabulary_db_id' => array('db_id'),
     )
   );
-  chado_create_custom_table('tripal_entity_type', $schema, TRUE);
+  chado_create_custom_table('tripal_vocabulary', $schema, TRUE);
 }
 /**
  *
  */
-function tripal_entities_add_tripal_entity_bundle_table() {
+function tripal_entities_add_tripal_term_table() {
   $schema = array (
-    'table' => 'tripal_entity_bundle',
+    'table' => 'tripal_term',
     'fields' => array (
-      'bundle_id' => array(
+      'term_id' => array(
         'type' => 'serial',
         'not null' => TRUE
       ),
-      'entity_type_id' => array (
+      'vocabulary_id' => array (
         'type' => 'int',
         'not null' => TRUE
       ),
@@ -114,7 +114,7 @@ function tripal_entities_add_tripal_entity_bundle_table() {
       ),
     ),
     'primary key' => array (
-      0 => 'bundle_id'
+      0 => 'term_id'
     ),
     'foreign keys' => array (
       'cvterm' => array (
@@ -123,37 +123,37 @@ function tripal_entities_add_tripal_entity_bundle_table() {
           'cvterm_id' => 'cvterm_id'
         )
       ),
-      'tripal_entity_type' => array (
-        'table' => 'tripal_entity_type',
+      'tripal_vocabulary' => array (
+        'table' => 'tripal_vocabulary',
         'columns' => array (
-          'entity_type_id' => 'entity_type_id'
+          'vocabulary_id' => 'vocabulary_id'
         )
       ),
     ),
     'unique keys' => array (
-      'tripal_entity_bundle_unq' => array (
-        'entity_type_id', 'cvterm_id'
+      'tripal_term_unq' => array (
+        'vocabulary_id', 'cvterm_id'
       ),
     ),
     'indexes' => array(
-      'tripal_entity_bundle_entity_type_id' => array('entity_type_id'),
-      'tripal_entity_bundle_cvterm_id' => array('cvterm_id'),
+      'tripal_term_vocabulary_id' => array('vocabulary_id'),
+      'tripal_term_cvterm_id' => array('cvterm_id'),
     ),
   );
-  chado_create_custom_table('tripal_entity_bundle', $schema, TRUE);
+  chado_create_custom_table('tripal_term', $schema, TRUE);
 }
 /**
  *
  */
-function tripal_entities_add_tripal_entity_type_source_table(){
+function tripal_entities_add_tripal_vocabulary_usage_table(){
   $schema = array (
-    'table' => 'tripal_entity_type_source',
+    'table' => 'tripal_vocabulary_usage',
     'fields' => array (
       'entity_type_source_id' => array(
         'type' => 'serial',
         'not null' => TRUE
       ),
-      'entity_type_id' => array (
+      'vocabulary_id' => array (
         'type' => 'int',
         'not null' => TRUE
       ),
@@ -177,38 +177,38 @@ function tripal_entities_add_tripal_entity_type_source_table(){
       0 => 'entity_type_source_id'
     ),
     'foreign keys' => array (
-      'tripal_entity_type' => array (
-        'table' => 'tripal_entity_type',
+      'tripal_vocabulary' => array (
+        'table' => 'tripal_vocabulary',
         'columns' => array (
-          'entity_type_id' => 'entity_type_id'
+          'vocabulary_id' => 'vocabulary_id'
         ),
       ),
     ),
     'unique keys' => array (
-      'tripal_entity_type_ridbase' => array (
-        'entity_type_id', 'data_table'
+      'tripal_vocabulary_ridbase' => array (
+        'vocabulary_id', 'data_table'
       ),
     ),
     'indexes' => array(
-      'tripal_entity_type_entity_type_id' => array('entity_type_id'),
-      'tripal_entity_type_data_table' => array('data_table'),
-      'tripal_entity_type_type_table' => array('type_table'),
+      'tripal_vocabulary_vocabulary_id' => array('vocabulary_id'),
+      'tripal_vocabulary_data_table' => array('data_table'),
+      'tripal_vocabulary_type_table' => array('type_table'),
     ),
   );
-  chado_create_custom_table('tripal_entity_type_source', $schema, TRUE);
+  chado_create_custom_table('tripal_vocabulary_usage', $schema, TRUE);
 }
 /**
  *
  */
-function tripal_entities_add_tripal_entity_bundle_source_table(){
+function tripal_entities_add_tripal_term_usage_table(){
   $schema = array (
-    'table' => 'tripal_entity_bundle_source',
+    'table' => 'tripal_term_usage',
     'fields' => array (
       'bundle_source_id' => array(
         'type' => 'serial',
         'not null' => TRUE
       ),
-      'bundle_id' => array (
+      'term_id' => array (
         'type' => 'int',
         'not null' => TRUE
       ),
@@ -232,30 +232,30 @@ function tripal_entities_add_tripal_entity_bundle_source_table(){
       0 => 'bundle_source_id'
     ),
     'foreign keys' => array (
-      'tripal_entity_bundle' => array (
-        'table' => 'tripal_entity_bundle',
+      'tripal_term' => array (
+        'table' => 'tripal_term',
         'columns' => array (
-          'bundle_id' => 'bundle_id'
+          'term_id' => 'term_id'
         ),
       ),
     ),
     'unique keys' => array (
-      'tripal_entity_bundle_source_ridbase' => array (
-        'bundle_id', 'type_table', 'field'
+      'tripal_term_usage_ridbase' => array (
+        'term_id', 'type_table', 'field'
       ),
     ),
     'indexes' => array(
-      'tripal_entity_bundle_source_bundle_id' => array('bundle_id'),
+      'tripal_term_usage_term_id' => array('term_id'),
     ),
   );
-  chado_create_custom_table('tripal_entity_bundle_source', $schema, TRUE);
+  chado_create_custom_table('tripal_term_usage', $schema, TRUE);
 }
 /**
  *
  */
-function tripal_entities_add_tripal_entity_relationship_table(){
+function tripal_entities_add_tripal_term_relationship_table(){
   $schema = array (
-    'table' => 'tripal_entity_relationship',
+    'table' => 'tripal_term_relationship',
     'fields' => array (
       'relationship_id' => array(
         'type' => 'serial',
@@ -283,26 +283,26 @@ function tripal_entities_add_tripal_entity_relationship_table(){
       0 => 'relationship_id'
     ),
     'foreign keys' => array (
-      'tripal_entity_bundle' => array (
-        'table' => 'tripal_entity_bundle',
+      'tripal_term' => array (
+        'table' => 'tripal_term',
         'columns' => array (
-          'subject_id' => 'bundle_id',
-          'object_id'  => 'bundle_id',
+          'subject_id' => 'term_id',
+          'object_id'  => 'term_id',
         ),
       ),
     ),
     'unique keys' => array (
-      'tripal_entity_relationship_unq' => array (
+      'tripal_term_relationship_unq' => array (
         'subject_id', 'type_id', 'object_id'
       ),
     ),
     'indexes' => array(
-      'tripal_entity_relationship_subject_id' => array('subject_id'),
-      'tripal_entity_relationship_object_id' => array('object_id'),
-      'tripal_entity_relationship_type_id' => array('type_id'),
+      '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_entity_relationship', $schema, TRUE);
+  chado_create_custom_table('tripal_term_relationship', $schema, TRUE);
 }
 /**
  * Implements hook_schema().

+ 125 - 111
tripal_entities/tripal_entities.module

@@ -3,6 +3,7 @@
 require_once "api/tripal_entities.api.inc";
 require_once "includes/tripal_entities.field_storage.inc";
 require_once "includes/tripal_entities.fields.inc";
+require_once "includes/tripal_entities.tables.inc";
 require_once "includes/TripalData.inc";
 require_once "includes/TripalDataController.inc";
 require_once "includes/TripalDataUIController.inc";
@@ -27,14 +28,21 @@ function tripal_entities_menu() {
   $items = array();
   // the administative settings menu
   $items['admin/tripal/data_types'] = array(
-    'title' => 'Manage Data Types',
+    'title' => 'Biological Data',
     'description' => 'Tools for publishing, configurating and managing biological data.',
     'page callback' => 'tripal_entities_admin_view',
     'access arguments' => array('administer tripal data types'),
     'file' =>  'includes/tripal_entities.admin.inc',
     'type' => MENU_NORMAL_ITEM,
   );
-
+  
+  // the default tab
+  $items['admin/tripal/data_types/default'] = array(
+    'title' => 'Biological Data',
+    'type' => MENU_DEFAULT_LOCAL_TASK,
+    'weight' =>  1,
+  );
+  
   $items['admin/tripal/data_types/publish'] = array(
     'title' => 'Publish',
     'description' => 'Publish Data',
@@ -144,95 +152,100 @@ function tripal_entities_rdf_mapping() {
 function tripal_entities_entity_info() {
   $entities = array();
 
-  $entities['tripal_data'] = array(
-    // A human readable label to identify our entity.
-    'label' => t('Tripal Data'),
-    'plural label' => t('Tripal Data'),
-
-    // The entity class and controller class extend the classes provided by the
-    // Entity API.
-    'entity class' => 'TripalData',
-    'controller class' => 'TripalDataController',
-
-    // The table for this entity defined in hook_schema()
-    'base table' => 'tripal_data',
-
-    // Returns the uri elements of an entity.
-    'uri callback' => 'tripal_entities_vocbulary_term_uri',
-
-    // IF fieldable == FALSE, we can't attach fields.
-    'fieldable' => TRUE,
-
-    // entity_keys tells the controller what database fields are used for key
-    // functions. It is not required if we don't have bundles or revisions.
-    // Here we do not support a revision, so that entity key is omitted.
-    'entity keys' => array(
-      'id' => 'id',
-      'bundle' => 'type',
-    ),
-    'bundle keys' => array(
-      'bundle' => 'type',
-    ),
-
-    // Callback function for access to this entity.
-    'access callback' => 'tripal_data_access',
-
-    // FALSE disables caching. Caching functionality is handled by Drupal core.
-    'static cache' => FALSE,
-
-    // Bundles are added in the hook_entities_info_alter() function.
-    'bundles' => array(),
-
-    'label callback' => 'entity_class_label',
-    'creation callback' => 'tripal_data_create',
-
-    // The information below is used by the TripalDataUIController
-    // (which extends the EntityDefaultUIController).  The admin_ui
-    // key here is mean to appear on the 'Find Content' page of the
-    // administrative menu.
-    'admin ui' => array(
-      'path' => 'admin/content/data',
-      'controller class' => 'TripalDataUIController',
-      'menu wildcard' => '%tripal_data',
-      'file' => 'includes/TripalDataUIController.inc',
-    ),
-    'view modes' => array(
-      'full' => array(
-        'label' => t('Full content'),
-        'custom settings' => FALSE,
+  // Get a list of published vocabularies from 'tripal_vocabulary
+  $published_vocs = chado_generate_var('tripal_vocabulary', array('publish' => 1), array('return_array' => 1));
+  
+  foreach ($published_vocs as $voc) {
+    $entities [$voc->db_id->name] = array (
+      // A human readable label to identify our entity.
+      'label' => $voc->db_id->name . ' (' . $voc->cv_id->name . ')',
+      'plural label' => $voc->db_id->name . ' (' . $voc->cv_id->name . ')',
+      
+      // The entity class and controller class extend the classes provided by the
+      // Entity API.
+      'entity class' => 'TripalData',
+      'controller class' => 'TripalDataController',
+      
+      // The table for this entity defined in hook_schema()
+      'base table' => 'tripal_data',
+      
+      // Returns the uri elements of an entity.
+      'uri callback' => 'tripal_entities_vocbulary_term_uri',
+      
+      // IF fieldable == FALSE, we can't attach fields.
+      'fieldable' => TRUE,
+      
+      // entity_keys tells the controller what database fields are used for key
+      // functions. It is not required if we don't have bundles or revisions.
+      // Here we do not support a revision, so that entity key is omitted.
+      'entity keys' => array (
+        'id' => 'id',
+        'bundle' => 'type' 
       ),
-      'teaser' => array(
-        'label' => t('Teaser'),
-        'custom settings' => TRUE,
+      'bundle keys' => array (
+        'bundle' => 'type' 
       ),
-    ),
-  );
-
-  // The entity that holds information about the entity types
-  $entities['tripal_data_type'] = array(
-    'label' => t('Tripal Data Type'),
-    'entity class' => 'TripalDataType',
-    'controller class' => 'TripalDataTypeController',
-    'base table' => 'tripal_data_type',
-    'fieldable' => FALSE,
-    // If this entity can be used as a bundle of another entity then
-    // that can be specified via the 'bundle of' key.
-    'bundle of' => 'tripal_data',
-    'exportable' => TRUE,
-    'entity keys' => array(
-      'id' => 'id',
-      'name' => 'type',
-      'label' => 'label',
-    ),
-    'access callback' => 'tripal_data_type_access',
-    'module' => 'tripal_entities',
-    // Enable the entity API's admin UI.
-    'admin ui' => array(
-      'path' => 'admin/structure/data_types',
-      'controller class' => 'TripalDataTypeUIController',
-      'file' => 'includes/TripalDataTypeUIController.inc',
-    ),
-  );
+      
+      // Callback function for access to this entity.
+      'access callback' => 'tripal_data_access',
+      
+      // FALSE disables caching. Caching functionality is handled by Drupal core.
+      'static cache' => FALSE,
+      
+      // Bundles are added in the hook_entities_info_alter() function.
+      'bundles' => array (),
+      
+      'label callback' => 'tripal_data_label',
+      'creation callback' => 'tripal_data_create',
+      
+      // The information below is used by the TripalDataUIController
+      // (which extends the EntityDefaultUIController). The admin_ui
+      // key here is mean to appear on the 'Find Content' page of the
+      // administrative menu.
+      'admin ui' => array (
+        'path' => 'admin/content/data',
+        'controller class' => 'TripalDataUIController',
+        'menu wildcard' => '%tripal_data',
+        'file' => 'includes/TripalDataUIController.inc' 
+      ),
+      'view modes' => array (
+        'full' => array (
+          'label' => t ( 'Full content' ),
+          'custom settings' => FALSE 
+        ),
+        'teaser' => array (
+          'label' => t ( 'Teaser' ),
+          'custom settings' => TRUE 
+        ) 
+      ) 
+    );
+    
+    // The entity that holds information about the entity types
+    $entities [$voc->db_id->name . '_type'] = array (
+      'label' => t ($voc->db_id->name . ' (' . $voc->cv_id->name . ')' . ' Type' ),
+      'entity class' => 'TripalDataType',
+      'controller class' => 'TripalDataTypeController',
+      'base table' => 'tripal_data_type',
+      'fieldable' => FALSE,
+      // If this entity can be used as a bundle of another entity then
+      // that can be specified via the 'bundle of' key.
+      'bundle of' => $voc->db_id->name,
+      'exportable' => TRUE,
+      'entity keys' => array (
+        'id' => 'id',
+        'name' => 'type',
+        'label' => 'label' 
+      ),
+      'access callback' => 'tripal_data_type_access',
+      'module' => 'tripal_entities',
+      // Enable the entity API's admin UI.
+      'admin ui' => array (
+        'path' => 'admin/structure/data_types',
+        'controller class' => 'TripalDataTypeUIController',
+        'file' => 'includes/TripalDataTypeUIController.inc' 
+      ) 
+    );
+  }
   return $entities;
 }
 /**
@@ -243,26 +256,27 @@ function tripal_entities_entity_info() {
  *
  */
 function tripal_entities_entity_info_alter(&$entity_info) {
-
-  // Bundles are alternative groups of fields or configuration
-  // associated with a base entity type.
-  // We want to dynamically add the bundles (or term types) to the entity.
-  $values = array(
-    'cv_id' => array(
-      'name' => 'sequence'
-    ),
-    'name' => 'gene',
-  );
-  $cvterm = chado_generate_var('cvterm', $values);
-  $label = preg_replace('/_/', ' ', ucwords($cvterm->name));
-  $type = $cvterm->dbxref_id->db_id->name . '_' . $cvterm->dbxref_id->accession;
-  $entity_info['tripal_data']['bundles'][$type] = array(
-    'label' => $label,
-    'admin' => array(
-      'path' => 'admin/structure/data_types/manage/%tripal_data_type',
-      'real path' => 'admin/structure/data_types/manage/' . $type,
-      'bundle argument' => 4,
-      'access arguments' => array('administer tripal data types'),
-    ),
-  );
+  
+  // Get a list of published terms from 'tripal_term
+  $published_terms = chado_generate_var('tripal_term', array('publish' => 1), array('return_array' => 1));
+  foreach ( $published_terms as $term ) {
+    
+    // Bundles are alternative groups of fields or configuration
+    // associated with a base entity type.
+    // We want to dynamically add the bundles (or term types) to the entity.
+    $cvterm = $term->cvterm_id;
+    $bundle_id = $cvterm->dbxref_id->db_id->name . '_' . $cvterm->dbxref_id->accession;
+    $label = preg_replace ( '/_/', ' ', ucwords ( $cvterm->name ) );
+    $entity_info [$cvterm->dbxref_id->db_id->name] ['bundles'] [$bundle_id] = array (
+      'label' => $label,
+      'admin' => array (
+        'path' => 'admin/structure/data_types/manage/%tripal_data_type',
+        'real path' => 'admin/structure/data_types/manage/' . $bundle_id,
+        'bundle argument' => 4,
+        'access arguments' => array (
+          'administer tripal data types' 
+        ) 
+      ) 
+    );
+  }
 }

+ 7 - 7
tripal_organism/theme/templates/tripal_organism_base.tpl.php

@@ -1,11 +1,11 @@
 <?php
 
-$cv = entity_load('trp_vocabulary', array(20, 21, 22));
-$cvterm = entity_load('trp_vocabulary_term', array(489, 44099, 45222, 527));
-$gene = entity_load('trp_SO_0000704', array(3));
-dpm($cv);
-dpm($cvterm);
-dpm($gene);
+//$cv = entity_load('trp_vocabulary', array(20, 21, 22));
+//$cvterm = entity_load('trp_vocabulary_term', array(489, 44099, 45222, 527));
+//$gene = entity_load('trp_SO_0000704', array(3));
+//dpm($cv);
+//dpm($cvterm);
+//dpm($gene);
 
 $organism  = $variables['node']->organism;
 $organism = chado_expand_var($organism,'field','organism.comment'); ?>
@@ -105,4 +105,4 @@ $table = array(
 // once we have our table array structure defined, we call Drupal's theme_table()
 // function to generate the table.
 print theme_table($table); ?>
-<div style="text-align: justify"><?php print $image . $organism->comment?></div>
+<div style="text-align: justify"><?php print $image . $organism->comment?></div>