Răsfoiți Sursa

Removed the tripal_term/vocabulary tables as they aren't needed for entities

Stephen Ficklin 9 ani în urmă
părinte
comite
73d6c14376

+ 45 - 160
tripal_entities/api/tripal_entities.api.inc

@@ -55,13 +55,6 @@ function chado_get_entity_title($entity) {
 /**
  * Creates a new Tripal Entity type (i.e. bundle).
  *
- * An entity is created by first adding a record to the tripal_term and
- * tripal_vocabulary tables.  This helps Tripal keep track of which terms
- * are used in which tables.  Second, records are added to the tripal_bundle
- * table which is where Tripal keeps track of all of the entity_types. Finally,
- * the hook_add_bundle_fields() is called that allows other modules to
- * add fields to the entity.
- *
  * @param $cvterm
  *  A cvterm object created using the chado_generate_var() function.
  * @param $error
@@ -73,118 +66,60 @@ function chado_get_entity_title($entity) {
  */
 function tripal_create_entity_type($cvterm, &$error = '') {
 
-  // Before creating the entity we must add records to the tripal_vocabulary
-  // tripal_vocabulary_usage, tripal_term, and tripal_term_usage tables.
-  $match = array('cv_id' => $cvterm->cv_id->cv_id);
-  $vocab = chado_select_record('tripal_vocabulary', array('*'), $match);
-  if (count($vocab) == 0) {
-    $values = array(
-      'cv_id' => $cvterm->cv_id->cv_id,
-      'db_id' => $cvterm->dbxref_id->db_id->db_id,
-      'publish' => 1,
-    );
-    $values = chado_insert_record('tripal_vocabulary', $values);
-    if (!$values) {
-      $error = 'Could not add vocabulary to tripal_vocabluary table.';
-      return FALSE;
-    }
-    // Convert the values array into an object.
-    $vocab = new stdClass();
-    $vocab->vocabulary_id = $values['vocabulary_id'];
-    $vocab->cv_id = $values['cv_id'];
-  }
-  else {
-    // Make sure the vocabulary is set to publish
-    $values = array('publish' => 1);
-    chado_update_record('tripal_vocabulary', $match, $values);
-    $vocab = $vocab[0];
-  }
+  // Create the bundle name and entity type name.  The bundle name is the
+  // cvterm ID.  This isn't very human readable, but the alternative is to
+  // use the accession which may not always be alpha-numeric.
+  $bundle_id = 'bio-data_' . $cvterm->cvterm_id;
 
   // The organism table does not have a type_id so we won't ever find
   // a record for it in the tripal_cv_defaults table.
+  $bundle_data = array();
   if ($cvterm->name == 'organism') {
-    $values = array(
-      'vocabulary_id' => $vocab->vocabulary_id,
+    $bundle_data = array(
+      'cv_id' => $cvterm->cv_id->cv_id,
+      'cvterm_id' => $cvterm->cvterm_id,
       'data_table' => 'organism',
       'type_table' => 'organism',
       'field' =>  '',
     );
-    $vocab_usage = chado_select_record('tripal_vocabulary_usage', array('*'), $values);
-    if (count($vocab_usage) == 0) {
-      $values = chado_insert_record('tripal_vocabulary_usage', $values);
-      if (!$values) {
-        $error = 'Could not add vocabulary to tripal_vocabulary_usage table.';
-        return FALSE;
-      }
-      $vocab_usage = new stdClass();
-      $vocab_usage->vocabulary_id = $values['vocabulary_id'];
-      $vocab_usage->data_table = $values['data_table'];
-      $vocab_usage->type_table = $values['type_table'];
-      $vocab_usage->field = $values['field'];
-    }
-    else {
-      $vocab_usage = (object) $values;
-    }
   }
   // The analysis table does not have a type_id so we won't ever find
   // a record for it in the tripalcv_defaults table.
   else if ($cvterm->name == 'analysis') {
-    $values = array(
-      'vocabulary_id' => $vocab->vocabulary_id,
+    $bundle_data = array(
+      'cv_id' => $cvterm->cv_id->cv_id,
+      'cvterm_id' => $cvterm->cvterm_id,
       'data_table' => 'analysis',
       'type_table' => 'analysis',
       'field' =>  '',
     );
-    $vocab_usage = chado_select_record('tripal_vocabulary_usage', array('*'), $values);
-    if (count($vocab_usage) == 0) {
-      $values = chado_insert_record('tripal_vocabulary_usage', $values);
-      if (!$values) {
-        $error = 'Could not add vocabulary to tripal_vocabulary_usage table.';
-        return FALSE;
-      }
-      $vocab_usage = new stdClass();
-      $vocab_usage->vocabulary_id = $values['vocabulary_id'];
-      $vocab_usage->data_table = $values['data_table'];
-      $vocab_usage->type_table = $values['type_table'];
-      $vocab_usage->field = $values['field'];
-    }
-    else {
-      $vocab_usage = (object) $values;
-    }
+  }
+  else if ($cvterm->name == 'project') {
+    $bundle_data = array(
+      'cv_id' => $cvterm->cv_id->cv_id,
+      'cvterm_id' => $cvterm->cvterm_id,
+      'data_table' => 'project',
+      'type_table' => 'project',
+      'field' =>  '',
+    );
   }
   else {
     // TODO: WHAT TO DO IF A VOCABULARY IS USED AS A DEFAULT FOR MULTIPLE
     // TABLES.
-    // Look to see if this vocabulary is used as a default for any table. If
-    // so then we can use that to populate the tripal_vocabulary_usage table.
+    // Look to see if this vocabulary is used as a default for any table.
     $default = db_select('tripal_cv_defaults', 't')
       ->fields('t')
-      ->condition('cv_id', $vocab->cv_id)
+      ->condition('cv_id', $cvterm->cv_id->cv_id)
       ->execute()
       ->fetchObject();
     if ($default) {
-      $values = array(
-        'vocabulary_id' => $vocab->vocabulary_id,
+      $bundle_data = array(
+        'cv_id' => $cvterm->cv_id->cv_id,
+        'cvterm_id' => $cvterm->cvterm_id,
         'data_table' => $default->table_name,
         'type_table' => $default->table_name,
         'field' =>  $default->field_name,
       );
-      $vocab_usage = chado_select_record('tripal_vocabulary_usage', array('*'), $values);
-      if (count($vocab_usage) == 0) {
-        $values = chado_insert_record('tripal_vocabulary_usage', $values);
-        if (!$values) {
-          $error = 'Could not add vocabulary to tripal_vocabulary_usage table.';
-          return FALSE;
-        }
-        $vocab_usage = new stdClass();
-        $vocab_usage->vocabulary_id = $values['vocabulary_id'];
-        $vocab_usage->data_table = $values['data_table'];
-        $vocab_usage->type_table = $values['type_table'];
-        $vocab_usage->field = $values['field'];
-      }
-      else {
-        $vocab_usage = (object) $values;
-      }
     }
     // If there is no default table then we have an error, and we should
     // set a variable so that the form can help the user deal with the problem.
@@ -196,85 +131,35 @@ function tripal_create_entity_type($cvterm, &$error = '') {
     }
   }
 
-  // Now add the tripal_term record if it doesn't already exist.
-  $match = array(
-    'vocabulary_id' => $vocab->vocabulary_id,
-    'cvterm_id' => $cvterm->cvterm_id,
-  );
-  $term = chado_select_record('tripal_term', array('*'), $match);
-  if (count($term) == 0) {
-    $values = array(
-      'vocabulary_id' => $vocab->vocabulary_id,
-      'cvterm_id' => $cvterm->cvterm_id,
-      'publish' => 1
-    );
-    $values = chado_insert_record('tripal_term', $values);
-    if (!$values) {
-      $error =  'Could not add term to tripal_term table.';
-      return FALSE;
-    }
-    $term = new stdClass();
-    $term->term_id = $values['term_id'];
-  }
-  else {
-    $values = array('publish' => 1);
-    chado_update_record('tripal_term', $match, $values);
-    $term = $term[0];
-  }
-
-  // Finally, add the tripal_term_usage record if it doesn't already exist.
-  $match = array('term_id' => $term->term_id);
-  $options = array('has_record' => TRUE);
-  if (!chado_select_record('tripal_term_usage', array('*'), $match, $options)) {
-    $values = array(
-      'term_id' => $term->term_id,
-      'data_table' => $vocab_usage->data_table,
-      'type_table' => $vocab_usage->type_table,
-      'field' =>  $vocab_usage->field,
-    );
-    $values = chado_insert_record('tripal_term_usage', $values);
-    if (!$values) {
-      $error = 'Could not add term to tripal_term table.';
-      return FALSE;
-    }
-  }
-
-  // Clear the entity cache so that Drupal will read our
-  // hook_entity_info() implementation which now will have the entities
-  // described because we set the publish column to 1 in the tripal_term
-  // table.
-  global $language;
-  $langcode = $language->language;
-  cache_clear_all("entity_info:$langcode", 'cache');
-
-  // Create the bundle name and entity type name.  The bundle name is the
-  // dbxref ID.  This isn't very human readable, but the alternative is to
-  // use the accession which may not always be alpha-numeric.
-  $bundle_name = 'dbxref_' . $cvterm->dbxref_id->dbxref_id;
-
   // Check to see if this bundle exists. If not then create it
   $bundle = db_select('tripal_bundle', 't')
     ->fields('t')
-    ->condition('type', 'BioData')
-    ->condition('bundle', $bundle_name)
+    ->condition('type', 'TripalEntity')
+    ->condition('bundle', $bundle_id)
     ->execute()
     ->fetchObject();
 
   if (!$bundle) {
-    // The TripalBundle Entity manages the bundles we have available.
-    // Therefore, we need to add a new entity for each bundle "type".
-    $vals = array(
-      'label' => $cvterm->name,
-      'type' => 'BioData',
-      'bundle' => $bundle_name,
-      'data' => serialize(array()),
-      'module' => 'tripal_entities'
-    );
-    $tripal_bundle = new TripalBundle($vals, 'BioData_bundles');
-    $tripal_bundle->save();
+    db_insert('tripal_bundle')
+      ->fields(array(
+        'label' => $cvterm->name,
+        'type' => 'TripalEntity',
+        'bundle' => $bundle_id,
+        'data' => serialize($bundle_data),
+        'module' => 'tripal_entities'
+      ))
+      ->execute();
   }
+
+  // Clear the entity cache so that Drupal will read our
+  // hook_entity_info() implementation.
+  global $language;
+  $langcode = $language->language;
+  cache_clear_all("entity_info:$langcode", 'cache');
+  variable_set('menu_rebuild_needed', TRUE);
+
   // Allow modules to now add fields to the bundle
-  module_invoke_all('add_bundle_fields', 'BioData', $bundle_name, $cvterm);
+  module_invoke_all('add_bundle_fields', 'TripalEntity', $bundle_id, $cvterm);
 
   return TRUE;
 }

+ 6 - 5
tripal_entities/includes/TripalBundleUIController.inc

@@ -18,15 +18,15 @@ class TripalBundleUIController extends EntityDefaultUIController {
    */
   public function hook_menu() {
     $items = parent::hook_menu();
-    $items[$this->path]['description'] = 'Manage Tripal data types, including adding
-      and removing fields and the display of fields.';
+    $items[$this->path]['description'] = 'Manage biological content types that are
+      added using Tripal.';
 
     // We don't want to let the user import new Tripal data types.
     unset($items[$this->path . '/import']);
 
     $items[$this->path . '/add'] = array(
-      'title' => 'Add Biological Data Type',
-      'description' => 'Add new biological data type',
+      'title' => 'Add new tripal content type',
+      'description' => 'Add new biological content',
       'page callback' => 'drupal_get_form',
       'page arguments' => array('tripal_entities_admin_add_type_form'),
       'access arguments' => array('administer tripal data types'),
@@ -65,7 +65,8 @@ function tripal_entities_tripal_bundle_form($form, &$form_state, $entityDataType
   $form = array();
   $form['message'] = array(
     '#type' => 'item',
-    '#markup' => 'Edit the function "tripal_entities_tripal_bundle_form()" to add a form each type. Put access controls here?',
+    '#markup' => 'Edit the function "tripal_entities_tripal_bundle_form()" ' .
+      'to add a form each type. Put access controls here?',
   );
   return $form;
 }

+ 11 - 21
tripal_entities/includes/TripalEntity.inc

@@ -5,6 +5,16 @@
 class TripalEntity extends Entity {
   public function __construct($values = array(), $entity_type) {
     parent::__construct($values, $entity_type);
+    $bundle_id = $this->bundle;
+    $bundle = db_select('tripal_bundle', 'tb')
+      ->fields('tb')
+      ->condition('bundle', $bundle_id)
+      ->execute()
+      ->fetchObject();
+
+    $data = unserialize($bundle->data);
+    $this->chado_table = $data['data_table'];
+    $this->chado_field = $data['field'];
 
     // If we have an ID then this entity has been saved and it will
     // also therefore have a chado_entity record.  We want to
@@ -19,8 +29,6 @@ class TripalEntity extends Entity {
       // Add the chado entity details to the entity in case it's needed
       // downstream (e.g. in field widget construction).
       $this->chado_entity_id = $details->chado_entity_id;
-      $this->chado_table = $details->data_table;
-      $this->chado_field = $details->field;
 
       // Add in the record.
       $schema = chado_get_schema($this->chado_table);
@@ -28,24 +36,6 @@ class TripalEntity extends Entity {
       $this->chado_record_id = $details->record_id;
       $this->chado_record = chado_generate_var($this->chado_table, array($pkey =>+ $details->record_id));
     }
-    // If we do not have an ID then we need to do a few queries to get
-    // information about the chado table this entity maps to.
-    else {
-      // Use the cvterm_id to look up the base table for this term.  We find
-      // the base table by looking in the term_usage table for the mapping.
-      $sel_values = array(
-        'term_id' => array(
-          'cvterm_id' => $this->cvterm_id,
-        ),
-      );
-      $term_usage = chado_generate_var('tripal_term_usage', $sel_values, array('return_array' => 1));
-
-      // For each table that uses this term, insert the field recursively
-      foreach ($term_usage as $usage) {
-        $this->chado_table = $usage->data_table;
-        $this->chado_field = $usage->field;
-      }
-    }
   }
 
   protected function defaultLabel() {
@@ -53,7 +43,7 @@ class TripalEntity extends Entity {
   }
 
   protected function defaultUri() {
-    return array('path' => 'BioData/' . $this->id);
+    return array('path' => 'TripalEntity/' . $this->id);
   }
 
 }

+ 7 - 7
tripal_entities/includes/TripalEntityController.inc

@@ -35,12 +35,12 @@ class TripalEntityController extends EntityAPIController {
     // The incoming values should have at a minimum the bundle_id;
     $bundle = $values['bundle'];
     $matches = array();
-    if (preg_match('/dbxref_(.*)/', $bundle, $matches)) {
-      $dbxref_id = $matches[1];
-      $values['type'] = 'BioData';
+    if (preg_match('/bio-data_(.*)/', $bundle, $matches)) {
+      $cvterm_id = $matches[1];
+      $values['type'] = 'TripalEntity';
 
       // Get the CVterm.
-      $match = array('dbxref_id' => $dbxref_id);
+      $match = array('cvterm_id' => $cvterm_id);
       $cvterm = chado_generate_var('cvterm', $match);
       if ($cvterm) {
         $values['cvterm_id'] = $cvterm->cvterm_id;
@@ -60,7 +60,7 @@ class TripalEntityController extends EntityAPIController {
     try {
       // Invoke hook_entity_delete().
       module_invoke_all('entity_delete', $entity, $entity->type);
-      field_attach_delete('BioData', $entity);
+      field_attach_delete('TripalEntity', $entity);
 
       db_delete('tripal_entity')
         ->condition('id', $entity->id)
@@ -136,10 +136,10 @@ class TripalEntityController extends EntityAPIController {
       // to determine whether to update or insert, and which hook we
       // need to invoke.
       if ($invocation == 'entity_insert') {
-        field_attach_insert('BioData', $entity);
+        field_attach_insert('TripalEntity', $entity);
       }
       else {
-        field_attach_update('BioData', $entity);
+        field_attach_update('TripalEntity', $entity);
       }
 
       // Invoke either hook_entity_update() or hook_entity_insert().

+ 12 - 14
tripal_entities/includes/TripalEntityUIController.inc

@@ -18,7 +18,7 @@ class TripalEntityUIController extends EntityDefaultUIController {
 
     // The content menu.
     $items[$this->path] = array(
-      'title' => 'Biological Data',
+      'title' => 'Tripal Content',
       'page callback' => 'tripal_entities_content_view',
       'file' =>  'includes/tripal_entities.admin.inc',
       'file path' => drupal_get_path('module', 'tripal_entities'),
@@ -26,9 +26,8 @@ class TripalEntityUIController extends EntityDefaultUIController {
       'type' => MENU_LOCAL_TASK,
     );
 
-
-    $items['BioData/add'] = array(
-      'title' => 'Add Biological Data',
+    $items['bio-data/add'] = array(
+      'title' => 'Add Tripal Content',
       'page callback' => 'tripal_entities_add_page',
       'file' =>  'includes/tripal_entities.entity_form.inc',
       'file path' => drupal_get_path('module', 'tripal_entities'),
@@ -36,17 +35,16 @@ class TripalEntityUIController extends EntityDefaultUIController {
       'access arguments' => array('edit'),
     );
 
-
     // Add a menu item for creating each bundle
     $bundles = array_keys($this->entityInfo['bundles']);
     foreach ($bundles as $bundle) {
       $matches = array();
-      preg_match('/^dbxref_(.*?)$/', $bundle, $matches);
-      $dbxref_id = $matches[1];
-      $cvterm = chado_generate_var('cvterm', array('dbxref_id' => $dbxref_id));
+      preg_match('/^bio-data_(.*?)$/', $bundle, $matches);
+      $cvterm_id = $matches[1];
+      $cvterm = chado_generate_var('cvterm', array('cvterm_id' => $cvterm_id));
 
       // Set a custom page for adding new tripal data entities.
-      $items['BioData/add/' . $dbxref_id] = array(
+      $items['bio-data/add/' . $cvterm_id] = array(
         'title' => ucfirst($cvterm->name),
         'description' => 'A ' . $cvterm->name . ' record.',
         'page callback'  => 'drupal_get_form',
@@ -59,7 +57,7 @@ class TripalEntityUIController extends EntityDefaultUIController {
     }
 
     // Link for viewing a tripal data type.
-    $items['BioData/' . $wildcard] = array(
+    $items['bio-data/' . $wildcard] = array(
       'title callback' => 'tripal_entities_entity_title',
       'title arguments' => array(1),
       'page callback' => 'tripal_entities_view_entity',
@@ -70,7 +68,7 @@ class TripalEntityUIController extends EntityDefaultUIController {
     );
 
     // 'View' tab for an individual entity page.
-    $items['BioData/' . $wildcard . '/view'] = array(
+    $items['bio-data/' . $wildcard . '/view'] = array(
       'title' => 'View',
       'page callback' => 'tripal_entities_view_entity',
       'page arguments' => array(1),
@@ -81,7 +79,7 @@ class TripalEntityUIController extends EntityDefaultUIController {
     );
 
     // 'Edit' tab for an individual entity page.
-    $items['BioData/' . $wildcard . '/edit'] = array(
+    $items['bio-data/' . $wildcard . '/edit'] = array(
       'title' => 'Edit',
       'page callback' => 'drupal_get_form',
       'page arguments' => array('tripal_entities_entity_form', NULL, 1),
@@ -94,7 +92,7 @@ class TripalEntityUIController extends EntityDefaultUIController {
     );
 
     // Menu item for deleting tripal data entities.
-    $items['BioData/' . $wildcard . '/delete'] = array(
+    $items['bio-data/' . $wildcard . '/delete'] = array(
       'title'  => 'Delete',
       'page callback' => 'drupal_get_form',
       'page arguments' => array('tripal_entities_entity_delete_form', 1),
@@ -114,6 +112,6 @@ class TripalEntityUIController extends EntityDefaultUIController {
  * @param unknown $entity
  */
 function tripal_entity_manage_fields($entity) {
-  drupal_goto('admin/structure/BioData/manage/' . $entity->bundle . '/fields');
+  drupal_goto('admin/structure/bio-data/manage/' . $entity->bundle . '/fields');
   return '';
 }

+ 79 - 195
tripal_entities/includes/tripal_entities.admin.inc

@@ -1,27 +1,10 @@
 <?php
 
-/**
- * Launchpad for biological data administration.
- */
-function tripal_entities_admin_view() {
-
-  // Render the tripal entites bundle form.
-  $form = drupal_get_form('tripal_entities_admin_bundles_form');
-  $output = drupal_render($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');
-  drupal_set_breadcrumb($breadcrumb);
-
-  return $output;
-}
-
 /**
  * Provide a data listing for tripal entites (ie: biological data).
- * Note: This hook returns a rendered page but we want a form.
+ *
+ * This function is a callback in a menu item which is set in the
+ * TripalEntityUIController class.
  */
 function tripal_entities_content_view() {
 
@@ -40,7 +23,7 @@ function tripal_entities_content_view() {
 }
 
 /**
- * Display a listing of Biological Data to the administrator.
+ * Display a listing of Tripal entities.
  *
  * @TODO Filters and bulk operations needed to be added to this form.
  *
@@ -76,14 +59,14 @@ function tripal_entities_content_overview_form($form, &$form_state) {
 
     // Add information to the table.
     $rows[] = array(
-      l($entity->title, 'BioData/' . $entity->id),
+      l($entity->title, 'bio-data/' . $entity->id),
       $cvterm->cv_id->name . ' (' . $cvterm->dbxref_id->db_id->name . ')',
       $cvterm->name,
       l($author->name, 'user/' . $entity->uid),
       $entity->status == 1 ? 'published' : 'unpublished',
       format_date($entity->changed, 'short'),
-      l('edit', 'BioData/' . $entity->id . '/edit') . '&nbsp;&nbsp;' .
-      l('delete', 'BioData/' . $entity->id . '/delete')
+      l('edit', 'bio-data/' . $entity->id . '/edit') . '&nbsp;&nbsp;' .
+      l('delete', 'bio-data/' . $entity->id . '/delete')
     );
   }
 
@@ -117,86 +100,7 @@ function tripal_entities_content_overview_form($form, &$form_state) {
 }
 
 /**
- * Tripal administration form for Biological data (Admin > Tripal > Biological Data).
- *
- * @TODO Add graph showing available data types.
- *
- * @param unknown $form
- * @param unknown $form_state
- * @return multitype:
- */
-function tripal_entities_admin_bundles_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_entity but only if they haven't
-  // already selected a tripal_entity.
-  $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_bundles_form_ajax_callback",
-      'wrapper' => 'tripal_entities_admin_bundles_form',
-      'effect' => 'fade',
-      'method' => 'replace'
-    )
-  );
-
-  $form['refresh_bundles'] = array(
-    '#type' => 'submit',
-    '#value' => t('Refresh Data Types'),
-    '#name' => 'refresh_bundles',
-  );
-
-  $form['publish_new_data'] = array(
-    '#type' => 'submit',
-    '#value' => t('Publish New Data'),
-    '#name' => 'publish_new_data',
-  );
-
-  $form['#prefix'] = '<div id="tripal_entities_admin_bundle_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_entities_admin_bundles_form_submit($form, $form_state) {
-  global $user;
-  if ($form_state['clicked_button']['#name'] == 'refresh_bundles') {
-    tripal_add_job('Create publishable data types', 'tripal_entity', 'tripal_entities_populate_entity_tables', array(), $user->uid);
-  }
-  if ($form_state['clicked_button']['#name'] == 'publish_new_data') {
-  }
-}
-
-/**
- * Form for creating biological data types (ie: tripal entity types).
+ * Form for creating tripal data types.
  *
  * This form is available on the menu at Admin >> Structure >> Biological Data
  * Types
@@ -244,11 +148,13 @@ function tripal_entities_admin_add_type_form($form, &$form_state) {
   // If no term has been selected yet then provide the auto complete field.
   if ($num_terms == 0) {
     $form['term_name'] = array(
-      '#title'       => t('Biological Data Type'),
+      '#title'       => t('Content Type'),
       '#type'        => 'textfield',
-      '#description' => t("Please enter the type of data that you want to add.
-          Once added, priviledged users can add new records of the selected
-          type. As you type, suggestions will be provided."),
+      '#description' => t("The content type must be the name of a term in
+          a controlled vocabulary and the controlled vocabulary should
+          already be loaded into Tripal.  For example, to create a content
+          type for storing 'genes', use the 'gene' term from the
+          Sequence Ontology (SO)."),
       '#required'    => TRUE,
       '#default_value' => $term_name,
       '#autocomplete_path' => "admin/tripal/chado/tripal_cv/cvterm/auto_name/$cv_id",
@@ -291,8 +197,6 @@ function tripal_entities_admin_add_type_form($form, &$form_state) {
  */
 function tripal_entities_admin_add_type_form_validate($form, &$form_state) {
 
-  // Check if this term and vocabulary is in the tripal_vocabulary usage tables.
-  // If not then add it.
   if (array_key_exists('clicked_button', $form_state) and
       $form_state['clicked_button']['#name'] =='select_cvterm') {
 
@@ -346,21 +250,21 @@ function tripal_entities_admin_add_type_form_submit($form, &$form_state) {
   if ($form_state['clicked_button']['#name'] =='select_cvterm') {
     $cvterm = $form_state['storage']['terms'][0];
 
-    $bundle_id = 'dbxref_' . $cvterm->dbxref_id->dbxref_id;
+    $bundle_id = 'bio-data_' . $cvterm->cvterm_id;
 
     // Before we try to add this type, check to see if it already exists
     // as a bundle.
-    $einfo = entity_get_info('BioData');
+    $einfo = entity_get_info('TripalEntity');
     if (!in_array($bundle_id, array_keys($einfo['bundles']))) {
       $error = '';
       $success = tripal_create_entity_type($cvterm, $error);
       if (!$success) {
         drupal_set_message($error, 'error');
-        $form_state['redirect'] = "admin/structure/BioData";
+        $form_state['redirect'] = "admin/structure/bio-data";
       }
       else {
         drupal_set_message('New biological data type created.  Fields are added automatically to this type.');
-        $form_state['redirect'] = "admin/structure/BioData";
+        $form_state['redirect'] = "admin/structure/bio-data";
       }
     }
     else {
@@ -373,26 +277,26 @@ function tripal_entities_admin_add_type_form_submit($form, &$form_state) {
  * Implements hook_add_bundle_fields().
  *
  * @param $entity_type_name
- * @param $bundle_name
+ * @param $bundle_id
  * @param $cvterm
  */
-function tripal_entities_add_bundle_fields($entity_type_name, $bundle_name, $cvterm) {
+function tripal_entities_add_bundle_fields($entity_type_name, $bundle_id, $cvterm) {
   // Adds the fields for the base table to the entity.
-  tripal_entities_add_bundle_base_fields($entity_type_name, $bundle_name, $cvterm);
+  tripal_entities_add_bundle_base_fields($entity_type_name, $bundle_id, $cvterm);
 
   // Check to see if there are any kv-property tables associated to this
   // base table. If so, add the fields for that type of table.
-  tripal_entities_add_bundle_kvproperty_adder_field($entity_type_name, $bundle_name, 'featureprop');
+  tripal_entities_add_bundle_kvproperty_adder_field($entity_type_name, $bundle_id, 'featureprop');
 }
 
 /**
  * Adds the fields for a kv-property table fields
  *
  * @param $entity_type_name
- * @param $bundle_name
+ * @param $bundle_id
  * @param $kv_table
  */
-function tripal_entities_add_bundle_kvproperty_adder_field($entity_type_name, $bundle_name, $kv_table) {
+function tripal_entities_add_bundle_kvproperty_adder_field($entity_type_name, $bundle_id, $kv_table) {
   // First add a generic property field so that users can add new proeprty types.
   $field_name = $kv_table;
 
@@ -406,90 +310,82 @@ function tripal_entities_add_bundle_kvproperty_adder_field($entity_type_name, $b
     'label' => 'Additional Properties',
     'is_required' => 0,
   );
-  tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
+  tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_id);
 }
 
 /**
  * Adds the fields for the base table to the entity.
  */
-function tripal_entities_add_bundle_base_fields($entity_type_name, $bundle_name, $cvterm) {
-
-  // Get the list of tables where this cvterm is used.
-  $match = array('cvterm_id' => $cvterm->cvterm_id);
-  $term = chado_select_record('tripal_term', array('*'), $match);
-  $values = array('term_id' => $term[0]->term_id);
-  $tables = chado_select_record('tripal_term_usage', array('*'), $values);
-
-  // Iterate through the tables.
-  foreach ($tables as $table) {
-    $table_name = $table->data_table;
-    $type_table = $table->type_table;
-    $type_field = $table->field;
-
-    // We only want to look at base tables.
-    if ($table_name == 'cvterm_dbxref' || $table_name == 'cvterm_relationship' ||
-        $table_name == 'cvtermpath' || $table_name == 'cvtermprop' || $table_name == 'chadoprop' ||
-        $table_name == 'cvtermsynonym' || preg_match('/_relationship$/', $table_name) ||
-        preg_match('/_cvterm$/', $table_name)) {
+function tripal_entities_add_bundle_base_fields($entity_type_name, $bundle_id, $cvterm) {
+
+  // Get the details for this bundle
+  $bundle = db_select('tripal_bundle', 't')
+    ->fields('t')
+    ->condition('type', 'TripalEntity')
+    ->condition('bundle', $bundle_id)
+    ->execute()
+    ->fetchObject();
+  $bundle_data = unserialize($bundle->data);
+
+  $table_name = $bundle_data['data_table'];
+  $type_table = $bundle_data['type_table'];
+  $type_field = $bundle_data['field'];
+
+  // Iterate through the columns of the table and see if fields have been
+  // created for each one. If not, then create them.
+  $schema = chado_get_schema($table_name);
+  $columns = $schema['fields'];
+  foreach ($columns as $column_name => $details) {
+    $field_name = $table_name . '__' . $column_name;
+
+    // Skip the primary key field.
+    if ($column_name == $schema['primary key'][0]) {
       continue;
     }
 
-    // Iterate through the columns of the table and see if fields have been
-    // created for each one. If not, then create them.
-    $schema = chado_get_schema($table_name);
-    $columns = $schema['fields'];
-    foreach ($columns as $column_name => $details) {
-      $field_name = $table_name . '__' . $column_name;
-
-      // Skip the primary key field.
-      if ($column_name == $schema['primary key'][0]) {
-        continue;
-      }
-
-      // Skip the type field.
-      if ($table_name == $type_table and $column_name == $type_field) {
-        continue;
-      }
+    // Skip the type field.
+    if ($table_name == $type_table and $column_name == $type_field) {
+      continue;
+    }
 
-      // Get the field defaults for this column.
-      $field_info = tripal_entities_get_table_column_field_default($table_name, $schema, $column_name);
+    // Get the field defaults for this column.
+    $field_info = tripal_entities_get_table_column_field_default($table_name, $schema, $column_name);
 
 
-      // Determine if the field is required.
-      if (array_key_exists('not null', $details) and $details['not null'] === TRUE) {
-        $field_info['is_required'] = array_key_exists('default', $details) ? 0 : 1;
-      }
+    // Determine if the field is required.
+    if (array_key_exists('not null', $details) and $details['not null'] === TRUE) {
+      $field_info['is_required'] = array_key_exists('default', $details) ? 0 : 1;
+    }
 
-      // If we don't have a field type then we don't need to create a field.
-      if (!$field_info['field_type']) {
-        // If we don't have a field type but it is required and doesn't have
-        // a default value then we are in trouble.
-        if ($field_info['is_required'] and !array_key_exists('default', $details)) {
-          throw new Exception(t('The %table.%field type, %type, is not yet supported for Entity fields, but it is required,',
-              array('%table' => $table_name, '%field' => $column_name, '%type' => $details['type'])));
-        }
-        continue;
+    // If we don't have a field type then we don't need to create a field.
+    if (!$field_info['field_type']) {
+      // If we don't have a field type but it is required and doesn't have
+      // a default value then we are in trouble.
+      if ($field_info['is_required'] and !array_key_exists('default', $details)) {
+        throw new Exception(t('The %table.%field type, %type, is not yet supported for Entity fields, but it is required,',
+            array('%table' => $table_name, '%field' => $column_name, '%type' => $details['type'])));
       }
+      continue;
+    }
 
-      // If this field is a foreign key field then we will have a special custom
-      // field provided by Tripal.
-      $is_fk = FALSE;
-      if (array_key_exists('foreign keys', $schema)) {
-        foreach ($schema['foreign keys'] as $remote_table => $fk_details) {
-          if (array_key_exists($column_name, $fk_details['columns'])) {
-            $is_fk = TRUE;
-          }
+    // If this field is a foreign key field then we will have a special custom
+    // field provided by Tripal.
+    $is_fk = FALSE;
+    if (array_key_exists('foreign keys', $schema)) {
+      foreach ($schema['foreign keys'] as $remote_table => $fk_details) {
+        if (array_key_exists($column_name, $fk_details['columns'])) {
+          $is_fk = TRUE;
         }
       }
-
-      // Add the field to the bundle.
-      tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
     }
+
+    // Add the field to the bundle.
+    tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_id);
   }
 }
 
 /**
- * Returns a $field_info array for a field based on a databaes column.
+ * Returns a $field_info array for a field based on a database column.
  *
  */
 function tripal_entities_get_table_column_field_default($table_name, $schema, $column_name) {
@@ -568,15 +464,3 @@ function tripal_entities_get_table_column_field_default($table_name, $schema, $c
 
   return $field_info;
 }
-
-/**
- *
- * @param unknown $form
- * @param unknown $form_state
- * @return multitype:
- */
-function tripal_entities_admin_access_form($form, &$form_state) {
-  $form = array();
-
-  return $form;
-}

+ 20 - 14
tripal_entities/includes/tripal_entities.entity_form.inc

@@ -1,7 +1,10 @@
 <?php
 
 /**
+ * Provides a list of TripalEntity types (bundles) for the user to add.
  *
+ * This function is a callback in a menu item which is set in the
+ * TripalEntityUIController class.
  */
 function tripal_entities_add_page() {
   $item = menu_get_item();
@@ -44,7 +47,10 @@ function theme_tripal_entities_add_list($variables) {
       TRIPAL_INFO,
       array('return_html' => TRUE)
     );
-    $output .= '<p>' . t('You have not created any biological data types yet. Go to the <a href="@create-content">data type creation page</a> to add a new biological data type.', array('@create-content' => url('admin/structure/BioData/add'))) . '</p>';
+    $output .= '<p>' . t('You have not created any biological data types yet. ' .
+      'Go to the <a href="@create-content">data type creation page</a> to ' .
+      'add a new biological data type.',
+       array('@create-content' => url('admin/structure/bio-data/add'))) . '</p>';
   }
   return $output;
 }
@@ -52,9 +58,9 @@ function theme_tripal_entities_add_list($variables) {
 /**
  *
  */
-function tripal_entities_entity_form($form, &$form_state, $dbxref_id = '', $entity = NULL) {
+function tripal_entities_entity_form($form, &$form_state, $cvterm_id = '', $entity = NULL) {
 
-  $bundle_id = 'dbxref_' . $dbxref_id;
+  $bundle_id = 'bio-data_' . $cvterm_id;
 
   // Add a vertical tabs element
   $form['entity_form_vtabs'] = array(
@@ -64,8 +70,8 @@ function tripal_entities_entity_form($form, &$form_state, $dbxref_id = '', $enti
 
   // If the entity doesn't exist then create one.
   if (!$entity) {
-    $entity = entity_get_controller('BioData')->create(array('bundle' => $bundle_id));
-    field_attach_form('BioData', $entity, $form, $form_state);
+    $entity = entity_get_controller('TripalEntity')->create(array('bundle' => $bundle_id));
+    field_attach_form('TripalEntity', $entity, $form, $form_state);
 
     $form['add_button'] = array(
       '#type' => 'submit',
@@ -75,7 +81,7 @@ function tripal_entities_entity_form($form, &$form_state, $dbxref_id = '', $enti
     );
   }
   else {
-    field_attach_form('BioData', $entity, $form, $form_state);
+    field_attach_form('TripalEntity', $entity, $form, $form_state);
     $form['update_button'] = array(
       '#type' => 'submit',
       '#value' => t('Update'),
@@ -92,7 +98,7 @@ function tripal_entities_entity_form($form, &$form_state, $dbxref_id = '', $enti
 
   // The entity object must be added to the $form_state in order for
   // the Entity API to work. It must have a key of the entity name.
-  $form_state['BioData'] = $entity;
+  $form_state['TripalEntity'] = $entity;
 
   $form['#prefix'] = "<div id='$bundle_id-entity-form'>";
   $form['#suffix'] = "</div>";
@@ -114,8 +120,8 @@ function tripal_entities_entity_form_validate($form, &$form_state) {
 
   if (array_key_exists('clicked_button', $form_state) and
       $form_state['clicked_button']['#name'] =='add_data') {
-    $entity = $form_state['BioData'];
-    field_attach_form_validate('BioData', $entity, $form, $form_state);
+    $entity = $form_state['TripalEntity'];
+    field_attach_form_validate('TripalEntity', $entity, $form, $form_state);
   }
 }
 
@@ -124,25 +130,25 @@ function tripal_entities_entity_form_validate($form, &$form_state) {
  * Implements hook_submit() for the tripal_entities_entity_form.
  */
 function tripal_entities_entity_form_submit($form, &$form_state) {
-  $entity = $form_state['BioData'];
+  $entity = $form_state['TripalEntity'];
 
   if ($form_state['clicked_button']['#name'] =='cancel') {
-    $form_state['redirect'] = "BioData/" . $entity->id;
+    $form_state['redirect'] = "bio-data/" . $entity->id;
   }
 
   if ($form_state['clicked_button']['#name'] =='update_data' or
       $form_state['clicked_button']['#name'] =='add_data') {
 
-    $entityform = entity_ui_controller('BioData')->entityFormSubmitBuildEntity($form, $form_state);
+    $entityform = entity_ui_controller('TripalEntity')->entityFormSubmitBuildEntity($form, $form_state);
     if ($entityform->save()) {
-      $form_state['redirect'] = "BioData/" . $entity->id;
+      $form_state['redirect'] = "bio-data/" . $entity->id;
     }
     else {
       drupal_set_message('Cannot save entity', 'error');
     }
   }
   if ($form_state['clicked_button']['#name'] =='delete_data') {
-    $form_state['redirect'] = 'BioData/' . $entity->id .'/delete';
+    $form_state['redirect'] = 'bio-data/' . $entity->id .'/delete';
   }
 }
 

+ 1 - 2
tripal_entities/includes/tripal_entities.tables.inc

@@ -41,8 +41,7 @@ function tripal_entities_populate_entity_tables() {
         $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.
+          // Get the CV term details.
           $cvterm = chado_generate_var('cvterm', array('cvterm_id' => $cvterm_id));
 
           // First add a record to the tripal_vocabulary table.

+ 26 - 355
tripal_entities/tripal_entities.install

@@ -9,35 +9,6 @@
  */
 function tripal_entities_install() {
 
-  // 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
-  );
-
   // Unfortunately, some Chado base tables do not have a type_id, so we must
   // take special action for those tables.  These include: organism and
   // analysis. Until we can find an appropriate controlled vocabulary
@@ -68,6 +39,15 @@ function tripal_entities_install() {
     'cv_name' => 'local',
   ));
 
+  tripal_insert_cvterm(array(
+    'id' => 'local:project',
+    'name' => 'project',
+    'definition' => 'A plan or proposal for accomplishing something. ' .
+      '(American Heritage® Dictionary of the English Language, Fifth Edition. ' .
+      'Copyright © 2011 by Houghton Mifflin Harcourt Publishing Company).',
+    'cv_name' => 'local',
+  ));
+
   // We want to provide a set of commonly used entity types by default. This
   // way when a user first installs Tripal there are some commonly used
   // formats.
@@ -82,13 +62,21 @@ function tripal_entities_install() {
     throw new Exception($error);
   }
 
-  // Create the 'Organism' entity type. This uses the local:organism term.
+  // Create the 'Analysis' entity type. This uses the local:analysis term.
   $error = '';
   $term = array('name' => 'analysis', 'cv_id' => array('name' => 'local'));
   $cvterm = chado_generate_var('cvterm', $term);
   if (!tripal_create_entity_type($cvterm, $error)) {
     throw new Exception($error);
   }
+
+  // Create the 'Project' entity type. This uses the local:project term.
+  $error = '';
+  $term = array('name' => 'project', 'cv_id' => array('name' => 'local'));
+  $cvterm = chado_generate_var('cvterm', $term);
+  if (!tripal_create_entity_type($cvterm, $error)) {
+    throw new Exception($error);
+  }
 }
 
 /**
@@ -96,13 +84,13 @@ function tripal_entities_install() {
  */
 function tripal_entities_schema() {
 
-  // Biological Data
+  // Adds a table for managing TripalEntity entities.
   $schema['tripal_entity'] = tripal_entities_tripal_entity_schema();
 
-  // Biological Data Types
+  // Adds a table for managing the TripalEntity entity types (bundles).
   $schema['tripal_bundle'] = tripal_entities_tripal_bundle_schema();
 
-  // Links Biological Data Entities to the chado "base" table the data is stored in.
+  // Links TripalEntity entities to the chado record.
   $schema['chado_entity'] = tripal_entities_chado_entity_schema();
 
   return $schema;
@@ -115,11 +103,11 @@ function tripal_entities_schema() {
  * 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);
-  }
+//   $terms = chado_generate_var('tripal_term', array('publish' => 1), array('return_array' => 1));
+//   foreach ($terms as $term) {
+//     $bundle_id = 'bio-data_' . $term->cvterm_id;
+//     field_attach_delete_bundle('TripalEntity', $bundle_id);
+//   }
 }
 
 /**
@@ -329,320 +317,3 @@ function tripal_entities_chado_entity_schema() {
   );
   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'
-      ),
-    ),
-    'indexes' => array(
-      'tripal_term_vocabulary_id' => array('vocabulary_id'),
-      'tripal_term_cvterm_id' => array('cvterm_id'),
-    ),
-  );
-  return $schema;
-}
-
-/**
- *
- *
- * 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',
-        '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
-      ),
-    ),
-    'primary key' => array (
-      0 => 'vocabulary_usage_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'),
-    ),
-  );
-  return $schema;
-}
-
-/**
- *
- *
- * 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',
-        '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'),
-    ),
-  );
-  return $schema;
-}
-
-/**
- *
- *
- * 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',
-        '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'),
-    ),
-  );
-  return $schema;
-}

+ 49 - 109
tripal_entities/tripal_entities.module

@@ -25,36 +25,10 @@ function tripal_entities_views_api() {
  */
 function tripal_entities_menu() {
 
-  $items = array();
-
-  // The administative settings menu.
-  $items['admin/tripal/BioData'] = array(
-    '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/BioData/default'] = array(
-    'title' => 'Biological Data',
-    'type' => MENU_DEFAULT_LOCAL_TASK,
-    'weight' =>  1,
-  );
-
-  $items['admin/tripal/BioData/access'] = array(
-    'title' => 'Access',
-    'description' => 'Set default access permissions for collections of data.',
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('tripal_entities_admin_access_form'),
-    'access arguments' => array('administer tripal data types'),
-    'file' =>  'includes/tripal_entities.admin.inc',
-    'type' => MENU_LOCAL_TASK,
-    'weight' => 3
-  );
+  // Note:  menu items for the entities can be found in the
+  // Entity's UI Controller class.
 
+  $items = array();
   return $items;
 }
 
@@ -65,10 +39,10 @@ function tripal_entities_menu() {
 function tripal_entities_admin_paths() {
   if (variable_get('node_admin_theme')) {
     $paths = array(
-      'BioData/*/edit' => TRUE,
-      'BioData/*/delete' => TRUE,
-      'BioData/add' => TRUE,
-      'BioData/add/*' => TRUE,
+      'bio-data/*/edit' => TRUE,
+      'bio-data/*/delete' => TRUE,
+      'bio-data/add' => TRUE,
+      'bio-data/add/*' => TRUE,
     );
     return $paths;
   }
@@ -76,13 +50,15 @@ function tripal_entities_admin_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 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');
+  // Add an "Add Tripal Content" action link to the Admin >> Content >>
+  // Biological Content page.
+  if ($root_path == 'admin/content/bio-data') {
+    $item = menu_get_item('bio-data/add');
     if ($item['access']) {
       $data['actions']['output'][] = array(
         '#theme' => 'menu_local_action',
@@ -94,10 +70,10 @@ 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.
+ * Modify the shortcut menu to include Biological content links.
  *
  * @param object $account
- *   The user account whose default shortcut set will be returned. If not provided, the 
+ *   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.
  *
  * @return
@@ -118,13 +94,13 @@ function tripal_entities_shortcut_default_set($account) {
     $shortcut_set->title = $t('TripalDefault');
     $shortcut_set->links = array(
       array(
-        'link_path' => 'BioData/add',
-        'link_title' => 'Add Biological Data',
+        'link_path' => 'bio-data/add',
+        'link_title' => 'Add Tripal Content',
         'weight' => -23,
       ),
       array(
-        'link_path' => 'admin/content/BioData',
-        'link_title' => 'Find Biological Data',
+        'link_path' => 'admin/content/bio-data',
+        'link_title' => 'Find Tripal Content',
         'weight' => -22,
       ),
       array(
@@ -166,7 +142,7 @@ function tripal_entities_permission() {
       'description' => t('Edit and delete all tripal data'),
     ),
   );
-  
+
   return $permissions;
 }
 
@@ -230,10 +206,10 @@ function tripal_entities_rdf_mapping() {
  */
 function tripal_entities_entity_info() {
   $entities = array();
-  $entities['BioData'] = array (
+  $entities['TripalEntity'] = array (
     // A human readable label to identify our entity.
-    'label' => 'Biological Data',
-    'plural label' => 'Biological Data',
+    'label' => 'Biological Content',
+    'plural label' => 'Biological Content',
 
     // The entity class and controller class extend the classes provided by the
     // Entity API.
@@ -276,7 +252,7 @@ function tripal_entities_entity_info() {
     // key here is mean to appear on the 'Find Content' page of the
     // administrative menu.
     'admin ui' => array (
-      'path' => 'admin/content/BioData',
+      'path' => 'admin/content/bio-data',
       'controller class' => 'TripalEntityUIController',
       'menu wildcard' => '%tripal_entity',
       'file' => 'includes/TripalEntityUIController.inc'
@@ -294,13 +270,13 @@ function tripal_entities_entity_info() {
   );
 
   // The entity that holds information about the entity types.
-  $entities['BioData_bundles'] = array (
-    'label' => 'Biological Data Type', //$voc->db_id->name . ' (' . $voc->cv_id->name . ') Data Type',
+  $entities['TripalBundle'] = array (
+    'label' => 'Tripal Content Type',
     'entity class' => 'TripalBundle',
     'controller class' => 'TripalBundleController',
     'base table' => 'tripal_bundle',
     'fieldable' => FALSE,
-    'bundle of' => 'BioData',
+    'bundle of' => 'TripalEntity',
     'exportable' => FALSE,
     'entity keys' => array (
       'id' => 'id',
@@ -311,28 +287,40 @@ function tripal_entities_entity_info() {
     'module' => 'tripal_entities',
     // Enable the entity API's admin UI.
     'admin ui' => array (
-      'path' => 'admin/structure/BioData',
+      'path' => 'admin/structure/bio-data',
       'controller class' => 'TripalBundleUIController',
       'file' => 'includes/TripalBundleUIController.inc',
       'menu wildcard' => '%tripal_bundle',
     )
   );
 
+  return $entities;
+}
+
+/**
+ * Implements hook_entities_info_alter().
+ *
+ * Add in the bundles (entity types) to the TripalEntity entity.
+ */
+function tripal_entities_entity_info_alter(&$entity_info){
   // Dynamically add in the bundles. Bundles are alternative groups of fields
   // or configuration associated with an entity type .We want to dynamically
   // add the bundles to the entity.
-  $published_terms = chado_generate_var('tripal_term', array('publish' => 1), array('return_array' => 1));
-  foreach ($published_terms as $term) {
-
-    $cvterm = $term->cvterm_id;
-    $bundle_id = 'dbxref_' . $cvterm->dbxref_id->dbxref_id;
+  $bundles = db_select('tripal_bundle', 'tb')
+    ->fields('tb')
+    ->execute();
+
+  while ($bundle = $bundles->fetchObject()) {
+    $bundle_id = $bundle->bundle;
+    $cvterm_id = preg_replace('/bio-data_/', '', $bundle_id);
+    $cvterm = chado_generate_var('cvterm', array('cvterm_id' => $cvterm_id));
     $label = preg_replace('/_/', ' ', ucwords($cvterm->name));
 
-    $entities['BioData']['bundles'][$bundle_id] = array (
+    $entity_info['TripalEntity']['bundles'][$bundle_id] = array (
       'label' => $label,
       'admin' => array (
-        'path' => 'admin/structure/BioData/manage/%tripal_bundle',
-        'real path' => 'admin/structure/BioData/manage/' . $bundle_id,
+        'path' => 'admin/structure/bio-data/manage/%tripal_bundle',
+        'real path' => 'admin/structure/bio-data/manage/' . $bundle_id,
         'bundle argument' => 4,
         'access arguments' => array (
           'administer tripal data types'
@@ -340,54 +328,6 @@ function tripal_entities_entity_info() {
       )
     );
   }
-  return $entities;
-}
-
-/**
- * Get published vocabularies as select options
- * @return multitype:NULL
- */
-function tripal_entities_get_published_vocabularies_as_select_options() {
-  $published_vocs = chado_generate_var('tripal_vocabulary', array('publish' => 1), array('return_array' => 1));
-  $options = array();
-  foreach ($published_vocs as $voc) {
-    $options [$voc->cv_id->cv_id] = $voc->cv_id->name;
-  }
-  return $options;
-}
-
-/**
- * Get published vocabularies as select options
- * @return multitype:NULL
- */
-function tripal_entities_get_db_names_for_published_vocabularies() {
-  $published_vocs = chado_generate_var('tripal_vocabulary', array('publish' => 1), array('return_array' => 1));
-  $db = array();
-  foreach ($published_vocs as $voc) {
-    $db [$voc->db_id->db_id] = $voc->db_id->name;
-  }
-  return $db;
-}
-
-/**
- * Get published terms as select options
- * @return multitype:NULL
- */
-function tripal_entities_get_published_terms_as_select_options($cv_id = NULL) {
-  $where = array('publish' => 1);
-  $published_terms = chado_generate_var('tripal_term', $where, array('return_array' => 1));
-  $options = array();
-  foreach ($published_terms as $term) {
-    if (!$cv_id) {
-      $options [$term->cvterm_id->name] = $term->cvterm_id->name;
-    }
-    else {
-      if ($term->cvterm_id->cv_id->cv_id == $cv_id) {
-        $options [$term->cvterm_id->name] = $term->cvterm_id->name;
-      }
-    }
-  }
-  return $options;
 }
 
 /**
@@ -408,7 +348,7 @@ function tripal_bundle_load($bundle_type, $reset = FALSE) {
     ->fetchObject();
 
   if ($bundle_types) {
-    $entity = entity_load('BioData_bundles', array($bundle_types->id), array(), $reset);
+    $entity = entity_load('TripalBundle', array($bundle_types->id), array(), $reset);
     return reset($entity);
   }
   return FALSE;
@@ -430,7 +370,7 @@ function tripal_bundle_load($bundle_type, $reset = FALSE) {
  * @see tripal_entity_load_multiple()
  */
 function tripal_entity_load($id, $reset = FALSE) {
-    $entity = entity_load('BioData', array($id), array(), $reset);
+    $entity = entity_load('TripalEntity', array($id), array(), $reset);
     return reset($entity);
 }
 

+ 4 - 5
tripal_fields/api/tripal_fields.api.inc

@@ -24,12 +24,11 @@
  *       FIELD_CARDINALITY_UNLIMITED for unlimited number of values.
  * @param $entity_type_name
  *   The entity type name.
- * @param $bundle_name
+ * @param $bundle_id
  *   The bundle name.
  *
  */
-function tripal_add_bundle_field($field_name, $field_info,
-    $entity_type_name, $bundle_name) {
+function tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_id) {
 
       $field = field_info_field($field_name);
 
@@ -37,7 +36,7 @@ function tripal_add_bundle_field($field_name, $field_info,
       // there is nothing left to do.
       if ($field and array_key_exists('bundles', $field) and
           array_key_exists($entity_type_name, $field['bundles']) and
-          in_array($bundle_name, $field['bundles'][$entity_type_name])) {
+          in_array($bundle_id, $field['bundles'][$entity_type_name])) {
             return;
           }
 
@@ -76,7 +75,7 @@ function tripal_add_bundle_field($field_name, $field_info,
             'entity_type' => $entity_type_name,
             'required' => $field_info['is_required'],
             'settings' => $field_info['field_settings'],
-            'bundle' => $bundle_name,
+            'bundle' => $bundle_id,
           );
           field_create_instance($field_instance);
 }

+ 2 - 2
tripal_fields/includes/fields/kvproperty.inc

@@ -14,11 +14,11 @@ function tripal_fields_kvproperty_formatter(&$element, $entity_type, $entity, $f
   $instance, $langcode, $items, $display) {
 
   $field_name = $field['field_name'];
-  $chado_tabe = $field['settings']['chado_table'];
+  $chado_table = $field['settings']['chado_table'];
 
   $properties = array();
   foreach ($items as $delta => $item) {
-    $properties[] = $item[$chado_tabe . '__value'];
+    $properties[] = $item[$chado_table . '__value'];
   }
   $content = implode(', ', $properties);
   $element[$delta] = array(

+ 2 - 2
tripal_fields_layout/theme/css/tripal_fields_layout.css

@@ -1,11 +1,11 @@
 @CHARSET "UTF-8";
 
-.tripal-biodata-panel {
+.tripal-entity-panel {
   border: solid 1px #CCC;
   margin: 15px 0px;
   padding: 15px;
 }
 
-.tripal-biodata-panel h2 {
+.tripal-entity-panel h2 {
   margin-top: 0px;
 }

+ 37 - 38
tripal_fields_layout/tripal_fields_layout.module

@@ -28,14 +28,14 @@ function tripal_fields_layout_form_field_ui_field_edit_form_alter(&$form, &$form
 function tripal_fields_layout_form_field_ui_display_overview_form_alter(&$form, &$form_state, $form_id) {
 
   drupal_add_css(drupal_get_path('module','tripal_fields_layout') . '/theme/css/tripal_fields_layout_panels.css');
-  
+
   $entity_type = $form['#entity_type'];
-  $bundle_name = $form['#bundle'];
+  $bundle_id = $form['#bundle'];
 
   // Get the bundle record.
   $bundle = db_select('tripal_bundle', 'tb')
     ->fields('tb')
-    ->condition('bundle', $bundle_name)
+    ->condition('bundle', $bundle_id)
     ->execute()
     ->fetchObject();
 
@@ -63,13 +63,13 @@ function tripal_fields_layout_form_field_ui_display_overview_form_alter(&$form,
 
   // Make sure our default panels are in the database.
   _tripal_fields_layout_check_default_field_panels($bundle);
-  
+
   // Add a Panel
   tripal_fields_layout_form_field_ui_display_overview_form_panel_add($form, $form_state);
-  
+
   // Arrange Panels
   tripal_fields_layout_form_field_ui_display_overview_form_panel_arrange($form, $form_state, $bundle);
-  
+
   // Configure Panels
   tripal_fields_layout_form_field_ui_display_overview_form_panel_configure($form, $bundle);
 
@@ -107,7 +107,7 @@ function tripal_fields_layout_form_field_ui_display_overview_form_alter(&$form,
   $default_panel = 'te_base';
 
   foreach (element_children($fields) as $field_name) {
-    $field_instance = field_info_instance($entity_type, $field_name, $bundle_name);
+    $field_instance = field_info_instance($entity_type, $field_name, $bundle_id);
     $panel_id = db_select('tripal_panel_fields', 'tpf')
     ->fields('tpf', array('panel_id'))
     ->condition('field_id', $field_instance['id'])
@@ -157,7 +157,7 @@ function tripal_fields_layout_form_field_ui_display_overview_form_panel_add (&$f
     '#type' => 'hidden',
     '#title' => 'Panel Name',
     '#description' => t('The name is automatically generated for a label. it
-        contains alphanumeric values and underscores and does not begin with 
+        contains alphanumeric values and underscores and does not begin with
         a number.')
   );
   $form['te_add_panels']['panel_label'] = array(
@@ -282,7 +282,7 @@ function tripal_fields_layout_form_field_ui_display_overview_form_panel_configur
     ->fields('tpf', array('field_id'))
     ->condition('panel_id', $panel->panel_id)
     ->execute();
-    
+
     $has_field = FALSE;
     foreach ($fields AS $field) {
       $field_obj = db_select('field_config_instance', 'tci')
@@ -310,15 +310,15 @@ function tripal_fields_layout_form_field_ui_display_overview_form_panel_configur
       $form['te_configure_panels']['panel_items'][$panel->panel_id][$fname]['table_group'] = array(
         '#type' => 'radios',
         '#options' => array(
-          0 => 'No Group', 
-          1 => 'Horizontal Table', 
+          0 => 'No Group',
+          1 => 'Horizontal Table',
           2 => 'Vertical Table'
         ),
         '#default_value' => $default_value,
       );
       $has_field = TRUE;
     }
-    
+
     if (!$has_field) {
       $form['te_configure_panels']['panel_items'][$panel->panel_id]['no_field'] = array(
         '#markup' => 'No field in this panel.',
@@ -461,7 +461,7 @@ function tripal_fields_layout_field_ui_row_region($row) {
  * @param $form_state
  */
 function tripal_fields_layout_field_ui_validate($form, &$form_state) {
-  
+
 }
 /**
  * Responds to a submit from the field UI form for saving panel assignments.
@@ -502,34 +502,33 @@ function tripal_fields_layout_field_ui_submit($form, &$form_state) {
       // Get region panel_id
       $region = $field_data['region'];
       $panel_id = db_select('tripal_panels', 'tp')
-      ->fields('tp', array('panel_id'))
-      ->condition('name', $region)
-      ->condition('bundle_id', $bundle->id)
-      ->execute()
-      ->fetchField();
+        ->fields('tp', array('panel_id'))
+        ->condition('name', $region)
+        ->condition('bundle_id', $bundle->id)
+        ->execute()
+        ->fetchField();
 
       // Save
       $penal_field_id = db_select('tripal_panel_fields', 'tpf')
-      ->fields('tpf', array('panel_field_id'))
-      ->condition('field_id', $field_instance_id)
-      ->execute()
-      ->fetchField();
-      //dpm(array('instance' => $field_instance_id, 'panel_id' => $panel_id, 'panel_field_id' => $penal_field_id, ));
+        ->fields('tpf', array('panel_field_id'))
+        ->condition('field_id', $field_instance_id)
+        ->execute()
+        ->fetchField();
       if ($penal_field_id) {
         db_update('tripal_panel_fields')
-        ->fields(array(
-          'panel_id' => $panel_id,
-        ))
-        ->condition('panel_field_id', $penal_field_id)
-        ->execute();
+          ->fields(array(
+            'panel_id' => $panel_id,
+          ))
+          ->condition('panel_field_id', $penal_field_id)
+          ->execute();
       }
       else {
         db_insert('tripal_panel_fields')
-        ->fields(array(
-          'panel_id' => $panel_id,
-          'field_id' => $field_instance_id
-        ))
-        ->execute();
+          ->fields(array(
+            'panel_id' => $panel_id,
+            'field_id' => $field_instance_id
+          ))
+          ->execute();
       }
     }
   }
@@ -596,7 +595,7 @@ function tripal_fields_layout_action_rename_panel (&$form, &$form_state) {
     ))
     ->condition('panel_id', $panel_id)
     ->execute();
-    form_set_value($form['te_arrange_panels']['panel_items'][$panel_id]['newlabel'], '', $form_state);    
+    form_set_value($form['te_arrange_panels']['panel_items'][$panel_id]['newlabel'], '', $form_state);
   }
 }
 
@@ -763,10 +762,10 @@ function theme_tripal_fields_layout_form_configure_panels ($variables) {
       'attributes' => array('id' => $table_id, 'class' => array($table_class)),
     ));
   }
-  
+
   $collapsible_item = array('element' => array());
   $collapsible_item['element']['#children'] = '';
-  $collapsible_item['element']['#description'] = 
+  $collapsible_item['element']['#description'] =
     '<div id="tripal_fields_layout-panel_configure-fieldset-instruction">
         Select a group to organize fields into table(s) in this panel.
      <div>'
@@ -776,7 +775,7 @@ function theme_tripal_fields_layout_form_configure_panels ($variables) {
   $output = theme('fieldset', $collapsible_item);
   return $output;
 }
-  
+
 /**
  * Implements hook_theme().
  */
@@ -801,7 +800,7 @@ function tripal_fields_layout_theme($existing, $type, $theme, $path) {
  */
 function tripal_fields_layout_entity_view($entity, $type, $view_mode, $langcode) {
   switch ($type) {
-    case 'BioData':
+    case 'TripalEntity':
       // Use the generic template to render the fields
       if ($view_mode == 'full') {