tripal_stock.DEPRECATED.inc 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <?php
  2. /**
  3. * @file
  4. * Wrapper functions to provide backwards compatibility for the tripal stock api
  5. */
  6. /**
  7. * @deprecated Restructured API to make naming more readable and consistent.
  8. * Function was deprecated in Tripal 2.0 and will be removed 2 releases from
  9. * now. This function has been replaced by tripal_get_stock().
  10. *
  11. * @see tripal_get_stock().
  12. */
  13. function tripal_stock_get_stock_by_nid($nid) {
  14. tripal_report_error(
  15. 'tripal_deprecated',
  16. TRIPAL_NOTICE,
  17. "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
  18. [
  19. '%old_function' => 'tripal_stock_get_stock_by_nid',
  20. '%new_function' => 'tripal_get_stock',
  21. ]
  22. );
  23. return tripal_get_stock(['nid' => $nid]);
  24. }
  25. /**
  26. * @deprecated Restructured API to make naming more readable and consistent.
  27. * Function was deprecated in Tripal 2.0 and will be removed 2 releases from
  28. * now. This function has been replaced by tripal_get_stock().
  29. *
  30. * @see tripal_get_stock().
  31. */
  32. function tripal_stock_get_stock_by_stock_id($stock_id) {
  33. tripal_report_error(
  34. 'tripal_deprecated',
  35. TRIPAL_NOTICE,
  36. "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
  37. [
  38. '%old_function' => 'tripal_stock_get_stock_by_stock_id',
  39. '%new_function' => 'tripal_get_stock',
  40. ]
  41. );
  42. return tripal_get_stock(['stock_id' => $stock_id]);
  43. }
  44. /**
  45. * @deprecated Restructured API to make naming more readable and consistent.
  46. * Function was deprecated in Tripal 2.0 and will be removed 2 releases from
  47. * now. This function has been replaced by tripal_get_multiple_stocks().
  48. *
  49. * @see tripal_get_multiple_stocks().
  50. */
  51. function tripal_stock_get_all_stocks() {
  52. tripal_report_error(
  53. 'tripal_deprecated',
  54. TRIPAL_NOTICE,
  55. "DEPRECATED: %old_function has been completely deprecated. There are often so many
  56. stocks in a chado database that it is unlikely a user really wants all of them.",
  57. [
  58. '%old_function' => 'tripal_stock_get_all_stocks',
  59. ]
  60. );
  61. $sql = "SELECT stock_id, nid from {chado_stock}";
  62. $resource = db_query($sql);
  63. $stocks = [];
  64. while ($r = $resource->fetchObject()) {
  65. $node = node_load($r->nid);
  66. if ($node) {
  67. $stocks[$r->stock_id] = $node;
  68. }
  69. }
  70. return $stocks;
  71. }
  72. /**
  73. * @deprecated Restructured API to make naming more readable and consistent.
  74. * Function was deprecated in Tripal 2.0 and will be removed 2 releases from
  75. * now. This function has been replaced by tripal_get_multiple_stocks().
  76. *
  77. * @see tripal_get_multiple_stocks().
  78. */
  79. function tripal_stock_get_stocks($values) {
  80. tripal_report_error(
  81. 'tripal_deprecated',
  82. TRIPAL_NOTICE,
  83. "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
  84. [
  85. '%old_function' => 'tripal_stock_get_stocks',
  86. '%new_function' => 'tripal_get_multiple_stocks',
  87. ]
  88. );
  89. return tripal_get_multiple_stocks($values);
  90. }
  91. /**
  92. * @deprecated Restructured API to make naming more readable and consistent.
  93. * Function was deprecated in Tripal 2.0 and will be removed 2 releases from
  94. * now. This function has been replaced by tripal_get_stock().
  95. *
  96. * @see tripal_get_stock().
  97. */
  98. function tripal_stock_get_stocks_by_stockprop($stockprop_values, $stock_values) {
  99. tripal_report_error(
  100. 'tripal_deprecated',
  101. TRIPAL_NOTICE,
  102. "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
  103. [
  104. '%old_function' => 'tripal_stock_get_stocks_by_stockprop',
  105. '%new_function' => 'tripal_get_stock',
  106. ]
  107. );
  108. $stock_values['property'] = $stockprop_values;
  109. return tripal_get_multiple_stocks($stock_values);
  110. }
  111. /**
  112. * @deprecated Restructured API to make naming more readable and consistent.
  113. * Function was deprecated in Tripal 2.0 and will be removed 2 releases from
  114. * now. This function has been replaced by tripal_get_stock().
  115. *
  116. * Return all stocks with a given name identifier
  117. * which might match stock.name, stock.uniquename, dbxref.accession,
  118. * stockprop.value where stockprop.type='synonym'
  119. *
  120. * @param $name
  121. * The name identfier to be used
  122. * @param $organism_id
  123. * The stock.organism_id of the stock to be selected
  124. *
  125. * @return
  126. * An array of stock node objects
  127. *
  128. * @see tripal_get_stock().
  129. */
  130. function tripal_stock_get_stock_by_name_identifier($name, $organism_id) {
  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_stock_get_stock_by_name_identifier',
  137. '%new_function' => 'tripal_get_stock',
  138. ]
  139. );
  140. $stock_ids = [];
  141. $options = [
  142. 'case_insensitive_columns' => ['name', 'uniquename', 'accession', 'value'],
  143. ];
  144. // where name_identifier = stock.name-------------------------------
  145. $current_stocks = chado_select_record('stock', ['stock_id'],
  146. [
  147. 'name' => $name,
  148. 'organism_id' => $organism_id,
  149. ],
  150. [
  151. 'case_insensitive_columns' => ['name'],
  152. ]
  153. );
  154. if (!empty($current_stocks)) {
  155. foreach ($current_stocks as $c) {
  156. $stock_ids[] = $c->stock_id;
  157. }
  158. }
  159. // where name_identifier = stock.uniquename-------------------------------
  160. $current_stocks = chado_select_record('stock', ['stock_id'],
  161. [
  162. 'uniquename' => $name,
  163. 'organism_id' => $organism_id,
  164. ],
  165. [
  166. 'case_insensitive_columns' => ['uniquename'],
  167. ]
  168. );
  169. if (!empty($current_stocks)) {
  170. foreach ($current_stocks as $c) {
  171. $stock_ids[] = $c->stock_id;
  172. }
  173. }
  174. // where name_identifier = dbxref.accession-------------------------------
  175. // linked to stock through stock.dbxref
  176. $current_stocks = chado_select_record('stock', ['stock_id'],
  177. [
  178. 'dbxref_id' => [
  179. 'accession' => $name,
  180. ],
  181. 'organism_id' => $organism_id,
  182. ],
  183. [
  184. 'case_insensitive_columns' => ['accession'],
  185. ]
  186. );
  187. if (!empty($current_stocks)) {
  188. foreach ($current_stocks as $c) {
  189. $stock_ids[] = $c->stock_id;
  190. }
  191. }
  192. // linked to stock through stock_dbxref?
  193. $current_stocks = chado_select_record('stock_dbxref', ['stock_id'],
  194. [
  195. 'dbxref_id' => [
  196. 'accession' => $name,
  197. ],
  198. 'stock_id' => [
  199. 'organism_id' => $organism_id,
  200. ],
  201. ],
  202. [
  203. 'case_insensitive_columns' => ['accession'],
  204. ]
  205. );
  206. if (!empty($current_stocks)) {
  207. foreach ($current_stocks as $c) {
  208. $stock_ids[] = $c->stock_id;
  209. }
  210. }
  211. // where name_identifier = stockprop.value-------------------------------
  212. // where type='synonym'
  213. $current_stocks = chado_select_record('stockprop', ['stock_id'],
  214. [
  215. 'stock_id' => [
  216. 'organism_id' => $organism_id,
  217. ],
  218. 'type_id' => [
  219. 'cv_id' => variable_get('chado_stock_prop_types_cv', 'null'),
  220. 'name' => 'synonym',
  221. ],
  222. 'value' => $name,
  223. ],
  224. [
  225. 'case_insensitive_columns' => ['value'],
  226. ]
  227. );
  228. if (!empty($current_stocks)) {
  229. foreach ($current_stocks as $c) {
  230. $stock_ids[] = $c->stock_id;
  231. }
  232. }
  233. // Change from stock_ids to nodes-----------------------------------
  234. $stock_ids = array_filter($stock_ids);
  235. $stock_ids = array_unique($stock_ids);
  236. $stocks = [];
  237. foreach ($stock_ids as $stock_id) {
  238. $node = tripal_stock_get_stock_by_stock_id($stock_id);
  239. if ($node) {
  240. $stocks[] = $node;
  241. }
  242. }
  243. return $stocks;
  244. }