tripal_stock.DEPRECATED.inc

  1. 2.x tripal_stock/api/tripal_stock.DEPRECATED.inc
  2. 3.x legacy/tripal_stock/api/tripal_stock.DEPRECATED.inc

Wrapper functions to provide backwards compatibility for the tripal stock api

File

legacy/tripal_stock/api/tripal_stock.DEPRECATED.inc
View source
  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 now.
  9. * 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. array(
  19. '%old_function'=>'tripal_stock_get_stock_by_nid',
  20. '%new_function' => 'tripal_get_stock'
  21. )
  22. );
  23. return tripal_get_stock(array('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 now.
  28. * 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. array(
  38. '%old_function'=>'tripal_stock_get_stock_by_stock_id',
  39. '%new_function' => 'tripal_get_stock'
  40. )
  41. );
  42. return tripal_get_stock(array('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 now.
  47. * 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. array(
  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 = array();
  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 now.
  75. * 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. array(
  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 now.
  94. * 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. array(
  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 now.
  114. * 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. array(
  136. '%old_function'=>'tripal_stock_get_stock_by_name_identifier',
  137. '%new_function' => 'tripal_get_stock'
  138. )
  139. );
  140. $stock_ids = array();
  141. $options = array(
  142. 'case_insensitive_columns' => array('name', 'uniquename', 'accession', 'value')
  143. );
  144. // where name_identifier = stock.name-------------------------------
  145. $current_stocks = chado_select_record('stock', array('stock_id'),
  146. array(
  147. 'name' => $name,
  148. 'organism_id' => $organism_id,
  149. ),
  150. array(
  151. 'case_insensitive_columns' => array('name'),
  152. )
  153. );
  154. if (!empty($current_stocks)) {
  155. foreach ($current_stocks as $c) {
  156. $stock_ids[] = $c->stock_id; }
  157. }
  158. // where name_identifier = stock.uniquename-------------------------------
  159. $current_stocks = chado_select_record('stock', array('stock_id'),
  160. array(
  161. 'uniquename' => $name,
  162. 'organism_id' => $organism_id,
  163. ),
  164. array(
  165. 'case_insensitive_columns' => array('uniquename'),
  166. )
  167. );
  168. if (!empty($current_stocks)) {
  169. foreach ($current_stocks as $c) {
  170. $stock_ids[] = $c->stock_id; }
  171. }
  172. // where name_identifier = dbxref.accession-------------------------------
  173. // linked to stock through stock.dbxref
  174. $current_stocks = chado_select_record('stock', array('stock_id'),
  175. array(
  176. 'dbxref_id' => array(
  177. 'accession' => $name,
  178. ),
  179. 'organism_id' => $organism_id,
  180. ),
  181. array(
  182. 'case_insensitive_columns' => array('accession'),
  183. )
  184. );
  185. if (!empty($current_stocks)) {
  186. foreach ($current_stocks as $c) {
  187. $stock_ids[] = $c->stock_id; }
  188. }
  189. // linked to stock through stock_dbxref?
  190. $current_stocks = chado_select_record('stock_dbxref', array('stock_id'),
  191. array(
  192. 'dbxref_id' => array(
  193. 'accession' => $name,
  194. ),
  195. 'stock_id' => array(
  196. 'organism_id' => $organism_id,
  197. ),
  198. ),
  199. array(
  200. 'case_insensitive_columns' => array('accession'),
  201. )
  202. );
  203. if (!empty($current_stocks)) {
  204. foreach ($current_stocks as $c) {
  205. $stock_ids[] = $c->stock_id;
  206. }
  207. }
  208. // where name_identifier = stockprop.value-------------------------------
  209. // where type='synonym'
  210. $current_stocks = chado_select_record('stockprop', array('stock_id'),
  211. array(
  212. 'stock_id' => array(
  213. 'organism_id' => $organism_id,
  214. ),
  215. 'type_id' => array(
  216. 'cv_id' => variable_get('chado_stock_prop_types_cv', 'null'),
  217. 'name' => 'synonym',
  218. ),
  219. 'value' => $name,
  220. ),
  221. array(
  222. 'case_insensitive_columns' => array('value'),
  223. )
  224. );
  225. if (!empty($current_stocks)) {
  226. foreach ($current_stocks as $c) {
  227. $stock_ids[] = $c->stock_id;
  228. }
  229. }
  230. // Change from stock_ids to nodes-----------------------------------
  231. $stock_ids = array_filter($stock_ids);
  232. $stock_ids = array_unique($stock_ids);
  233. $stocks = array();
  234. foreach ($stock_ids as $stock_id) {
  235. $node = tripal_stock_get_stock_by_stock_id($stock_id);
  236. if ($node) {
  237. $stocks[] = $node;
  238. }
  239. }
  240. return $stocks;
  241. }