tripal_natural_diversity.theme.inc 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Because the nd_experiment_id can be associated with projects, phenotypes,
  4. * stocks, genotypes, etc. it becomes slow to allow the template to use the
  5. * chado_expand_var function to traverse the FK relationships. Ideally
  6. * we would use the chado_expand_var function to only return a subset of
  7. * paged results. This function queries for all of the nd_experiment_genotypes
  8. * that share an nd_experiment_id with a stock
  9. *
  10. * @param $variables
  11. * The list of variables that will be passed into the template
  12. */
  13. function tripal_natural_diversity_preprocess_tripal_stock_nd_genotypes(&$variables) {
  14. $stock = $variables['node']->stock;
  15. // because the nd_experiment_id value can be used to associate projects, genotypes,
  16. // phenotypes, etc, we must do an inner join to only pull out those that
  17. // associate a stock to a genotype.
  18. $sql = "
  19. SELECT NDEG.nd_experiment_genotype_id
  20. FROM {nd_experiment_stock} NDES
  21. INNER JOIN {nd_experiment_genotype} NDEG ON NDEG.nd_experiment_id = NDES.nd_experiment_id
  22. WHERE NDES.stock_id = :stock_id
  23. ";
  24. $results = chado_query($sql, [':stock_id' => $stock->stock_id]);
  25. $nd_exp_ids = [];
  26. foreach ($results as $result) {
  27. $nd_exp_ids[] = $result->nd_experiment_genotype_id;
  28. }
  29. $stock->nd_experiment_genotype_ids = $nd_exp_ids;
  30. }
  31. /**
  32. * Because the nd_experiment_id can be associated with projects, phenotypes,
  33. * stocks, genotypes, etc. it becomes slow to allow the template to use the
  34. * chado_expand_var function to traverse the FK relationships. Ideally
  35. * we would use the chado_expand_var function to only return a subset of
  36. * paged results. This function queries for all of the nd_experiment_phenotypes
  37. * that share an nd_experiment_id with a stock
  38. *
  39. * @param $variables
  40. * The list of variables that will be passed into the template
  41. */
  42. function tripal_natural_diversity_preprocess_tripal_stock_nd_phenotypes(&$variables) {
  43. $stock = $variables['node']->stock;
  44. // because the nd_experiment_id value can be used to associate projects, phenotypes,
  45. // phenotypes, etc, we must do an inner join to only pull out those that
  46. // associate a stock to a phenotype.
  47. $sql = "
  48. SELECT NDEP.nd_experiment_phenotype_id
  49. FROM {nd_experiment_stock} NDES
  50. INNER JOIN {nd_experiment_phenotype} NDEP ON NDEP.nd_experiment_id = NDES.nd_experiment_id
  51. WHERE NDES.stock_id = :stock_id
  52. ";
  53. $results = chado_query($sql, [':stock_id' => $stock->stock_id]);
  54. $nd_exp_ids = [];
  55. foreach ($results as $result) {
  56. $nd_exp_ids[] = $result->nd_experiment_phenotype_id;
  57. }
  58. $stock->nd_experiment_phenotype_ids = $nd_exp_ids;
  59. }