tripal_cv.feature.inc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. *
  4. *
  5. */
  6. class TrpFeatureController extends DrupalDefaultEntityController {
  7. /**
  8. *
  9. * @param $ids
  10. * An array of entity IDs, or FALSE to load all entities.
  11. * @param $conditions
  12. * DEPRECATED. An array of conditions. Keys are field names on the entity's
  13. * base table.Values will be compared for equality. All the comparisons will
  14. * be ANDed together. This parameter is deprecated; use an EntityFieldQuery
  15. * instead.
  16. * @return multitype:An
  17. */
  18. public function load($ids = array(), $conditions = array()) {
  19. $entities = array();
  20. $queried_entities = array();
  21. $values = array('feature_id' => $ids);
  22. $options = array('return_array' => TRUE);
  23. $features = chado_generate_var('feature', $values, $options);
  24. foreach ($features as $result) {
  25. $feature = new stdClass();
  26. $feature->internal_id = $result->feature_id;
  27. $feature->type_id = $result->type_id->dbxref_id->db_id->name . ':' . $result->type_id->dbxref_id->accession;
  28. // Add the names by which this feature is known.
  29. $names = array();
  30. $names[] = $result->name;
  31. $names[] = $result->uniquename;
  32. $feature->name = array_unique($names);
  33. // Add in the synonyms.
  34. $sql = "
  35. SELECT *
  36. FROM {feature_synonym} FS
  37. INNER JOIN {synonym} S ON FS.synonym_id = S.synonym_id
  38. WHERE FS.feature_id = :feature_id
  39. ";
  40. $synonym_results = chado_query($sql, array(':feature_id' => $result->feature_id));
  41. $synonyms = array();
  42. while ($synonym = $synonym_results->fetchObject()) {
  43. $synonyms[] = $synonym->name;
  44. }
  45. if (count($synonyms) > 0) {
  46. $feature->synonyms = $synonyms;
  47. }
  48. // Add in database cross-references.
  49. $xrefs = array();
  50. if ($result->dbxref_id) {
  51. $xrefs[] = $result->dbxref_id->db_id->name . ':' . $result->dbxref_id->accession;
  52. }
  53. $sql = "
  54. SELECT DB.name as namespace, DBX.accession
  55. FROM {feature_dbxref} FDBX
  56. INNER JOIN {dbxref} DBX ON DBX.dbxref_id = FDBX.dbxref_id
  57. INNER JOIN {db} DB ON DB.db_id = DBX.db_id
  58. WHERE FDBX.feature_id = :feature_id
  59. ";
  60. $dbxref_results = chado_query($sql, array(':feature_id' => $result->feature_id));
  61. while ($dbxref = $dbxref_results->fetchObject()) {
  62. if ($dbxref->namespace != 'GFF_source') {
  63. $xrefs[] = $dbxref->namespace . ':' . $dbxref->accession;
  64. }
  65. }
  66. if (count($xrefs) > 0) {
  67. $feature->xref_id = $xrefs;
  68. }
  69. // Add in the expand array
  70. $expand = array();
  71. $expand[] = 'chado:organism';
  72. $feature->expand = $expand;
  73. // Add in the embeded elements
  74. $embedded = array();
  75. $embedded['chado:organism'] = entity_load('trp_organism', array($result->organism_id->organism_id));
  76. $feature->embedded = $embedded;
  77. $queried_entities[$feature->internal_id] = $feature;
  78. }
  79. // Pass all entities loaded from the database through $this->attachLoad(),
  80. // which attaches fields (if supported by the entity type) and calls the
  81. // entity type specific load callback, for example hook_node_load().
  82. if (!empty($queried_entities)) {
  83. // $this->attachLoad($queried_entities);
  84. $entities += $queried_entities;
  85. }
  86. // Ensure that the returned array is ordered the same as the original
  87. // $ids array if this was passed in and remove any invalid ids.
  88. return $entities;
  89. }
  90. }