local__source_data.inc 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 label 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 accessed within
  15. // the instanceSettingsForm. When the instanceSettingsForm is submitted
  16. // then Drupal will automatically change these settings for the instance.
  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 = [
  22. // The short name for the vocabulary (e.g. schema, 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 = chado_get_semweb_term('analysis', 'sourcename');
  53. $sourceversion_term = chado_get_semweb_term('analysis', 'sourceversion');
  54. $sourceuri_term = chado_get_semweb_term('analysis', 'sourceuri');
  55. return [
  56. $field_term => [
  57. 'operations' => [],
  58. 'sortable' => FALSE,
  59. 'searchable' => FALSE,
  60. 'type' => 'xs:complexType',
  61. 'readonly' => TRUE,
  62. 'elements' => [
  63. $sourcename_term => [
  64. 'searchable' => TRUE,
  65. 'label' => 'Data Source Name',
  66. 'help' => 'The name of the data source used for the analysis.',
  67. 'sortable' => TRUE,
  68. 'type' => 'xs:string',
  69. 'readonly' => TRUE,
  70. 'required' => FALSE,
  71. ],
  72. $sourceversion_term => [
  73. 'searchable' => TRUE,
  74. 'label' => 'Data Source Version',
  75. 'help' => 'If applicable, the version number of the source data used for the analysis.',
  76. 'sortable' => TRUE,
  77. 'type' => 'xs:string',
  78. 'readonly' => TRUE,
  79. 'required' => FALSE,
  80. ],
  81. $sourceuri_term => [
  82. 'searchable' => FALSE,
  83. 'label' => 'Data Source URI',
  84. 'help' => 'If applicable, the universal resource indicator (e.g. URL) of the source data used for the analysis.',
  85. 'sortable' => FALSE,
  86. 'type' => 'xs:string',
  87. 'readonly' => TRUE,
  88. 'required' => FALSE,
  89. ],
  90. ],
  91. ],
  92. ];
  93. }
  94. /**
  95. * @see ChadoField::query()
  96. */
  97. public function query($query, $condition) {
  98. $operator = $condition['operator'];
  99. $field_term_id = $this->getFieldTermID();
  100. $sourcename_term = $field_term_id . ',' . chado_get_semweb_term('analysis', 'sourcename');
  101. $sourceversion_term = $field_term_id . ',' . chado_get_semweb_term('analysis', 'sourceversion');
  102. $sourceuri_term = $field_term_id . ',' . chado_get_semweb_term('analysis', 'sourceuri');
  103. if ($condition['column'] == $sourcename_term) {
  104. $query->condition("base.sourcename", $condition['value'], $operator);
  105. }
  106. if ($condition['column'] == $sourceversion_term) {
  107. $query->condition("base.sourceversion", $condition['value'], $operator);
  108. }
  109. }
  110. /**
  111. * @see ChadoField::queryOrder()
  112. */
  113. public function queryOrder($query, $order) {
  114. $field_term_id = $this->getFieldTermID();
  115. $sourcename_term = $field_term_id . ',' . chado_get_semweb_term('analysis', 'sourcename');
  116. $sourceversion_term = $field_term_id . ',' . chado_get_semweb_term('analysis', 'sourceversion');
  117. $sourceuri_term = $field_term_id . ',' . chado_get_semweb_term('analysis', 'sourceuri');
  118. if ($order['column'] == $sourcename_term) {
  119. $query->orderBy("base.sourcename", $order['direction']);
  120. }
  121. if ($order['column'] == $sourceversion_term) {
  122. $query->orderBy("base.sourceversion", $order['direction']);
  123. }
  124. }
  125. /**
  126. *
  127. * @see TripalField::load()
  128. */
  129. public function load($entity) {
  130. $analysis = $entity->chado_record;
  131. $field_name = $this->field['field_name'];
  132. $field_type = $this->field['type'];
  133. $field_table = $this->instance['settings']['chado_table'];
  134. $field_column = $this->instance['settings']['chado_column'];
  135. $sourcename_term = chado_get_semweb_term('analysis', 'sourcename');
  136. $sourceversion_term = chado_get_semweb_term('analysis', 'sourceversion');
  137. $sourceuri_term = chado_get_semweb_term('analysis', 'sourceuri');
  138. $entity->{$field_name}['und'][0] = [
  139. 'value' => [
  140. $sourcename_term => $analysis->sourcename,
  141. $sourceversion_term => $analysis->sourceversion,
  142. $sourceuri_term => $analysis->sourceuri,
  143. ],
  144. 'chado-analysis__sourcename' => $analysis->sourcename,
  145. 'chado-analysis__sourceversion' => $analysis->sourceversion,
  146. 'chado-analysis__sourceuri' => $analysis->sourceuri,
  147. ];
  148. }
  149. }