tripal_chado.entity.api.inc 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * A helper function to retreive the entity_id of a given record_id.
  4. *
  5. * @param $bundle
  6. * A bundle object (as retreieved from tripal_load_bundle_entity().
  7. * @param $record_id
  8. * The ID of the record in the Chado table. The record must belong to
  9. * the table to which the bundle is associated in chado.
  10. *
  11. * @return
  12. * A database result object.
  13. */
  14. function tripal_chado_get_record_entity($bundle, $record_id) {
  15. if (!$bundle or !$record_id) {
  16. return NULL;
  17. }
  18. $chado_entity_table = tripal_chado_get_bundle_entity_table($bundle);
  19. return db_select($chado_entity_table, 'CE')
  20. ->condition('CE.record_id', $record_id)
  21. ->execute()
  22. ->fetchObject();
  23. }
  24. /**
  25. * A helper function that provides the Chado mapping table for the bundle.
  26. *
  27. * The tripal_chado module must map entities to their corresponding record
  28. * in Chado. Each bundl type has their own table for this mapping. This
  29. * function provides the name of the table given the bundle name. A mapping
  30. * table will only map to one table in Chado so the record_id's of the mapping
  31. * table should always be unique.
  32. *
  33. * @param $bundle
  34. * A bundle object (as retreieved from tripal_load_bundle_entity().
  35. *
  36. * @return
  37. * The name of the mapping table that Chado uses to map entities to records.
  38. */
  39. function tripal_chado_get_bundle_entity_table($bundle) {
  40. if (!$bundle) {
  41. return '';
  42. }
  43. return 'chado_' . $bundle->name;
  44. }