tripal_library.api.inc 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?php
  2. /**
  3. * @file
  4. * @todo Add file header description
  5. */
  6. /**
  7. * @defgroup tripal_library_api Library Module API
  8. * @ingroup tripal_api
  9. * @ingroup tripal_library
  10. */
  11. /**
  12. * Implements hook_chado_library_schema()
  13. * Purpose: To add descriptions and foreign keys to default table description
  14. * Note: This array will be merged with the array from all other implementations
  15. *
  16. * @return
  17. * Array describing the library table
  18. *
  19. * @ingroup tripal_schema_api
  20. */
  21. function tripal_library_chado_library_schema() {
  22. $description = array();
  23. // Default table description in tripal_core.schema.api.inc: tripal_core_chado_feature_schema()
  24. $description['foreign keys']['organism'] = array(
  25. 'table' => 'organism',
  26. 'columns' => array(
  27. 'organism_id' => 'organism_id',
  28. ),
  29. );
  30. $description['foreign keys']['cvterm'] = array(
  31. 'table' => 'cvterm',
  32. 'columns' => array(
  33. 'type_id' => 'cvterm_id',
  34. ),
  35. );
  36. $referring_tables = array(
  37. 'library_cvterm',
  38. 'library_feature',
  39. 'library_pub',
  40. 'library_synonym',
  41. 'libraryprop'
  42. );
  43. $description['referring_tables'] = $referring_tables;
  44. return $description;
  45. }
  46. /**
  47. * Implements hook_chado_library_feature_schema()
  48. * Purpose: To add descriptions and foreign keys to default table description
  49. * Note: This array will be merged with the array from all other implementations
  50. *
  51. * @return
  52. * Array describing the library_feature table
  53. *
  54. * @ingroup tripal_schema_api
  55. */
  56. function tripal_library_chado_library_feature_schema() {
  57. $description = array();
  58. // Default table description in tripal_core.schema.api.inc: tripal_core_chado_library_feature_schema()
  59. $description['foreign keys']['library'] = array(
  60. 'table' => 'library',
  61. 'columns' => array(
  62. 'library_id' => 'library_id',
  63. ),
  64. );
  65. $description['foreign keys']['feature'] = array(
  66. 'table' => 'feature',
  67. 'columns' => array(
  68. 'feature_id' => 'feature_id',
  69. ),
  70. );
  71. return $description;
  72. }
  73. /**
  74. * Implements hook_chado_libraryprop_schema()
  75. * Purpose: To add descriptions and foreign keys to default table description
  76. * Note: This array will be merged with the array from all other implementations
  77. *
  78. * @return
  79. * Array describing the libraryprop table
  80. *
  81. * @ingroup tripal_schema_api
  82. */
  83. function tripal_library_chado_libraryprop_schema() {
  84. $description = array();
  85. // Default table description in tripal_core.schema.api.inc: tripal_core_chado_library_feature_schema()
  86. $description['foreign keys']['library'] = array(
  87. 'table' => 'library',
  88. 'columns' => array(
  89. 'library_id' => 'library_id',
  90. ),
  91. );
  92. $description['foreign keys']['cvterm'] = array(
  93. 'table' => 'cvterm',
  94. 'columns' => array(
  95. 'type_id' => 'cvterm_id',
  96. ),
  97. );
  98. return $description;
  99. }
  100. /**
  101. * Retrieve properties of a given type for a given library
  102. *
  103. * @param $library_id
  104. * The library_id of the properties you would like to retrieve
  105. * @param $property
  106. * The cvterm name of the properties to retrieve
  107. *
  108. * @return
  109. * An library chado variable with the specified properties expanded
  110. *
  111. * @ingroup tripal_library_api
  112. */
  113. function tripal_library_get_property($library_id, $property) {
  114. return tripal_core_get_property('library', $library_id, $property, 'tripal');
  115. }
  116. /**
  117. * Insert a given property
  118. *
  119. * @param $library_id
  120. * The library_id of the property to insert
  121. * @param $property
  122. * The cvterm name of the property to insert
  123. * @param $value
  124. * The value of the property to insert
  125. * @param $update_if_present
  126. * A boolean indicated whether to update the record if it's already present
  127. *
  128. * @return
  129. * True of success, False otherwise
  130. *
  131. * @ingroup tripal_library_api
  132. */
  133. function tripal_library_insert_property($library_id, $property, $value, $update_if_present = 0) {
  134. return tripal_core_insert_property('library', $library_id, $property, 'tripal', $value, $update_if_present);
  135. }
  136. /**
  137. * Update a given property
  138. *
  139. * @param $library_id
  140. * The library_id of the property to update
  141. * @param $property
  142. * The cvterm name of the property to update
  143. * @param $value
  144. * The value of the property to update
  145. * @param $insert_if_missing
  146. * A boolean indicated whether to insert the record if it's absent
  147. *
  148. * Note: The property will be identified using the unique combination of the $library_id and $property
  149. * and then it will be updated with the supplied value
  150. *
  151. * @return
  152. * True of success, False otherwise
  153. *
  154. * @ingroup tripal_library_api
  155. */
  156. function tripal_library_update_property($library_id, $property, $value, $insert_if_missing = 0) {
  157. return tripal_core_update_property('library', $library_id, $property, 'tripal', $value, $insert_if_missing);
  158. }
  159. /**
  160. * Delete a given property
  161. *
  162. * @param $library_id
  163. * The library_id of the property to delete
  164. * @param $property
  165. * The cvterm name of the property to delete
  166. *
  167. * Note: The property will be identified using the unique combination of the $library_id and $property
  168. * and then it will be deleted
  169. *
  170. * @return
  171. * True of success, False otherwise
  172. *
  173. * @ingroup tripal_library_api
  174. */
  175. function tripal_library_delete_property($library_id, $property) {
  176. return tripal_core_delete_property('library', $library_id, $property, 'tripal');
  177. }