ChadoField.inc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. class ChadoField extends TripalField {
  3. // The default lable for this field.
  4. public static $default_label = 'Chado Field';
  5. // The default description for this field.
  6. public static $default_description = 'The generic base class for all Chado fields. ' .
  7. 'Replace this text as appropriate for the child implementation.';
  8. // A list of global settings. These can be accessed witihn the
  9. // globalSettingsForm. When the globalSettingsForm is submitted then
  10. // Drupal will automatically change these settings for all fields.
  11. // Once instances exist for a field type then these settings cannot be
  12. // changed.
  13. public static $default_settings = array(
  14. 'storage' => 'field_chado_storage',
  15. );
  16. // Provide a list of instance specific settings. These can be access within
  17. // the instanceSettingsForm. When the instanceSettingsForm is submitted
  18. // then Drupal with automatically change these settings for the instnace.
  19. // It is recommended to put settings at the instance level whenever possible.
  20. // If you override this variable in a child class be sure to replicate the
  21. // term_name, term_vocab, term_accession and term_fixed keys as these are
  22. // required for all TripalFields.
  23. public static $default_instance_settings = array(
  24. // The short name for the vocabulary (e.g. shcema, SO, GO, PATO, etc.).
  25. 'term_vocabulary' => 'schema',
  26. // The name of the term.
  27. 'term_name' => 'Thing',
  28. // The unique ID (i.e. accession) of the term.
  29. 'term_accession' => 'Thing',
  30. // Set to TRUE if the site admin is allowed to change the term
  31. // type. This will create form elements when editing the field instance
  32. // to allow the site admin to change the term settings above.
  33. 'term_fixed' => FALSE,
  34. // The table in Chado that the instance maps to.
  35. 'chado_table' => '',
  36. // The column of the table in Chado where the value of the field comes from.
  37. 'chado_column' => '',
  38. // The base table.
  39. 'base_table' => '',
  40. );
  41. // By default our Chado fields are complicated and we only want to support
  42. // viewing them, and not filtering by them. Each field cand override as
  43. // needed.
  44. public static $default_view_handlers = array(
  45. 'field' => array(
  46. 'handler' => 'tripal_views_handler_field',
  47. 'click sortable' => TRUE,
  48. ),
  49. );
  50. // The module that manages this field.
  51. public static $module = 'tripal_chado';
  52. /**
  53. * @see TripalField::query()
  54. *
  55. * In addition to the rules to follow for the TripalField::query function
  56. * these should also be followed for the ChadoField::query implementation.
  57. *
  58. * - When giving alias to joined tables be sure to use aliases that are
  59. * unique to avoid conflicts with other fields.
  60. * - When joining with the base table its alias is 'base'.
  61. * - You may join to materialized views if need be to help speed queries.
  62. */
  63. public function query($query, $condition) {
  64. // If we are here it is because the child class did not implement the
  65. // query function. So, we will do our best to make the query work.
  66. $chado_table = $this->instance['settings']['chado_table'];
  67. $base_table = $this->instance['settings']['base_table'];
  68. $bschema = chado_get_schema($base_table);
  69. $bpkey = $bschema['primary key'][0];
  70. $alias = 'dbx_linker';
  71. $operator = $condition['operator'];
  72. // If the chado_table and the base_table are the same then this is easy.
  73. if ($chado_table == $base_table) {
  74. // Get the base table column that is associated with the term
  75. // passed as $condition['column'].
  76. $base_field = tripal_get_chado_semweb_column($chado_table, $condition['column']);
  77. $query->condition('base.' . $base_field , $condition['value'], $operator);
  78. }
  79. else {
  80. // If the two are not the same then we expect that the child class
  81. // will implement a query() function.
  82. }
  83. }
  84. /**
  85. * @see TripalField::queryOrder()
  86. */
  87. public function queryOrder($query, $order) {
  88. }
  89. /**
  90. * @see TripalField::instanceSettingsForm()
  91. */
  92. public function instanceSettingsForm() {
  93. // Make sure we don't lose our Chado table mappings when the settings
  94. // are updated. Setting them as values in the form ensures they don't
  95. // get accidentally overwritten.
  96. $element['base_table'] = array(
  97. '#type' => 'value',
  98. '#value' => $this->instance['settings']['base_table'],
  99. );
  100. $element['chado_table'] = array(
  101. '#type' => 'value',
  102. '#value' => $this->instance['settings']['chado_table'],
  103. );
  104. $element['chado_column'] = array(
  105. '#type' => 'value',
  106. '#value' => $this->instance['settings']['chado_column'],
  107. );
  108. return $element;
  109. }
  110. }