tripal_entities.api.inc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * Menu argument loader; Load a tripal data type by string.
  4. *
  5. * @param $type
  6. * The machine-readable name of a tripal data type to load.
  7. * @return
  8. * A tripal data type array or FALSE if $type does not exist.
  9. */
  10. function tripal_data_type_load($bundle_type, $reset = FALSE) {
  11. // Get the type of entity by the ID.
  12. $bundle_types = db_select('tripal_data_type', 'tdt')
  13. ->fields('tdt', array('id', 'type'))
  14. ->condition('bundle', $bundle_type)
  15. ->execute()
  16. ->fetchObject();
  17. // Load the entity.
  18. $entity = entity_load($bundle_types->type, array($bundle_types->id), array(), $reset);
  19. return reset($entity);
  20. }
  21. /**
  22. * Fetch a tripal_data object. Make sure that the wildcard you choose
  23. * in the tripal_data entity definition fits the function name here.
  24. *
  25. * @param $id
  26. * Integer specifying the tripal_data id.
  27. * @param $reset
  28. * A boolean indicating that the internal cache should be reset.
  29. * @return
  30. * A fully-loaded $tripal_data object or FALSE if it cannot be loaded.
  31. *
  32. * @see tripal_data_load_multiple()
  33. */
  34. function tripal_data_load($id, $reset = FALSE) {
  35. // Get the type of entity by the ID.
  36. $entity_type = db_select('tripal_data', 'td')
  37. ->fields('td', array('type'))
  38. ->condition('id', $id)
  39. ->execute()
  40. ->fetchField();
  41. // Load the entity.
  42. $entity = entity_load($entity_type, array($id), array(), $reset);
  43. return reset($entity);
  44. }
  45. /**
  46. * Deletes a tripal_data.
  47. */
  48. function tripal_data_delete(TripalData $tripal_data) {
  49. $tripal_data->delete();
  50. }
  51. /**
  52. * Saves a tripal_data to the database.
  53. *
  54. * @param $tripal_data
  55. * The tripal_data object.
  56. */
  57. function tripal_data_save(TripalData $entity) {
  58. return $entity->save();
  59. }
  60. /**
  61. * Saves a tripal_data type to the db.
  62. */
  63. function tripal_data_type_save(TripalDataType $entity) {
  64. $entity->save();
  65. }
  66. /**
  67. * Deletes a tripal_data type from the db.
  68. */
  69. function tripal_data_type_delete(TripalDataType $type) {
  70. $type->delete();
  71. }
  72. /**
  73. * URI callback for tripal_datas
  74. */
  75. function tripal_data_uri(TripalData $entity){
  76. return array(
  77. 'path' => 'data/' . $entity->id,
  78. );
  79. }