local__source_data.inc 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. class local__source_data extends ChadoField {
  3. // --------------------------------------------------------------------------
  4. // EDITABLE STATIC CONSTANTS
  5. //
  6. // The following constants SHOULD be set for each descendent class. They are
  7. // used by the static functions to provide information to Drupal about
  8. // the field and it's default widget and formatter.
  9. // --------------------------------------------------------------------------
  10. // The default lable for this field.
  11. public static $default_label = 'Source of Data';
  12. // The default description for this field.
  13. public static $description = 'The source data used for this analysis.';
  14. // Provide a list of instance specific settings. These can be access within
  15. // the instanceSettingsForm. When the instanceSettingsForm is submitted
  16. // then Drupal with automatically change these settings for the instnace.
  17. // It is recommended to put settings at the instance level whenever possible.
  18. // If you override this variable in a child class be sure to replicate the
  19. // term_name, term_vocab, term_accession and term_fixed keys as these are
  20. // required for all TripalFields.
  21. public static $default_instance_settings = array(
  22. // The short name for the vocabulary (e.g. shcema, SO, GO, PATO, etc.).
  23. 'term_vocabulary' => 'local',
  24. // The name of the term.
  25. 'term_name' => 'source_data',
  26. // The unique ID (i.e. accession) of the term.
  27. 'term_accession' => 'source_data',
  28. // Set to TRUE if the site admin is allowed to change the term
  29. // type. This will create form elements when editing the field instance
  30. // to allow the site admin to change the term settings above.
  31. 'term_fixed' => FALSE,
  32. );
  33. // The default widget for this field.
  34. public static $default_widget = 'local__source_data_widget';
  35. // The default formatter for this field.
  36. public static $default_formatter = 'local__source_data_formatter';
  37. // --------------------------------------------------------------------------
  38. // PROTECTED CLASS MEMBERS -- DO NOT OVERRIDE
  39. // --------------------------------------------------------------------------
  40. // An array containing details about the field. The format of this array
  41. // is the same as that returned by field_info_fields()
  42. protected $field;
  43. // An array containing details about an instance of the field. A field does
  44. // not have to have an instance. But if dealing with an instance (such as
  45. // when using the widgetForm, formatterSettingsForm, etc.) it should be set.
  46. protected $instance;
  47. /**
  48. * @see TripalField::elementInfo()
  49. */
  50. public function elementInfo() {
  51. $field_term = $this->getFieldTermID();
  52. $sourcename_term = tripal_get_chado_semweb_term('analysis', 'sourcename');
  53. $sourceversion_term = tripal_get_chado_semweb_term('analysis', 'sourceversion');
  54. $sourceuri_term = tripal_get_chado_semweb_term('analysis', 'sourceuri');
  55. return array(
  56. $field_term => array(
  57. 'operations' => array(),
  58. 'sortable' => FALSE,
  59. 'searchable' => FALSE,
  60. 'elements' => array(
  61. $sourcename_term => array(
  62. 'searchable' => TRUE,
  63. 'label' => 'Data Source Name',
  64. 'help' => 'The name of the data source used for the analysis.',
  65. 'sortable' => TRUE,
  66. ),
  67. $sourceversion_term => array(
  68. 'searchable' => TRUE,
  69. 'label' => 'Data Source Version',
  70. 'help' => 'If applicable, the version number of the source data used for the analysis.',
  71. 'sortable' => TRUE,
  72. ),
  73. $sourceuri_term => array(
  74. 'searchable' => FALSE,
  75. 'label' => 'Data Source URI',
  76. 'help' => 'If applicable, the universal resource indicator (e.g. URL) of the source data used for the analysis.',
  77. 'sortable' => FALSE,
  78. ),
  79. ),
  80. ),
  81. );
  82. }
  83. /**
  84. * @see ChadoField::query()
  85. */
  86. public function query($query, $condition) {
  87. $operator = $condition['operator'];
  88. $field_term_id = $this->getFieldTermID();
  89. $sourcename_term = $field_term_id . ',' . tripal_get_chado_semweb_term('analysis', 'sourcename');
  90. $sourceversion_term = $field_term_id . ',' . tripal_get_chado_semweb_term('analysis', 'sourceversion');
  91. $sourceuri_term = $field_term_id . ',' . tripal_get_chado_semweb_term('analysis', 'sourceuri');
  92. if ($condition['column'] == $sourcename_term) {
  93. $query->condition("base.sourcename", $condition['value'], $operator);
  94. }
  95. if ($condition['column'] == $sourceversion_term) {
  96. $query->condition("base.sourceversion", $condition['value'], $operator);
  97. }
  98. }
  99. /**
  100. * @see ChadoField::queryOrder()
  101. */
  102. public function queryOrder($query, $order) {
  103. $field_term_id = $this->getFieldTermID();
  104. $sourcename_term = $field_term_id . ',' . tripal_get_chado_semweb_term('analysis', 'sourcename');
  105. $sourceversion_term = $field_term_id . ',' . tripal_get_chado_semweb_term('analysis', 'sourceversion');
  106. $sourceuri_term = $field_term_id . ',' . tripal_get_chado_semweb_term('analysis', 'sourceuri');
  107. if ($order['column'] == $sourcename_term) {
  108. $query->orderBy("base.sourcename", $order['direction']);
  109. }
  110. if ($order['column'] == $sourceversion_term) {
  111. $query->orderBy("base.sourceversion", $order['direction']);
  112. }
  113. }
  114. /**
  115. *
  116. * @see TripalField::load()
  117. */
  118. public function load($entity) {
  119. $analysis = $entity->chado_record;
  120. $field_name = $this->field['field_name'];
  121. $field_type = $this->field['type'];
  122. $field_table = $this->instance['settings']['chado_table'];
  123. $field_column = $this->instance['settings']['chado_column'];
  124. $sourcename_term = tripal_get_chado_semweb_term('analysis', 'sourcename');
  125. $sourceversion_term = tripal_get_chado_semweb_term('analysis', 'sourceversion');
  126. $sourceuri_term = tripal_get_chado_semweb_term('analysis', 'sourceuri');
  127. $entity->{$field_name}['und'][0] = array(
  128. 'value' => array(
  129. $sourcename_term => $analysis->sourcename,
  130. $sourceversion_term => $analysis->sourceversion,
  131. $sourceuri_term => $analysis->sourceuri,
  132. ),
  133. 'chado-analysis__sourcename' => $analysis->sourcename,
  134. 'chado-analysis__sourceversion' => $analysis->sourceversion,
  135. 'chado-analysis__sourceuri' => $analysis->sourceuri,
  136. );
  137. }
  138. }