123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- <?php
- class sio__annotation_formatter extends ChadoFieldFormatter {
- // The default lable for this field.
- public static $default_label = 'Chado Annotation';
- // The list of field types for which this formatter is appropriate.
- public static $field_types = array('chado_linker__cvterm');
- /**
- *
- * @see TripalFieldFormatter::view()
- */
- public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
- $headers = array('Term', 'Name', 'Definition');
- $rows = array();
- $field_table = $this->instance['settings']['chado_table'];
- $schema = chado_get_schema($field_table);
- $vocabulary_term = tripal_get_chado_semweb_term('cvterm', 'cv_id');
- $accession_term = tripal_get_chado_semweb_term('dbxref', 'accession');
- $definition_term = tripal_get_chado_semweb_term('cvterm', 'definition');
- $name_term = tripal_get_chado_semweb_term('cvterm', 'name');
- if (array_key_exists('is_not', $schema['fields'])) {
- $negation_term = chado_get_semweb_term($field_table, 'is_not');
- }
- $chado_table = $this->instance['settings']['chado_table'];
- foreach ($items as $delta => $item) {
- if (!empty($item['chado-' . $chado_table . '__cvterm_id'])) {
- $cvterm = chado_generate_var('cvterm', array('cvterm_id' => $item['chado-' . $chado_table . '__cvterm_id']));
- $dbxref = $cvterm->dbxref_id;
- // Build the accession.
- $accession = $dbxref->db_id->name . ':' . $dbxref->accession;
- if ($dbxref->db_id->urlprefix) {
- $accession = l($accession, chado_get_dbxref_url($dbxref), array('attributes' => array('target' => '_blank')));
- }
- $row = array(
- $accession,
- $item['value'][$name_term],
- $item['value'][$definition_term],
- );
- if (array_key_exists('is_not', $schema['fields'])) {
- if ($negation_term == FALSE) {
- $row[1] = 'NOT ' . $row[1];
- }
- }
- $rows[] = $row;
- }
- }
- // Theme the results in a table.
- $caption = 'This record has the following annotations.';
- $table = array(
- 'header' => $headers,
- 'rows' => $rows,
- 'attributes' => array(
- 'id' => "$chado_table-table-terms",
- 'class' => 'tripal-data-table'
- ),
- 'caption' => $caption,
- 'sticky' => FALSE,
- 'colgroups' => array(),
- 'empty' => 'There are no annotations of this type',
- );
- if (count($items) > 0) {
- $element[0]['base'] = array(
- '#type' => 'markup',
- '#markup' => theme_table($table),
- );
- }
- }
- /**
- * Get annotations for child features, from the data__sequence_features field.
- * Possibly not used.
- *
- * @param $data
- */
- private function getAnnotationRows($data) {
- $rows = [];
- $info = $data['info'];
- $children = $data['children'] ?? NULL;
- $annotations = $info->feature_cvterm;
- if ($annotations) {
- if (is_array($annotations)) {
- foreach ($annotations as $ann) {
- $annotation_name = $ann->cvterm_id->name;
- if ($ann->is_not) {
- $annotation_name = "is not " . $annotation_name;
- }
- $rows[] = [
- $info->uniquename,
- $info->type_id->name,
- $annotation_name,
- ];
- }
- }
- else {
- $annotation_name = $annotations->cvterm_id->name;
- if ($annotations->is_not) {
- $annotation_name = "is not " . $annotation_name;
- }
- $rows[] = [
- $info->uniquename,
- $info->type_id->name,
- $annotation_name,
- ];
- }
- }
- if ($children && !empty($children)) {
- foreach ($children as $child) {
- $rows = array_merge($this->getAnnotationRows($child), $rows);
- }
- }
- return $rows;
- }
- }
|