123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- <?php
- class chado_feature__seqlen extends TripalField {
- // The default lable for this field.
- public static $default_label = 'Sequence length';
- // The default description for this field.
- public static $default_description = 'A field for calculating the length of a sequence.';
- // Add any default settings elements. If you override the fieldSettingsForm()
- // or the instanceSettingsForm() functions then you need to be sure that
- // any settings you want those functions to manage are listed in this
- // array.
- public static $default_settings = array(
- 'chado_table' => '',
- 'chado_column' => '',
- 'base_table' => '',
- 'semantic_web' => '',
- );
- // Set this to the name of the storage backend that by default will support
- // this field.
- public static $default_storage = 'field_chado_storage';
- /**
- * @see TripalField::create_info()
- */
- function createInfo() {
- if (!$this->can_attach) {
- return;
- }
- $table_name = $this->details['chado_table'];
- $type_table = $this->details['chado_type_table'];
- $type_field = $this->details['chado_type_column'];
- $cv_id = $this->details['chado_cv_id'];
- $cvterm_id = $this->details['chado_cvterm_id'];
- return array(
- 'field_name' => $this->field_name,
- 'type' => 'chado_feature__seqlen',
- 'cardinality' => 1,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- 'settings' => array(
- 'chado_table' => $table_name,
- 'chado_column' => 'seqlen',
- 'semantic_web' => tripal_get_chado_semweb_term($table_name, 'seqlen'),
- ),
- );
- }
- /**
- * @see TripalField::createInstanceInfo()
- */
- function createInstanceInfo() {
- if (!$this->can_attach) {
- return;
- }
- $table_name = $this->details['chado_table'];
- $type_table = $this->details['chado_type_table'];
- $type_field = $this->details['chado_type_column'];
- $cv_id = $this->details['chado_cv_id'];
- $cvterm_id = $this->details['chado_cvterm_id'];
- return array(
- 'field_name' => $this->field_name,
- 'entity_type' => $this->entity_type,
- 'bundle' => $this->bundle->name,
- 'label' => 'Raw Sequence Length',
- 'description' => 'The number of residues in the raw sequence. This length
- is only for the assigned raw sequence and does not represent the length of any
- sequences derived from alignments. If this value is zero but aligned sequences
- are present then this record has no official assigned sequence.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => TRUE,
- ),
- 'widget' => array(
- 'type' => 'chado_feature__seqlen_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'inline',
- 'type' => 'chado_feature__seqlen_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- /**
- * @see TripalField::widgetInfo()
- */
- public static function widgetInfo() {
- return array(
- 'chado_feature__seqlen_widget' => array(
- 'label' => t('Sequence Length'),
- 'field types' => array('chado_feature__seqlen'),
- ),
- );
- }
- /**
- * @see TripalField::formatterInfo()
- */
- static function formatterInfo() {
- return array(
- 'chado_feature__seqlen_formatter' => array(
- 'label' => t('Residues Length'),
- 'field types' => array('chado_feature__seqlen'),
- 'settings' => array(
- ),
- ),
- );
- }
- /**
- * @see TripalField::formatterView()
- */
- static function formatterView(&$element, $entity_type, $entity, $field,
- $instance, $langcode, $items, $display) {
- foreach ($items as $delta => $item) {
- $element[$delta] = array(
- '#type' => 'markup',
- '#markup' => $item['value'],
- );
- }
- }
- /**
- * @see TripalField::widgetForm()
- */
- public static function widgetForm(&$widget, &$form, &$form_state, $field, $instance,
- $langcode, $items, $delta, $element) {
- $settings = $field['settings'];
- $field_name = $field['field_name'];
- $field_type = $field['type'];
- $field_table = $field['settings']['chado_table'];
- $field_column = $field['settings']['chado_column'];
- $widget['value'] = array(
- '#type' => 'value',
- '#value' => array_key_exists($delta, $items) ? $items[$delta]['value'] : '',
- );
- $widget['feature__seqlen'] = array(
- '#type' => 'value',
- '#value' => 0,
- '#title' => $element['#title'],
- '#description' => $element['#description'],
- '#weight' => isset($element['#weight']) ? $element['#weight'] : 0,
- '#delta' => $delta,
- // '#element_validate' => array('chado_feature__seqlen_widget_validate'),
- );
- }
- }
- /**
- * Callback function for validating the chado_feature__seqlen_widget.
- */
- function chado_feature__seqlen_widget_validate($element, &$form_state) {
- $field_name = $element['#parents'][0];
- // Get the residues so we can calculate teh length.
- //$residues = tripal_chado_get_field_form_values('feature__residues', $form_state, 0, 'feature__residues');
- // Remove any white spaces.
- if ($residues) {
- $residues = preg_replace('/\s/', '', $residues);
- tripal_chado_set_field_form_values($field_name, $form_state, strlen($residues), 0, 'feature__seqlen');
- }
- else {
- // Otherwise, remove the seqlen value
- tripal_chado_set_field_form_values($field_name, $form_state, '__NULL__', 0, 'feature_seqlen');
- }
- }
|