123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- <?php
- class data__accession extends ChadoField {
-
-
-
-
-
-
-
-
- public static $default_label = 'Site Accession';
-
- public static $description = 'The unique stable accession (ID) for this record on this site.';
-
-
-
-
-
-
-
- public static $default_instance_settings = array(
-
- 'term_vocabulary' => 'data',
-
- 'term_name' => 'accession',
-
- 'term_accession' => '2091',
-
-
-
- 'term_fixed' => FALSE,
- );
-
- public static $default_widget = 'data__accession_widget';
-
- public static $default_formatter = 'data__accession_formatter';
-
- 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'];
-
- $entity->{$field_name}['und'][0] = array(
- 'value' => '',
- 'chado-' . $field_table . '__' . $field_column => '',
- 'db_id' => '',
- 'accession' => '',
- );
-
-
- if ($record->$field_column) {
- $dbxref = $record->$field_column;
- $value = $dbxref->db_id->name . ':' . $dbxref->accession;
-
- if ($value != 'local:null') {
- $entity->{$field_name}['und'][0] = array(
- 'value' => $dbxref->accession,
- 'chado-' . $field_table . '__' . $field_column => $record->$field_column->$field_column,
- 'db_id' => $dbxref->db_id->db_id,
- 'accession' => $dbxref->accession,
- );
- }
- }
- }
-
- public function query($query, $condition) {
- $alias = $this->field['field_name'];
- $operator = $condition['operator'];
- $field_table = $this->instance['settings']['chado_table'];
- $field_column = $this->instance['settings']['chado_column'];
- $field_term_id = $this->getFieldTermID();
- $accession_term = chado_get_semweb_term($field_table, $field_column);
-
-
- if ($condition['column'] == $accession_term) {
- $this->queryJoinOnce($query, 'dbxref', 'DBX', "DBX.dbxref_id = base.dbxref_id");
- $query->condition("DBX.accession", $condition['value'], $operator);
- }
- }
- public function queryOrder($query, $order) {
- $alias = $this->field['field_name'];
- $operator = $condition['operator'];
- $field_table = $this->instance['settings']['chado_table'];
- $field_column = $this->instance['settings']['chado_column'];
- $field_term_id = $this->getFieldTermID();
- $accession_term = chado_get_semweb_term($field_table, $field_column);
-
-
- if ($order['column'] == $accession_term) {
- $this->queryJoinOnce($query, 'dbxref', 'DBX', "DBX.dbxref_id = base.dbxref_id", "LEFT OUTER");
- $query->orderBy("DBX.accession", $order['direction']);
- }
- }
-
- public function validate($entity_type, $entity, $langcode, $items, &$errors) {
-
-
-
-
-
- if (!$entity) {
- return;
- }
- $field_name = $this->field['field_name'];
- $settings = $this->field['settings'];
- $field_type = $this->field['type'];
- $field_table = $this->instance['settings']['chado_table'];
- $field_column = $this->instance['settings']['chado_column'];
-
- foreach ($items as $delta => $values) {
- $db_id = $values['db_id'];
- $accession = $values['accession'];
-
-
-
-
-
-
-
- if (!$db_id and $accession) {
- $errors[$field_name][$delta]['und'][] = array(
- 'message' => t("A database and the accession must both be provided for the primary cross reference."),
- 'error' => 'chado_base__dbxref',
- );
- }
- if ($db_id and !$accession) {
- $errors[$field_name][$delta]['und'][] = array(
- 'message' => t("A database and the accession must both be provided for the primary cross reference."),
- 'error' => 'chado_base__dbxref',
- );
- }
- if (!$db_id and !$accession) {
- $errors[$field_name][$delta]['und'][] = array(
- 'message' => t("A database and the accession must both be provided for the primary cross reference."),
- 'error' => 'chado_base__dbxref',
- );
- }
- }
- }
- }
|