tripal_entities.api.inc 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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($type) {
  11. $entity = tripal_data_get_types($type);
  12. return $entity;
  13. }
  14. /**
  15. * Gets an array of all tripal_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 TripalDataType[]
  20. * Depending whether $type isset, an array of tripal_data types or a single one.
  21. */
  22. function tripal_data_get_types($type_name = NULL) {
  23. // entity_load will get the Entity controller for our tripal_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('tripal_data_type', isset($type_name) ? array($type_name) : FALSE);
  26. return isset($type_name) ? reset($types) : $types;
  27. }
  28. /**
  29. * Fetch a tripal_data object. Make sure that the wildcard you choose
  30. * in the tripal_data entity definition fits the function name here.
  31. *
  32. * @param $entity_id
  33. * Integer specifying the tripal_data id.
  34. * @param $reset
  35. * A boolean indicating that the internal cache should be reset.
  36. * @return
  37. * A fully-loaded $tripal_data object or FALSE if it cannot be loaded.
  38. *
  39. * @see tripal_data_load_multiple()
  40. */
  41. function tripal_data_load($entity_id, $reset = FALSE) {
  42. $tripal_datas = tripal_data_load_multiple(array($entity_id), array(), $reset);
  43. return reset($tripal_datas);
  44. }
  45. /**
  46. * Load multiple tripal_datas based on certain conditions.
  47. *
  48. * @param $entity_ids
  49. * An array of tripal_data IDs.
  50. * @param $conditions
  51. * An array of conditions to match against the entity table.
  52. * @param $reset
  53. * A boolean indicating that the internal cache should be reset.
  54. * @return
  55. * An array of tripal_data objects, indexed by entity_id.
  56. *
  57. * @see entity_load()
  58. * @see tripal_data_load()
  59. */
  60. function tripal_data_load_multiple($entity_ids = array(), $conditions = array(), $reset = FALSE) {
  61. return entity_load('tripal_data', $entity_ids, $conditions, $reset);
  62. }
  63. /**
  64. * Deletes a tripal_data.
  65. */
  66. function tripal_data_delete(TripalData $tripal_data) {
  67. $tripal_data->delete();
  68. }
  69. /**
  70. * Delete multiple tripal_datas.
  71. *
  72. * @param $entity_ids
  73. * An array of tripal_data IDs.
  74. */
  75. function tripal_data_delete_multiple(array $entity_ids) {
  76. entity_get_controller('tripal_data')->delete($entity_ids);
  77. }
  78. /**
  79. * Create a tripal_data object.
  80. */
  81. function tripal_data_create($values = array()) {
  82. return entity_get_controller('tripal_data')->create($values);
  83. }
  84. function tripal_data_type_create($values = array()) {
  85. return entity_get_controller('tripal_data_type')->create($values);
  86. }
  87. /**
  88. * Saves a tripal_data to the database.
  89. *
  90. * @param $tripal_data
  91. * The tripal_data object.
  92. */
  93. function tripal_data_save(TripalData $tripal_data) {
  94. return $tripal_data->save();
  95. }
  96. /**
  97. * Saves a tripal_data type to the db.
  98. */
  99. function tripal_data_type_save(TripalDataType $type) {
  100. $type->save();
  101. }
  102. /**
  103. * Deletes a tripal_data type from the db.
  104. */
  105. function tripal_data_type_delete(TripalDataType $type) {
  106. $type->delete();
  107. }
  108. /**
  109. * URI callback for tripal_datas
  110. */
  111. function tripal_data_uri(TripalData $entity){
  112. return array(
  113. 'path' => 'data/' . $entity->entity_id,
  114. );
  115. }