Browse Source

Allowed users to generate MD5 checksum for a sequence with a checkbox

Chun-Huai Cheng 9 years ago
parent
commit
ca6ffa8e5b

+ 1 - 1
tripal_entities/includes/TripalEntityController.inc

@@ -54,7 +54,7 @@ class TripalEntityController extends EntityAPIController {
    *   An array of entity IDs or a single numeric ID.
    */
   public function deleteMultiple($entities) {
-    dpm($entities);
+
     $ids = array();
     if (!empty($entities)) {
       $transaction = db_transaction();

+ 13 - 0
tripal_entities/includes/tripal_entities.admin.inc

@@ -430,6 +430,7 @@ function tripal_entities_add_bundle_fields($entity_type_name, $bundle_name, $cvt
       $widget_type = '';
       $settings = array();
       $label = '';
+      $desc = '';
 
       switch($details['type']) {
         case 'char':
@@ -520,15 +521,26 @@ function tripal_entities_add_bundle_fields($entity_type_name, $bundle_name, $cvt
           case 'organism_id':
             $field_type = 'organism_id';
             $label = 'Organism';
+            $desc = 'Select an organism.';
             $widget_type = 'tripal_entities_organism_select_widget';
             break;
           case 'dbxref_id':
             $field_type = 'dbxref_id';
             $label = 'Primary Cross Reference';
+            $desc = 'This record can be cross-referenced with a record in another online database. This field is intended for the most prominent reference.  At a minimum, the database and accession must be provided.';
             $widget_type = 'tripal_entities_primary_dbxref_widget';
             break;
         }
       }
+
+      // If this column is the md5checksum
+      if ($column_name == 'md5checksum') {
+        $field_type = 'md5checksum';
+        $label = 'MD5 Checksum';
+        $desc = 'Generating MD5 checksum for the sequence.';
+        $widget_type = 'tripal_entities_md5checksum_checkbox_widget';
+      }
+
       // If the field doesn't exist then create it.
       if (!$field) {
         $field = array(
@@ -548,6 +560,7 @@ function tripal_entities_add_bundle_fields($entity_type_name, $bundle_name, $cvt
       $field_instance = array(
         'field_name' => $field_name,
         'label' => $label ? $label : ucwords(preg_replace('/_/', ' ', $column_name)),
+        'description' => $desc,
         'widget' => array(
           'type' => $widget_type,
           'settings' => array('display_label' => 1)

+ 5 - 0
tripal_entities/includes/tripal_entities.field_storage.inc

@@ -19,6 +19,11 @@ function tripal_entities_field_storage_write($entity_type, $entity, $op, $fields
 
   // Conver the fields into a key/value list of fields and their values.
   $field_vals = tripal_entities_field_storage_unnest_fields($fields, $entity_type, $entity);
+  // Calculate the md5 checksum for the sequence per user's request
+  if (key_exists('feature__md5checksum', $field_vals) && key_exists('feature__residues', $field_vals)) {
+    $residues = $field_vals['feature__residues'];
+    $field_vals['feature__md5checksum'] = $field_vals['feature__md5checksum'] ? md5($residues) : NULL;
+  }
   $transaction = db_transaction();
   try {
     switch ($op) {

+ 49 - 0
tripal_entities/includes/tripal_entities.fields.inc

@@ -29,6 +29,18 @@ function tripal_entities_field_info() {
         'active' => TRUE
       ),
     ),
+    'md5checksum' => array(
+      'label' => t('MD5 checksum'),
+      'description' => t('A field for generating MD5 checksum for a sequence.'),
+      'default_widget' => 'tripal_entities_md5checksum_checkbox_widget',
+      'default_formatter' => 'tripal_entities_md5checksum_formatter',
+      'settings' => array(),
+      'storage' => array(
+        'type' => 'field_chado_storage',
+        'module' => 'tripal_entities',
+        'active' => TRUE
+      ),
+    ),
   );
   return $fields;
 }
@@ -47,6 +59,10 @@ function tripal_entities_field_widget_info() {
       'field types' => array('dbxref_id'),
       'description' => t('This record can be cross-referenced with a record in another online database. This field is intended for the most prominent reference.  At a minimum, the database and accession must be provided.'),
     ),
+    'tripal_entities_md5checksum_checkbox_widget' => array(
+      'label' => t('MD5 Checksum Checkbox'),
+      'field types' => array('md5checksum')
+    ),
   );
 }
 /**
@@ -62,6 +78,10 @@ function tripal_entities_field_formatter_info() {
       'label' => t('Cross-reference'),
       'field types' => array('dbxref_id')
     ),
+    'tripal_entities_md5checksum_formatter' => array(
+      'label' => t('MD5 checksum'),
+      'field types' => array('md5checksum')
+    ),
   );
 }
 /**
@@ -112,6 +132,17 @@ function tripal_entities_field_formatter_view($entity_type, $entity, $field, $in
         );
       }
       break;
+      case 'tripal_entities_md5checksum_formatter':
+        foreach ($items as $delta => $item) {
+          // TODO: add hook here to allow other modules to change this display
+          // if they want.
+          $element[$delta] = array(
+            // We create a render array to produce the desired markup,
+            '#type' => 'markup',
+            '#markup' => key_exists('value', $item) ? $item['value'] : '',
+          );
+        }
+        break;
   }
   return $element;
 }
@@ -204,6 +235,19 @@ function tripal_entities_field_widget_form(&$form, &$form_state, $field,
       );
       $element['value'] = $widget;
       break;
+      case 'tripal_entities_md5checksum_checkbox_widget':
+        $widget += array(
+          '#type' => 'checkbox',
+          '#title' => $element['#title'],
+          '#description' => $element['#description'],
+          '#options' => array(0, 1),
+          '#default_value' => 1,
+          '#weight' => isset($element['#weight']) ? $element['#weight'] : 0,
+          '#delta' => $delta,
+          '#element_validate' => array('tripal_entities_md5checksum_checkbox_widget_validate'),
+        );
+        $element['value'] = $widget;
+        break;
   }
   return $element;
 }
@@ -256,7 +300,12 @@ function tripal_entities_primary_dbxref_widget_validate($element, &$form_state)
     form_set_error(implode('][', $element ['#parents']) . '][0][dbxref__accession', t("A database and the accession must both be provided for the primary cross reference."));
   }
 }
+/**
+ * Callback function for validating the tripal_entities_md5checksum_checkbox_widget.
+ */
+function tripal_entities_md5checksum_checkbox_widget_validate($element, &$form_state) {
 
+}
 /**
  * Theme function for the primary_dbxref_widget.
  *