Sfoglia il codice sorgente

Bulk Loader: Added Created and Updated timestamps to tripal_bulk_loader templates

Lacey Sanderson 11 anni fa
parent
commit
f904860e67

+ 16 - 6
tripal_bulk_loader/includes/tripal_bulk_loader.admin.templates.inc

@@ -467,12 +467,14 @@ function tripal_bulk_loader_modify_template_base_form_submit($form, &$form_state
       $record = array(
         'name' => $form_state['values']['new_template_name'],
         'template_array' => array(),
+        'created' => time(),
+        'changed' => time()
       );
-      drupal_write_record('tripal_bulk_loader_template', $record);
+      $result = drupal_write_record('tripal_bulk_loader_template', $record);
       $form_state['storage']['template_id'] = $record['template_id'];
       $form_state['storage']['template_name'] = $record['name'];
       $form_state['storage']['template'] = array();
-      $form['rebuild'] = FALSE;
+      $form_state['rebuild'] = FALSE;
       $form_state['redirect'] = 'admin/tripal/loaders/bulk/template/'.$record['template_id'].'/edit';
     break;
 
@@ -508,7 +510,8 @@ function tripal_bulk_loader_modify_template_base_form_submit($form, &$form_state
   if ($save) {
     $record = array(
       'template_id' => $form_state['storage']['template_id'],
-      'template_array' => serialize($form_state['storage']['template'])
+      'template_array' => serialize($form_state['storage']['template']),
+      'changed' => time()
     );
     drupal_write_record('tripal_bulk_loader_template', $record, array('template_id'));
     drupal_set_message(t('Template Saved.'));
@@ -677,6 +680,8 @@ function tripal_bulk_loader_import_export_template_form_submit($form, &$form_sta
       $record = array(
         'name' => $form_state['values']['new_template_name'],
         'template_array' => serialize($t),
+        'created' => time(),
+        'changed' => time()
       );
       drupal_write_record('tripal_bulk_loader_template', $record);
       if ($record->template_id) {
@@ -1023,6 +1028,7 @@ function tripal_bulk_loader_edit_template_record_form_submit($form, &$form_state
 
     // Save Template
     $form_state['storage']['template']->template_array = serialize($template);
+    $form_state['storage']['template']->changed = time();
     $success = drupal_write_record('tripal_bulk_loader_template', $form_state['storage']['template'], array('template_id'));
 
     if ($success) {
@@ -1147,7 +1153,8 @@ function tripal_bulk_loader_delete_template_record_form_submit($form, &$form_sta
 
   $record = array(
     'template_id' => $form_state['storage']['template_id'],
-    'template_array' => serialize($form_state['storage']['template'])
+    'template_array' => serialize($form_state['storage']['template']),
+    'changed' => time()
   );
   drupal_write_record('tripal_bulk_loader_template', $record, array('template_id'));
   drupal_set_message(t('Template Saved.'));
@@ -1253,7 +1260,8 @@ function tripal_bulk_loader_duplicate_template_record_form_submit($form, &$form_
 
   $record = array(
     'template_id' => $form_state['storage']['template_id'],
-    'template_array' => serialize($form_state['storage']['template'])
+    'template_array' => serialize($form_state['storage']['template']),
+    'changed' => time()
   );
   drupal_write_record('tripal_bulk_loader_template', $record, array('template_id'));
   drupal_set_message(t('Template Saved.'));
@@ -2054,6 +2062,7 @@ function tripal_bulk_loader_template_field_form_submit($form, &$form_state) {
       $template[$priority]['fields'][$form_state['storage']['field_index']] = $field;
     }
     $form_state['storage']['template']->template_array = serialize($template);
+    $form_state['storage']['template']->changed = time();
     $success = drupal_write_record('tripal_bulk_loader_template', $form_state['storage']['template'], array('template_id'));
 
     if ($success) {
@@ -2225,7 +2234,8 @@ function tripal_bulk_loader_delete_template_field_form_submit($form, &$form_stat
 
   $record = array(
     'template_id' => $form_state['storage']['template_id'],
-    'template_array' => serialize($form_state['storage']['template'])
+    'template_array' => serialize($form_state['storage']['template']),
+    'changed' => time()
   );
   drupal_write_record('tripal_bulk_loader_template', $record, array('template_id'));
   drupal_set_message(t('Template Saved.'));

+ 44 - 7
tripal_bulk_loader/tripal_bulk_loader.install

@@ -61,13 +61,25 @@ function tripal_bulk_loader_schema() {
             'type' => 'serial',
             'unsigned' => TRUE,
             'not null' => TRUE,
-      ),
-      'name' => array(
+          ),
+          'name' => array(
             'type' => 'varchar',
-      ),
-         'template_array' => array(
+          ),
+          'template_array' => array(
             'type' => 'varchar',
-      )
+          ),
+          'created' => array(
+            'description' => 'The Unix timestamp when the template was created.',
+            'type' => 'int',
+            'not null' => TRUE,
+            'default' => 0,
+          ),
+          'changed' => array(
+            'description' => 'The Unix timestamp when the template was most recently saved.',
+            'type' => 'int',
+            'not null' => TRUE,
+            'default' => 0,
+          )
     ),
       'primary key' => array('template_id'),
     'unique keys' => array(
@@ -199,7 +211,7 @@ function tripal_bulk_loader_update_6152() {
  * Update to 7.x-2.0
  * -Cast tripal_bulk_loader.template_id to int field
  */
-function tripal_bulk_loader_update_7200() {
+function tripal_bulk_loader_update_7201() {
 
   db_change_field(
     'tripal_bulk_loader',
@@ -208,7 +220,32 @@ function tripal_bulk_loader_update_7200() {
     array('type' => 'int')
   );
 
-  return 'Updated tripal_bulk_loader.template_id from character to integer';
+
+  db_add_field(
+    'tripal_bulk_loader_template',
+    'created',
+    array(
+      'description' => 'The Unix timestamp when the template was created.',
+      'type' => 'int',
+      'not null' => TRUE,
+      'default' => 0,
+    )
+  );
+
+  db_add_field(
+    'tripal_bulk_loader_template',
+    'changed',
+    array(
+      'description' => 'The Unix timestamp when the template was most recently saved.',
+      'type' => 'int',
+      'not null' => TRUE,
+      'default' => 0,
+    )
+  );
+
+
+  return 'Updated tripal_bulk_loader.template_id from character to integer '
+    . 'and added time created/updated track to templates.';
 
 }
 

+ 30 - 0
tripal_bulk_loader/tripal_bulk_loader.views.inc

@@ -236,6 +236,36 @@ function tripal_bulk_loader_views_data() {
     ),
   );
 
+  $data['tripal_bulk_loader_template']['created'] = array(
+    'title' => t('Created'),
+    'help' => t('Date the template was created on.'),
+    'field' => array(
+      'handler' => 'views_handler_field_date',
+      'click sortable' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort_date',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_date',
+    ),
+  );
+
+  $data['tripal_bulk_loader_template']['changed'] = array(
+    'title' => t('Updated'),
+    'help' => t('The date the template was last updated on.'),
+    'field' => array(
+      'handler' => 'views_handler_field_date',
+      'click sortable' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort_date',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_date',
+    ),
+  );
+
   // Tripal Bulk Loader Constants ***************
   $data['tripal_bulk_loader_constants']['table']['group'] = t('Tripal Bulk Loader Constants');
   $data['tripal_bulk_loader_constants']['table'] = array(