123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- <?php
- class local__contact extends ChadoField {
-
-
-
-
-
-
-
-
- public static $default_label = 'Contact';
-
- public static $description = 'An indviddual or organization that serves as a contact for this record.';
-
-
-
-
-
-
-
- public static $default_instance_settings = array(
-
- 'term_vocabulary' => 'local',
-
- 'term_name' => 'contact',
-
- 'term_accession' => 'contact',
-
-
-
- 'term_fixed' => FALSE,
- );
-
- public static $default_widget = 'local__contact_widget';
-
- public static $default_formatter = 'local__contact_formatter';
-
-
-
-
-
- protected $field;
-
-
-
- protected $instance;
-
- public function elementInfo() {
- $field_term = $this->getFieldTermID();
- $type_term = chado_get_semweb_term('contact', 'type_id');
- $name_term = chado_get_semweb_term('contact', 'name');
- $description_term = chado_get_semweb_term('contact', 'description');
- return array(
- $field_term => array(
- 'operations' => array('eq', 'contains', 'starts'),
- 'sortable' => TRUE,
- 'searchable' => TRUE,
- 'type' => 'xs:complexType',
- 'readonly' => TRUE,
- 'elements' => array(
- $type_term => array(
- 'searchable' => TRUE,
- 'label' => 'Contact Type',
- 'help' => 'The type of contact',
- 'operations' => array('eq', 'ne', 'contains', 'starts'),
- 'sortable' => TRUE,
- 'type' => 'xs:string',
- 'readonly' => FALSE,
- 'required' => TRUE,
- ),
- $name_term => array(
- 'searchable' => TRUE,
- 'label' => 'Contact Name',
- 'help' => 'The name of the contact.',
- 'operations' => array('eq', 'ne', 'contains', 'starts'),
- 'sortable' => TRUE,
- 'type' => 'xs:string',
- 'readonly' => FALSE,
- 'required' => TRUE,
- ),
- $description_term => array(
- 'searchable' => TRUE,
- 'label' => 'Contact Description',
- 'help' => 'A descriptoin of the contact.',
- 'operations' => array('contains'),
- 'sortable' => TRUE,
- 'type' => 'xs:string',
- 'readonly' => FALSE,
- 'required' => FALSE,
- ),
- 'entity' => array(
- 'searchable' => FALSE,
- ),
- ),
- )
- );
- }
-
- public function load($entity) {
- $record = $entity->chado_record;
- $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'];
- $type_term = chado_get_semweb_term('contact', 'type_id');
- $name_term = chado_get_semweb_term('contact', 'name');
- $description_term = chado_get_semweb_term('contact', 'description');
-
- $entity->{$field_name}['und'][0] = array(
- 'value' => array(),
- );
-
- if ($field_table == 'biomaterial') {
- if ($record) {
- $contact = $record->biosourceprovider_id;
- if ($contact) {
- $entity->{$field_name}['und'][0] = array(
- 'value' => array(
- $type_term => $contact->type_id ? $contact->type_id->name : '',
- $name_term => $contact->name,
- $description_term => $contact->description,
- ),
- $entity->{$field_name}['und'][0]['chado-biomaterial__biosourceprovider_id'] = $contact->contact_id,
- );
- if (property_exists($contact, 'entity_id')) {
- $entity->{$field_name}['und'][0]['value']['entity'] = 'TripalEntity:' . $contact->entity_id;
- }
- }
- }
- };
-
- }
-
- public function query($query, $condition) {
- $alias = $this->field['field_name'];
- $operator = $condition['operator'];
- $field_term_id = $this->getFieldTermID();
- $type_term = chado_get_semweb_term('contact', 'type_id');
- $name_term = chado_get_semweb_term('contact', 'name');
- $description_term = chado_get_semweb_term('contact', 'description');
- if ($field_table == 'biomaterial') {
- if ($record) {
- $contact = $record->biosourceprovider_id;
-
- $calias = $alias . '_provider_id';
- $this->queryJoinOnce($query, 'contact', $calias, "base.biosourceprovider_id = $calias.contact_id");
-
- if ($condition['column'] == $field_term_id or
- $condition['column'] == $field_term_id . ',' . $name_term) {
- $query->condition("$calias.name", $condition['value'], $operator);
- }
-
- if ($condition['column'] == $field_term_id . ',' . $description_term) {
- $query->condition("$calias.description", $condition['value'], $operator);
- }
-
- if ($condition['column'] == $field_term_id . ',' . $type_term) {
- $talias = $alias . 'provider_contact_type';
- $this->queryJoinOnce($query, 'cvterm', $talias, "$calias.type_id = $talias.cvterm_id");
- $query->condition("$talias.name", $condition['value'], $operator);
- }
- }
- }
- }
-
- public function queryOrder($query, $order) {
- $alias = $this->field['field_name'];
- $field_term_id = $this->getFieldTermID();
- $type_term = chado_get_semweb_term('contact', 'type_id');
- $name_term = chado_get_semweb_term('contact', 'name');
- $description_term = chado_get_semweb_term('contact', 'description');
- if ($field_table == 'biomaterial') {
- if ($record) {
- $contact = $record->biosourceprovider_id;
-
- $calias = $alias . '_provider_id';
- $this->queryJoinOnce($query, 'contact', $calias, "base.biosourceprovider_id = $calias.contact_id");
-
- if ($order['column'] == $field_term_id or
- $order['column'] == $field_term_id . ',' . $name_term) {
- $query->orderBy("$calias.name", $order['direction']);
- }
-
- if ($order['column'] == $field_term_id . ',' . $description_term) {
- $query->orderBy("$calias.description", $order['direction']);
- }
-
- if ($order['column'] == $field_term_id . ',' . $type_term) {
- $talias = $alias . 'provider_contact_type';
- $this->queryJoinOnce($query, 'cvterm', $talias, "$calias.type_id = $talias.cvterm_id", "LEFT OUTER");
- $query->orderBy("$talias.name", $order['direction']);
- }
- }
- }
- }
- }
|