123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- <?php
- class sep__protocol extends ChadoField {
-
- public static $default_label = 'Protocol';
-
- public static $default_description = 'The protocol followed to generate this resource.';
-
- public static $default_widget = 'sep__protocol_widget';
-
- public static $default_formatter = 'sep__protocol_formatter';
-
- public static $module = 'tripal_chado';
-
-
-
-
-
- public static $default_settings = [
- 'storage' => 'field_chado_storage',
-
-
-
-
-
-
- 'searchable_keys' => [],
- ];
-
-
-
-
-
-
-
- public static $default_instance_settings = [
-
- 'term_vocabulary' => 'sep',
-
- 'term_name' => 'protocol',
-
- 'term_accession' => '00101',
-
-
- 'term_fixed' => FALSE,
-
-
-
-
-
- 'auto_attach' => FALSE,
- ];
-
-
-
-
- public static $no_ui = FALSE;
-
-
-
-
- public static $no_data = FALSE;
-
- public function load($entity) {
- parent::load($entity);
- $record = $entity->chado_record;
- $settings = $this->instance['settings'];
- $field_name = $this->field['field_name'];
- $field_type = $this->field['type'];
- $field_table = $this->instance['settings']['chado_table'];
- $field_column = $this->instance['settings']['chado_column'];
- $base_table = $this->instance['settings']['base_table'];
- $linker_field = 'chado-' . $field_table . '__' . $field_column;
- if (!$record) {
- return;
- }
-
- $protocol = $record->{$field_column};
-
- if (!$protocol) {
- return;
- }
-
-
- $entity->{$field_name}['und'][0] = [
- 'value' => [],
- ];
-
- $entity_id = $record->entity_id;
-
- $protocol_name_term = chado_get_semweb_term('protocol', 'name');
- $protocol_type_term = chado_get_semweb_term('protocol', 'type_id');
-
- $entity->{$field_name}['und'][0]['value'] = [
- $protocol_name_term => $protocol->name,
- $protocol_type_term => $protocol->type_id->name,
- ];
-
- $entity->{$field_name}['und'][0][$linker_field] = $protocol->protocol_id;
-
- if (property_exists($record->{$field_column}, 'entity_id')) {
- $entity->{$field_name}['und'][0]['value']['entity_id'] = 'TripalEntity:' . $record->{$field_column}->entity_id;
- }
- }
-
- function elementInfo() {
- $field_term = $this->getFieldTermID();
- $type_id_term = tripal_get_chado_semweb_term('protocol', 'type_id');
- return [
- $field_term => [
- 'operations' => ['eq', 'contains', 'starts'],
- 'sortable' => TRUE,
- 'searchable' => TRUE,
- 'readonly' => FALSE,
- 'type' => 'xs:complexType',
- 'elements' => [
- 'rdfs:label' => [
- 'searchable' => TRUE,
- 'name' => 'protocol_name',
- 'operations' => ['eq', 'ne', 'contains', 'starts'],
- 'sortable' => FALSE,
- 'type' => 'xs:string',
- 'readonly' => TRUE,
- 'required' => FALSE,
- ],
- 'entity' => [
- 'searchable' => FALSE,
- ],
- $type_id_term => [
- 'searchable' => TRUE,
- 'name' => 'protocol_type',
- 'operations' => ['eq', 'ne', 'contains', 'starts'],
- 'sortable' => TRUE,
- 'readonly' => FALSE,
- 'required' => TRUE,
- 'type' => 'xs:integer',
- ],
- ],
- ],
- ];
- }
-
- function query($query, $condition) {
- $alias = $this->field['field_name'];
- $operator = $condition['operator'];
- $field_term_id = $this->getFieldTermID();
- $type_id_term = $field_term_id . ',' . tripal_get_chado_semweb_term('protocol', 'type_id');
-
- $this->queryJoinOnce($query, 'protocol', $alias, "base.protocol_id = $alias.protocol_id");
- if ($condition['column'] == $field_term_id or
- $condition['column'] == $field_term_id . ',rdfs:label') {
- $query->condition("$alias.name", $condition['value'], $operator);
- }
- if ($condition['column'] == $type_id_term) {
- $this->queryJoinOnce($query, 'cvterm', 'CVT', "base.type_id = CVT.cvterm_id");
- $query->condition("CVT.name", $condition['value'], $operator);
- }
- }
- function queryOrder($query, $order) {
- $alias = $this->field['field_name'];
- $field_term_id = $this->getFieldTermID();
- $type_id_term = tripal_get_chado_semweb_term('protocol', 'type_id');
-
- $this->queryJoinOnce($query, 'protocol', $alias, "base.protocol_id = $alias.organism_id");
- if ($order['column'] == $type_id_term) {
- if (!in_array('CVT', $joins)) {
- $this->queryJoinOnce($query, 'cvterm', 'CVT', "base.type_id = CVT.cvterm_id");
- }
- $query->orderBy("CVT.name", $order['direction']);
- }
- }
- }
|