ChadoField.inc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. // The module that manages this field.
  42. public static $module = 'tripal_chado';
  43. /**
  44. * Used to filter records that match a given condition.
  45. *
  46. * Entities can be filtered using the fields. This function should be
  47. * implemented if the field supports filtering. To provide filtering,
  48. * the $query object should be updated to including any joins and
  49. * conditions necessary. The following rules should be followed when
  50. * implementing this function:
  51. * - Try to implement a filter for every element of the 'value' array
  52. * returned by the load() function.
  53. * - However, avoid making filteres for non-indexed database columns.
  54. * - When giving alias to joined tables be sure to use aliases that are
  55. * unique to avoid conflicts with other fields.
  56. * - When joining with the base table its alias is 'base'.
  57. * - This function should never set the fields that should be returned
  58. * nor ordering or group by.
  59. * - You may join to materialized views if need be to help speed queries.
  60. *
  61. * @param $query
  62. * A SelectQuery object.
  63. * @param $condition
  64. * The field specific condition as set in the TripalFieldQuery object.
  65. */
  66. public function query($query, $condition) {
  67. }
  68. /**
  69. * Used to sort records that have been filtered.
  70. *
  71. * @param $query
  72. * A SelectQuery object.
  73. * @param $order
  74. * The field ordering as set in the TripalFieldQuery object. This function
  75. * should handle the ordering request as specified by this object.
  76. */
  77. public function queryOrder($query, $order) {
  78. }
  79. /**
  80. * @see TripalField::instanceSettingsForm()
  81. */
  82. public function instanceSettingsForm() {
  83. // Make sure we don't lose our Chado table mappings when the settings
  84. // are updated. Setting them as values in the form ensures they don't
  85. // get accidentally overwritten.
  86. $element['base_table'] = array(
  87. '#type' => 'value',
  88. '#value' => $this->instance['settings']['base_table'],
  89. );
  90. $element['chado_table'] = array(
  91. '#type' => 'value',
  92. '#value' => $this->instance['settings']['chado_table'],
  93. );
  94. $element['chado_column'] = array(
  95. '#type' => 'value',
  96. '#value' => $this->instance['settings']['chado_column'],
  97. );
  98. return $element;
  99. }
  100. }