tripal_entities.api.inc 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /**
  3. * Menu argument loader; Load a chado data type by string.
  4. *
  5. * @param $type
  6. * The machine-readable name of a chado data type to load.
  7. * @return
  8. * A chado data type array or FALSE if $type does not exist.
  9. */
  10. function chado_data_type_load($type) {
  11. $entity = chado_data_get_types($type);
  12. return $entity;
  13. }
  14. /**
  15. * Gets an array of all chado_data types, keyed by the type name.
  16. *
  17. * @param $type_name
  18. * If set, the type with the given name is returned.
  19. * @return ChadoDataType[]
  20. * Depending whether $type isset, an array of chado_data types or a single one.
  21. */
  22. function chado_data_get_types($type_name = NULL) {
  23. // entity_load will get the Entity controller for our chado_data entity and call the load
  24. // function of that object - we are loading entities by name here.
  25. $types = entity_load_multiple_by_name('chado_data_type', isset($type_name) ? array($type_name) : FALSE);
  26. return isset($type_name) ? reset($types) : $types;
  27. }
  28. /**
  29. * Fetch a chado_data object. Make sure that the wildcard you choose
  30. * in the chado_data entity definition fits the function name here.
  31. *
  32. * @param $entity_id
  33. * Integer specifying the chado_data id.
  34. * @param $reset
  35. * A boolean indicating that the internal cache should be reset.
  36. * @return
  37. * A fully-loaded $chado_data object or FALSE if it cannot be loaded.
  38. *
  39. * @see chado_data_load_multiple()
  40. */
  41. function chado_data_load($entity_id, $reset = FALSE) {
  42. $chado_datas = chado_data_load_multiple(array($entity_id), array(), $reset);
  43. return reset($chado_datas);
  44. }
  45. /**
  46. * Load multiple chado_datas based on certain conditions.
  47. *
  48. * @param $entity_ids
  49. * An array of chado_data IDs.
  50. * @param $conditions
  51. * An array of conditions to match against the {chado_data} table.
  52. * @param $reset
  53. * A boolean indicating that the internal cache should be reset.
  54. * @return
  55. * An array of chado_data objects, indexed by entity_id.
  56. *
  57. * @see entity_load()
  58. * @see chado_data_load()
  59. */
  60. function chado_data_load_multiple($entity_ids = array(), $conditions = array(), $reset = FALSE) {
  61. return entity_load('chado_data', $entity_ids, $conditions, $reset);
  62. }
  63. /**
  64. * Deletes a chado_data.
  65. */
  66. function chado_data_delete(ChadoData $chado_data) {
  67. $chado_data->delete();
  68. }
  69. /**
  70. * Delete multiple chado_datas.
  71. *
  72. * @param $entity_ids
  73. * An array of chado_data IDs.
  74. */
  75. function chado_data_delete_multiple(array $entity_ids) {
  76. entity_get_controller('chado_data')->delete($entity_ids);
  77. }
  78. /**
  79. * Create a chado_data object.
  80. */
  81. function chado_data_create($values = array()) {
  82. return entity_get_controller('chado_data')->create($values);
  83. }
  84. function chado_data_type_create($values = array()) {
  85. return entity_get_controller('chado_data_type')->create($values);
  86. }
  87. /**
  88. * Saves a chado_data to the database.
  89. *
  90. * @param $chado_data
  91. * The chado_data object.
  92. */
  93. function chado_data_save(ChadoData $chado_data) {
  94. return $chado_data->save();
  95. }
  96. /**
  97. * Saves a chado_data type to the db.
  98. */
  99. function chado_data_type_save(ChadoDataType $type) {
  100. $type->save();
  101. }
  102. /**
  103. * Deletes a chado_data type from the db.
  104. */
  105. function chado_data_type_delete(ChadoDataType $type) {
  106. $type->delete();
  107. }
  108. /**
  109. * URI callback for chado_datas
  110. */
  111. function chado_data_uri(ChadoData $entity){
  112. return array(
  113. 'path' => 'data/' . $entity->entity_id,
  114. );
  115. }