operation__analysis.inc 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. class operation__analysis extends ChadoField {
  3. // The default label for this field.
  4. public static $default_label = 'Analysis';
  5. // The default description for this field.
  6. public static $description = 'Application of analytical methods to existing data of a specific type.';
  7. // Provide a list of instance specific settings. These can be accessed within
  8. // the instanceSettingsForm. When the instanceSettingsForm is submitted
  9. // then Drupal will automatically change these settings for the instance.
  10. // It is recommended to put settings at the instance level whenever possible.
  11. // If you override this variable in a child class be sure to replicate the
  12. // term_name, term_vocab, term_accession and term_fixed keys as these are
  13. // required for all TripalFields.
  14. public static $default_instance_settings = [
  15. // The short name for the vocabulary (e.g. schema, SO, GO, PATO, etc.).
  16. 'term_vocabulary' => 'operation',
  17. // The name of the term.
  18. 'term_name' => 'Analysis',
  19. // The unique ID (i.e. accession) of the term.
  20. 'term_accession' => '2945',
  21. // Set to TRUE if the site admin is allowed to change the term
  22. // type. This will create form elements when editing the field instance
  23. // to allow the site admin to change the term settings above.
  24. 'term_fixed' => FALSE,
  25. ];
  26. // The default widget for this field.
  27. public static $default_widget = 'operation__analysis_widget';
  28. // The default formatter for this field.
  29. public static $default_formatter = 'operation__analysis_formatter';
  30. /**
  31. * @see TripalField::load()
  32. */
  33. public function load($entity) {
  34. $record = $entity->chado_record;
  35. $settings = $this->instance['settings'];
  36. $field_name = $this->field['field_name'];
  37. $field_type = $this->field['type'];
  38. $field_table = $this->instance['settings']['chado_table'];
  39. $field_column = $this->instance['settings']['chado_column'];
  40. // Get the terms for each of the keys for the 'values' property.
  41. $name_term = chado_get_semweb_term('analysis', 'name');
  42. // Set some defaults for the empty record.
  43. $entity->{$field_name}['und'][0] = [
  44. 'value' => [],
  45. ];
  46. if (!$record or !$record->analysis_id) {
  47. return;
  48. }
  49. $linker_field = 'chado-' . $field_table . '__' . $field_column;
  50. $entity->{$field_name}['und'][0]['value'] = [
  51. $name_term => $record->{$field_column}->name,
  52. ];
  53. $entity->{$field_name}['und'][0][$linker_field] = $record->{$field_column}->analysis_id;
  54. // Is there a published entity for this analysis?
  55. if (property_exists($record->{$field_column}, 'entity_id')) {
  56. $entity->{$field_name}['und'][0]['value']['entity'] = 'TripalEntity:' . $record->{$field_column}->entity_id;
  57. }
  58. }
  59. /**
  60. * @see TripalField::elementInfo()
  61. */
  62. public function elementInfo() {
  63. $field_term = $this->getFieldTermID();
  64. $name_term = chado_get_semweb_term('analysis', 'name');
  65. return [
  66. $field_term => [
  67. 'operations' => ['eq', 'contains', 'starts'],
  68. 'sortable' => TRUE,
  69. 'searchable' => TRUE,
  70. 'readonly' => FALSE,
  71. 'type' => 'xs:complexType',
  72. 'elements' => [
  73. $name_term => [
  74. 'searchable' => TRUE,
  75. 'name' => 'name',
  76. 'operations' => ['eq', 'ne', 'contains', 'starts'],
  77. 'sortable' => FALSE,
  78. 'type' => 'xs:string',
  79. 'readonly' => TRUE,
  80. 'required' => FALSE,
  81. ],
  82. 'entity' => [
  83. 'searchable' => FALSE,
  84. ],
  85. ],
  86. ],
  87. ];
  88. }
  89. /**
  90. * @see ChadoField::query()
  91. */
  92. public function query($query, $condition) {
  93. $alias = $this->field['field_name'];
  94. $operator = $condition['operator'];
  95. $field_term_id = $this->getFieldTermID();
  96. $name_term = $field_term_id . ',' . chado_get_semweb_term('analysis', 'name');
  97. // Join to the organism table for this field.
  98. $this->queryJoinOnce($query, 'analysis', $alias, "base.analysis_id = $alias.analysis_id");
  99. // If the column is the field name then we're during a search on the full
  100. // scientific name.
  101. if ($condition['column'] == $field_term_id or
  102. $condition['column'] == $name_term) {
  103. $query->condition("$alias.name", $condition['value'], $operator);
  104. }
  105. }
  106. /**
  107. * @see ChadoField::queryOrder()
  108. */
  109. public function queryOrder($query, $order) {
  110. $alias = $this->field['field_name'];
  111. $field_term_id = $this->getFieldTermID();
  112. $name_term = $field_term_id . ',' . chado_get_semweb_term('analysis', 'name');
  113. // Join to the organism table for this field.
  114. $this->queryJoinOnce($query, 'analysis', $alias, "base.analysis_id = $alias.analysis_id");
  115. // Now perform the sort.
  116. if ($order['column'] == $name_term) {
  117. $query->orderBy("$alias.name", $order['direction']);
  118. }
  119. }
  120. }