tripal_featuremap.DEPRECATED.inc 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?php
  2. /**
  3. * @file
  4. * Wrapper functions to provide backwards compatibility for the tripal
  5. * featuremap api
  6. */
  7. /**
  8. * @deprecated Restructured API to make naming more readable and consistent.
  9. * Function was deprecated in Tripal 2.0 and will be removed 2 releases from
  10. * now. This function has been replaced by chado_get_property().
  11. *
  12. * @see chado_get_property().
  13. */
  14. function tripal_featuremap_get_property($featuremap_id, $property) {
  15. tripal_report_error(
  16. 'tripal_deprecated',
  17. TRIPAL_NOTICE,
  18. "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
  19. [
  20. '%old_function' => 'tripal_featuremap_get_property',
  21. '%new_function' => 'chado_get_property',
  22. ]
  23. );
  24. $record = [
  25. 'table' => 'featuremap',
  26. 'id' => $featuremap_id,
  27. ];
  28. $property = [
  29. 'type_name' => $property,
  30. 'cv_name' => 'featuremap_property',
  31. ];
  32. return chado_get_property($record, $property);
  33. }
  34. /**
  35. * @deprecated Restructured API to make naming more readable and consistent.
  36. * Function was deprecated in Tripal 2.0 and will be removed 2 releases from
  37. * now. This function has been replaced by chado_insert_property().
  38. *
  39. * @see chado_insert_property().
  40. */
  41. function tripal_featuremap_insert_property($featuremap_id, $property, $value, $update_if_present = 0) {
  42. tripal_report_error(
  43. 'tripal_deprecated',
  44. TRIPAL_NOTICE,
  45. "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
  46. [
  47. '%old_function' => 'tripal_featuremap_insert_property',
  48. '%new_function' => 'chado_insert_property',
  49. ]
  50. );
  51. $record = [
  52. 'table' => 'featuremap',
  53. 'id' => $featuremap_id,
  54. ];
  55. $property = [
  56. 'type_name' => $property,
  57. 'cv_name' => 'featuremap_property',
  58. 'value' => $value,
  59. ];
  60. $options = [
  61. 'update_if_present' => $update_if_present,
  62. ];
  63. return chado_insert_property($record, $property, $options);
  64. }
  65. /**
  66. * @deprecated Restructured API to make naming more readable and consistent.
  67. * Function was deprecated in Tripal 2.0 and will be removed 2 releases from
  68. * now. This function has been replaced by chado_update_property().
  69. *
  70. * @see chado_update_property().
  71. */
  72. function tripal_featuremap_update_property($featuremap_id, $property, $value, $insert_if_missing = 0) {
  73. tripal_report_error(
  74. 'tripal_deprecated',
  75. TRIPAL_NOTICE,
  76. "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
  77. [
  78. '%old_function' => 'tripal_featuremap_update_property',
  79. '%new_function' => 'chado_update_property',
  80. ]
  81. );
  82. $record = [
  83. 'table' => 'featuremap',
  84. 'id' => $featuremap_id,
  85. ];
  86. $property = [
  87. 'type_name' => $property,
  88. 'cv_name' => 'featuremap_property',
  89. 'value' => $value,
  90. ];
  91. $options = [
  92. 'insert_if_missing' => $insert_if_missing,
  93. ];
  94. return chado_update_property($record, $property, $options);
  95. }
  96. /**
  97. * @deprecated Restructured API to make naming more readable and consistent.
  98. * Function was deprecated in Tripal 2.0 and will be removed 2 releases from
  99. * now. This function has been replaced by chado_delete_property().
  100. *
  101. * @see chado_delete_property().
  102. */
  103. function tripal_featuremap_delete_property($featuremap_id, $property) {
  104. tripal_report_error(
  105. 'tripal_deprecated',
  106. TRIPAL_NOTICE,
  107. "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
  108. [
  109. '%old_function' => 'tripal_featuremap_delete_property',
  110. '%new_function' => 'chado_delete_property',
  111. ]
  112. );
  113. $record = [
  114. 'table' => 'featuremap',
  115. 'id' => $featuremap_id,
  116. ];
  117. $property = [
  118. 'type_name' => $property,
  119. 'cv_name' => 'featuremap_property',
  120. ];
  121. return chado_delete_property($record, $property);
  122. }
  123. /**
  124. * @deprecated Restructured API to make naming more readable and consistent.
  125. * Function was deprecated in Tripal 2.0 and will be removed 2 releases from
  126. * now. This function has been replaced by chado_associate_dbxref().
  127. *
  128. * @see chado_associate_dbxref().
  129. */
  130. function tripal_featuremap_add_featuremap_dbxref($featuremap_id, $featuremap_dbxref) {
  131. tripal_report_error(
  132. 'tripal_deprecated',
  133. TRIPAL_NOTICE,
  134. "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
  135. [
  136. '%old_function' => 'tripal_featuremap_add_featuremap_dbxref',
  137. '%new_function' => 'chado_associate_dbxref',
  138. ]
  139. );
  140. // break apart the dbxref
  141. $dbname = '';
  142. $accession = '';
  143. if (preg_match('/^(.*?):(.*?)$/', $featuremap_dbxref, $matches)) {
  144. $dbname = $matches[1];
  145. $accession = $matches[2];
  146. }
  147. else {
  148. return FALSE;
  149. }
  150. // check to see if the featuremap_dbxref record already exist
  151. $values = [
  152. 'dbxref_id' => [
  153. 'accession' => $accession,
  154. 'db_id' => [
  155. 'name' => $dbname,
  156. ],
  157. ],
  158. 'featuremap_id' => $featuremap_id,
  159. ];
  160. $options = ['statement_name' => 'sel_featuremapdbxref_dbpu'];
  161. $results = chado_select_record('featuremap_dbxref', ['*'], $values, $options);
  162. // if the featuremap_dbxref record exist then we don't need to re-add it.
  163. if (count($results) > 0) {
  164. return $results[0];
  165. }
  166. // make sure our database already exists
  167. $db = tripal_db_add_db($dbname);
  168. // get the database cross-reference
  169. $dbxvalues = [
  170. 'accession' => $accession,
  171. 'db_id' => $db->db_id,
  172. ];
  173. $dbxoptions = ['statement_name' => 'sel_dbxref_acdb'];
  174. $results = chado_select_record('dbxref', ['dbxref_id'], $dbxvalues, $dbxoptions);
  175. // if the accession doesn't exist then add it
  176. if (count($results) == 0) {
  177. $dbxref = tripal_db_add_dbxref($db->db_id, $accession);
  178. }
  179. else {
  180. $dbxref = $results[0];
  181. }
  182. // now add the record
  183. $options = ['statement_name' => 'ins_featuremapdbxref_dbpu'];
  184. $results = chado_insert_record('featuremap_dbxref', $values, $options);
  185. if (!$results) {
  186. tripal_report_error('t_featuremap', TRIPAL_ERROR, "Cannot add map dbxref: %db:%accession.",
  187. ['%db' => $dbname, '%accession' => $accession]);
  188. return FALSE;
  189. }
  190. return $results;
  191. }