class sbo__relationship_formatter
Hierarchy
- class \TripalFieldFormatter
- class \ChadoFieldFormatter
- class \sbo__relationship_formatter
- class \ChadoFieldFormatter
Expanded class hierarchy of sbo__relationship_formatter
2 string references to 'sbo__relationship_formatter'
- sbo__relationship.inc in tripal_chado/
includes/ TripalFields/ sbo__relationship/ sbo__relationship.inc - tripal_chado_bundle_instances_info_linker in tripal_chado/
includes/ tripal_chado.fields.inc
File
- tripal_chado/
includes/ TripalFields/ sbo__relationship/ sbo__relationship_formatter.inc, line 3
View source
class sbo__relationship_formatter extends ChadoFieldFormatter {
// The default lable for this field.
public static $default_label = 'Relationship';
// The list of field types for which this formatter is appropriate.
public static $field_types = array('sbo__relationship');
public static $default_settings = array(
'title' => 'Relationship',
'empty' => 'There are no relationships',
);
/**
*
* @see TripalFieldFormatter::settingsForm()
*/
public function settingsForm($view_mode, $form, &$form_state) {
$display = $this->instance['display'][$view_mode];
$settings = $display['settings'];
$element = array();
$element['title'] = array(
'#type' => 'textfield',
'#title' => 'Table Header',
'#default_value' => array_key_exists('title', $settings) ? $settings['title'] : 'Relationship',
);
$element['empty'] = array(
'#type' => 'textfield',
'#title' => 'Empty text',
'#default_value' => array_key_exists('empty', $settings) ? $settings['empty'] : 'There are no relationships',
);
return $element;
}
/**
* @see TripalFieldFormatter::settingsSummary()
*/
public function settingsSummary($view_mode) {
$display = $this->instance['display'][$view_mode];
$settings = $display['settings'];
$summary = t('Title: @title<br>Empty: @empty',
array(
'@title' => $settings['title'],
'@empty' => $settings['empty'])
);
return $summary;
}
/**
*
* @see TripalFieldFormatter::view()
*/
public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
// Get the settings
$settings = $display['settings'];
$rows = array();
$headers = array($settings['title']);
foreach ($items as $delta => $item) {
if (empty($item['value'])) {
continue;
}
$subject_name = $item['value']['local:relationship_subject']['schema:name'];
$subject_type = $item['value']['local:relationship_subject']['rdfs:type'];
$object_name = $item['value']['local:relationship_object']['schema:name'];
$object_type = $item['value']['local:relationship_object']['rdfs:type'];
$phrase = $item['value']['SIO:000493'];
// Handle some special cases.
// For mRNA objects we don't want to show the CDS, exons, 5' UTR, etc.
// we want to show the parent gene and the protein.
if ($object_type == 'mRNA' and
(in_array($subject_type, array('CDS', 'exon', 'five_prime_UTR', 'three_prime_UTR')))) {
continue;
}
// Add bold font to the object and subject names.
$phrase = preg_replace("/$subject_type/", "<b>$subject_type</b>", $phrase);
$phrase = preg_replace("/$object_type/", "<b>$object_type</b>", $phrase);
// Convert the object/subject to a link if an entity exists for it.
if (array_key_exists('entity', $item['value']['local:relationship_object'])) {
list($entity_type, $object_entity_id) = explode(':', $item['value']['local:relationship_object']['entity']);
if ($object_entity_id != $entity->id) {
$link = l($object_name, 'bio_data/' . $object_entity_id);
$phrase = preg_replace("/$object_name/", $link, $phrase);
}
}
if (array_key_exists('entity', $item['value']['local:relationship_subject'])) {
list($entity_type, $subject_entity_id) = explode(':', $item['value']['local:relationship_subject']['entity']);
if ($subject_entity_id != $entity->id) {
$link = l($subject_name, 'bio_data/' . $subject_entity_id);
$phrase = preg_replace("/$subject_name/", $link, $phrase);
}
}
$rows[][] = array(
'data' => $phrase,
'class' => array('tripal-entity-unattached field-items')
);
}
// Build the pager
$items_per_page = array_key_exists('items_per_page', $this->instance['settings']) ? $this->instance['settings']['items_per_page'] : 10;
$total_records = count($rows);
$total_pages = (int) ($total_records / $items_per_page) + 1;
$pelement = 0; //$this->getPagerElementID();
$current_page = pager_default_initialize($total_records, $items_per_page, $pelement);
$pager = theme('pager', array(
'tags' => array(),
'element' => $pelement,
'parameters' => array(),
'quantity' => $total_pages,
));
$pager = $this->ajaxifyPager($pager, $entity);
$page_items = array_chunk($rows, $items_per_page);
$content = '';
if ($total_pages > 1) {
if (count($rows) == 1) {
$content = 'There is ' . count($rows) . ' relationship.';
}
if (count($rows) > 1) {
$content = 'There are ' . count($rows) . ' relationships.';
}
}
$content .= theme_table(array(
'header' => $headers,
'rows' => count($rows) > 0 ? $page_items[$current_page] : array(),
'attributes' => array(
'id' => 'sbo--relationship-table',
),
'sticky' => FALSE,
'caption' => '',
'colgroups' => array(),
'empty' => $settings['empty'],
));
$element[0] = array(
'#type' => 'markup',
'#markup' => $content . $pager,
);
}
}
Members
Name | Modifiers | Type | Description |
---|---|---|---|
sbo__relationship_formatter:: |
public static | property |
The default lable for this field. Overrides TripalFieldFormatter:: |
sbo__relationship_formatter:: |
public static | property |
The list of default settings for this formatter. Overrides TripalFieldFormatter:: |
sbo__relationship_formatter:: |
public static | property |
The list of field types for which this formatter is appropriate. Overrides TripalFieldFormatter:: |
sbo__relationship_formatter:: |
public | function |
Overrides TripalFieldFormatter:: |
sbo__relationship_formatter:: |
public | function |
Overrides TripalFieldFormatter:: |
sbo__relationship_formatter:: |
public | function |
Overrides TripalFieldFormatter:: |
TripalFieldFormatter:: |
protected | function | Updates a pager generated by theme('pager') for use with AJAX. |
TripalFieldFormatter:: |
protected | function | When constructing a pager for use by a field, all pagers must have a unique ID |
TripalFieldFormatter:: |
public static | function | Provides information about the formatter for this field. |
TripalFieldFormatter:: |
public | function | Instantiates a new TripalFieldFormatter object. |