uo__unit.inc 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. class uo__unit extends ChadoField {
  3. // The default lable for this field.
  4. public static $default_label = 'Unit';
  5. // The default description for this field.
  6. public static $description = 'The unit of measurement.';
  7. // Provide a list of instance specific settings. These can be access within
  8. // the instanceSettingsForm. When the instanceSettingsForm is submitted
  9. // then Drupal with automatically change these settings for the instnace.
  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 = array(
  15. // The short name for the vocabulary (e.g. shcema, SO, GO, PATO, etc.).
  16. 'term_vocabulary' => 'UO',
  17. // The name of the term.
  18. 'term_name' => 'unit',
  19. // The unique ID (i.e. accession) of the term.
  20. 'term_accession' => '0000000',
  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 = 'UO__unit_widget';
  28. // The default formatter for this field.
  29. public static $default_formatter = 'UO__unit_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. // Set some defaults for the empty record.
  41. $entity->{$field_name}['und'][0] = array(
  42. 'value' => '',
  43. );
  44. if ($record) {
  45. $entity->{$field_name}['und'][0]['value'] = $record->unittype_id->name;
  46. $entity->{$field_name}['und'][0]['chado-' . $field_table . '__unittype_id'] = $record->unittype_id->cvterm_id;
  47. $entity->{$field_name}['und'][0]['chado-cvterm__name'] = $record->unittype_id->name;
  48. $entity->{$field_name}['und'][0]['chado-cvterm__definition'] = $record->unittype_id->definition;
  49. $entity->{$field_name}['und'][0]['chado-cvterm__cv_id'] = $record->unittype_id->cv_id->cv_id;
  50. $entity->{$field_name}['und'][0]['chado-cv__name'] = $record->unittype_id->cv_id->name;
  51. }
  52. }
  53. /**
  54. * @see ChadoField::query()
  55. */
  56. public function query($query, $condition) {
  57. $chado_table = $this->instance['settings']['chado_table']; // featuremap
  58. $chado_field = $this->instance['settings']['chado_column']; // unittype_id
  59. $alias = $this->field['field_name'];
  60. $operator = $condition['operator'];
  61. $this->queryJoinOnce($query, 'cvterm', $alias, "base.$chado_field = $alias.cvterm_id");
  62. $query->condition("$alias.name", $condition['value'], $operator);
  63. }
  64. /**
  65. * @see ChadoField::query()
  66. */
  67. public function queryOrder($query, $order) {
  68. $chado_table = $this->instance['settings']['chado_table']; // featuremap
  69. $chado_field = $this->instance['settings']['chado_column']; // unittype_id
  70. $alias = $this->field['field_name'];
  71. $this->queryJoinOnce($query, 'cvterm', $alias, "base.$chado_field = $alias.cvterm_id");
  72. $query->orderBy("$alias.name", $order['direction']);
  73. }
  74. }