Browse Source

Worked on new field classes

Chun-Huai Cheng 8 years ago
parent
commit
c6e97c04fd

+ 90 - 0
tripal_chado/includes/TripalFields/data__sequence_checksum_widget.inc

@@ -1 +1,91 @@
 <?php
+
+class data__sequence_checksum_widget extends TripalFieldWidget {
+  // The default lable for this field.
+  public static $label = 'Sequence MD5 checksum';
+
+  // The list of field types for which this formatter is appropriate.
+  public static $field_types = array('no_widget');
+
+
+  /**
+   * 
+   * @param unknown $field
+   * @param unknown $instance
+   */
+  public function __construct($field, $instance = NULL) {
+    $this->field = $field;
+    $this->instance = $instance;
+  }
+
+  /**
+   * 
+   * @see TripalFieldWidget::form()
+   */
+  public function form(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {
+    parent::widgetForm($widget, $form, $form_state, $langcode, $items, $delta, $element);
+    
+    $settings = $this->field['settings'];
+    $field_name = $this->field['field_name'];
+    $field_type = $this->field['type'];
+    $field_table = $this->field['settings']['chado_table'];
+    $field_column = $this->field['settings']['chado_column'];
+    
+    // Get the field defaults.
+    $md5checksum = '';
+    if (count($items) > 0 and array_key_exists('chado-feature__md5checksum', $items[0])) {
+      $md5checksum = $items[0]['chado-feature__md5checksum'];
+    }
+    
+    $widget['value'] = array(
+      '#type' => 'value',
+      '#value' => $md5checksum,
+    );
+    $widget['chado-feature__md5checksum'] = array(
+      '#type' => 'value',
+      '#value' => $md5checksum,
+    );
+  }
+
+  /**
+   * Performs validation of the widgetForm.
+   *
+   * Use this validate to ensure that form values are entered correctly.  Note
+   * this is different from the validate() function which ensures that the
+   * field data meets expectations.
+   *
+   * @param $form
+   * @param $form_state
+   */
+  public function validate($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
+
+  }
+
+
+  /**
+   * 
+   * @see TripalFieldWidget::submit()
+   */
+  public function submit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
+    $field = $this->field;
+    $settings = $field['settings'];
+    $field_name = $field['field_name'];
+    $field_type = $field['type'];
+    $field_table = $field['settings']['chado_table'];
+    $field_column = $field['settings']['chado_column'];
+    
+    // Get the residues so we can calculate teh length.
+    $residues = isset($form_state['values']['feature__residues'][$langcode][0]['chado-feature__residues']) ? $form_state['values']['feature__residues'][$langcode][0]['chado-feature__residues'] : '';
+    
+    if ($residues) {
+      // Remove spaces and new lines from the residues string.
+      $residues = preg_replace('/\s/', '', $residues);
+      $form_state['values']['feature__residues'][$langcode][0]['chado-feature__residues'] = $residues;
+      $form_state['values'][$field_name][$langcode][$delta]['chado-feature__md5checksum'] = md5($residues);
+    }
+    else {
+      // Otherwise, remove the md5 value
+      $form_state['values'][$field_name][$langcode][$delta]['chado-feature__md5checksum'] = '__NULL__';
+    }
+  }
+}

+ 11 - 11
tripal_chado/includes/tripal_chado.fields.inc

@@ -257,13 +257,11 @@ function tripal_chado_bundle_create_fields_custom(&$info, $details, $entity_type
       ),
     );
   }
-  return;
-
 
   // FEATURE MD5CHECKSUM
   if ($table_name == 'feature') {
-    $field_name = $table_name . '__md5checksum';
-    $field_type = 'chado_feature__md5checksum';
+    $field_name = $bundle->name . '_data__sequence_checksum';
+    $field_type = 'data__sequence_checksum';
     $info[$field_name] = array(
       'field_name' => $field_name,
       'type' => $field_type,
@@ -279,6 +277,8 @@ function tripal_chado_bundle_create_fields_custom(&$info, $details, $entity_type
       ),
     );
   }
+  
+  return;
 
   // FEATURE RESIDUES
   if ($table_name == 'feature') {
@@ -935,7 +935,7 @@ function tripal_chado_bundle_create_instances_custom(&$info, $entity_type, $bund
         'auto_attach' => TRUE,
       ),
       'widget' => array(
-        'type' => 'chado_base__dbxref_id_widget',
+        'type' => 'data__accession_widget',
         'settings' => array(
           'display_label' => 1,
         ),
@@ -943,18 +943,16 @@ function tripal_chado_bundle_create_instances_custom(&$info, $entity_type, $bund
       'display' => array(
         'default' => array(
           'label' => 'inline',
-          'type' => 'chado_base__dbxref_id_formatter',
+          'type' => 'data__accession_formatter',
           'settings' => array(),
         ),
       ),
     );
   }
-  return;
-
 
   // FEATURE MD5CHECKSUM
   if ($table_name == 'feature') {
-    $field_name = $table_name . '__md5checksum';
+    $field_name = $bundle->name . '_data__sequence_checksum';
     $info[$field_name] = array(
       'field_name' => $field_name,
       'entity_type' => $entity_type,
@@ -970,7 +968,7 @@ function tripal_chado_bundle_create_instances_custom(&$info, $entity_type, $bund
         'auto_attach' => TRUE,
       ),
       'widget' => array(
-        'type' => 'chado_feature__md5checksum_widget',
+        'type' => 'data__sequence_checksum_widget',
         'settings' => array(
           'display_label' => 1,
           'md5_fieldname' => 'feature__md5checksum',
@@ -979,13 +977,15 @@ function tripal_chado_bundle_create_instances_custom(&$info, $entity_type, $bund
       'display' => array(
         'default' => array(
           'label' => 'inline',
-          'type' => 'chado_feature__md5checksum_formatter',
+          'type' => 'data__sequence_checksum_formatter',
           'settings' => array(),
         ),
       ),
     );
   }
 
+  return;
+  
   // FEATURE RESIDUES
   if ($table_name == 'feature') {
     $field_name = 'feature__residues';