فهرست منبع

admin interface updates for the collections functionality

Shawna Spoor 7 سال پیش
والد
کامیت
2a8b15c904

+ 13 - 19
tripal/api/tripal.collections.api.inc

@@ -23,13 +23,7 @@ function tripal_create_collection($details) {
     $collection->create($details);
     $collection->create($details);
     $collection_id = $collection->getCollectionID();
     $collection_id = $collection->getCollectionID();
 
 
-    // Add the job to write the collection download files.
-    $args = array($collection_id);
-    tripal_add_job('Create data collection files for ' . $user->name, 'tripal',
-        'tripal_create_collection_files', $args, $user->uid, 10, array());
-
-
-    drupal_set_message(t("Collection '%name' created with %num_recs record(s).  Downloadble files will be available shortly.  Check the !view for status and download links.",
+    drupal_set_message(t("Collection '%name' created with %num_recs record(s). Check the !view for generate file links.",
       array(
       array(
         '%name' => $details['collection_name'],
         '%name' => $details['collection_name'],
         '%num_recs' => count($details['ids']),
         '%num_recs' => count($details['ids']),
@@ -79,12 +73,12 @@ function tripal_get_user_collections($uid) {
  * Deletes all collections that have surpassed their lifespan
  * Deletes all collections that have surpassed their lifespan
  */
  */
 function tripal_expire_collections() {
 function tripal_expire_collections() {
-  $max_hours = variable_get('tripal_data_collections_lifespan', 7);
+  $max_days = variable_get('tripal_data_collections_lifespan', 30);
   $ctime = time();
   $ctime = time();
 
 
   $query = db_select('tripal_collection', 'tc');
   $query = db_select('tripal_collection', 'tc');
   $query->fields('tc', array('collection_id'));
   $query->fields('tc', array('collection_id'));
-  $query->where("(($ctime - create_date) / 60) / 60 >= $max_hours");
+  $query->where("((($ctime - create_date) / 60) / 60) / 24 >= $max_days");
   $results = $query->execute();
   $results = $query->execute();
   while ($collection_id = $results->fetchField()) {
   while ($collection_id = $results->fetchField()) {
     $collection = new TripalEntityCollection();
     $collection = new TripalEntityCollection();
@@ -155,15 +149,15 @@ function tripal_get_collection($values) {
  * @param TripalEntityCollection $collection
  * @param TripalEntityCollection $collection
  */
  */
 function tripal_create_collection_files($collection_id, TripalJob $job = NULL) {
 function tripal_create_collection_files($collection_id, TripalJob $job = NULL) {
-   if($job) {
-     $job->setProgress(0);
-   }
+  if ($job) {
+    $job->setProgress(0);
+  }
 
 
-   $collection = new TripalEntityCollection();
-   $collection->load($collection_id);
-   $collection->writeAll();
+  $collection = new TripalEntityCollection();
+  $collection->load($collection_id);
+  $collection->writeAll();
 
 
-   if ($job) {
-     $job->setProgress(100);
-   }
-}
+  if ($job) {
+    $job->setProgress(100);
+  }
+}

+ 33 - 7
tripal/includes/TripalEntityCollection.inc

@@ -3,7 +3,7 @@
 class TripalEntityCollection {
 class TripalEntityCollection {
 
 
   /**
   /**
-   * The name of the bundle (i.e. content type) to which the entities belong.
+   * The name of the bundles (i.e. content type) to which the entities belong.
    */
    */
   protected $bundles = array();
   protected $bundles = array();
 
 
@@ -68,7 +68,7 @@ class TripalEntityCollection {
       foreach ($this->downloaders as $class_name => $label) {
       foreach ($this->downloaders as $class_name => $label) {
         tripal_load_include_downloader_class($class_name);
         tripal_load_include_downloader_class($class_name);
         $outfile = $this->getOutfile($class_name);
         $outfile = $this->getOutfile($class_name);
-        $downloader = new $class_name($this->bundle_name, $this->ids, $this->fields,
+        $downloader = new $class_name($this->bundles, $this->ids, $this->fields,
             $outfile, $this->getUserID());
             $outfile, $this->getUserID());
         $downloader->delete();
         $downloader->delete();
       }
       }
@@ -117,6 +117,24 @@ class TripalEntityCollection {
     $this->description = $collection->description;
     $this->description = $collection->description;
     $this->collection_id = $collection->collection_id;
     $this->collection_id = $collection->collection_id;
 
 
+    /* Add the IDs, Fields, Bundles for this collection from the
+     * collection_bundle table.
+     */
+    $this->bundles = getBundles();
+    // If more than one bundle plop into associative array.
+    if (count($this->bundles) > 1) {
+      foreach ($this->bundles as $bundle) {
+        $ids[$bundle] = unserialize(getEntityIDs($this->bundle));
+        $fields[$bundle] = unserialize(getFields($this->bundle));
+      }
+      $this->ids = $ids;
+      $this->fields = $fields;
+    }
+    else {
+      $this->ids = unserialize(getEntityIDs($this->bundles));
+      $this->fields = unserialize(getFields($this->bundles));
+    }
+
     // Iterate through the fields and find out what download formats are
     // Iterate through the fields and find out what download formats are
     // supported for this basket.
     // supported for this basket.
     foreach ($this->fields as $field_id) {
     foreach ($this->fields as $field_id) {
@@ -127,7 +145,7 @@ class TripalEntityCollection {
       $field_name = $field['field_name'];
       $field_name = $field['field_name'];
       $field_type = $field['type'];
       $field_type = $field['type'];
       $field_module = $field['module'];
       $field_module = $field['module'];
-      $instance = field_info_instance('TripalEntity', $field_name, $this->bundle_name);
+      $instance = field_info_instance('TripalEntity', $field_name, $this->bundles);
       $downloaders = array();
       $downloaders = array();
 
 
       // All fields should support the Tab and CSV downloaders.
       // All fields should support the Tab and CSV downloaders.
@@ -249,7 +267,15 @@ class TripalEntityCollection {
    *   An array of bundles.
    *   An array of bundles.
    */
    */
   public function getBundles() {
   public function getBundles() {
-    return $this->bundles;
+    $collection_id = $this->collection_id;
+    // Return the bundles from the collection_bundle table.
+    $result = db_select('tripal_collection_bundle')
+      ->fields('tripal_collection_bundle', array('ids'))
+      ->condition('collection_id', $collection_id, '=')
+      ->execute()
+      ->fetchAll();
+
+    return $result;
   }
   }
 
 
   /**
   /**
@@ -454,7 +480,7 @@ class TripalEntityCollection {
 
 
     $outfile = $this->getOutfile($formatter);
     $outfile = $this->getOutfile($formatter);
 
 
-    $downloader = new $formatter($this->bundle_name, $this->ids, $this->fields, $outfile, $this->user->uid);
+    $downloader = new $formatter($this->bundles, $this->ids, $this->fields, $outfile, $this->user->uid);
 
 
     return $downloader->getURL();
     return $downloader->getURL();
   }
   }
@@ -508,8 +534,8 @@ class TripalEntityCollection {
       }
       }
     }
     }
 
 
-    $downloader = new $formatter($this->bundle_name, $this->ids, $supported_fields, $outfile, $this->user->uid);
+    $downloader = new $formatter($this->bundles, $this->ids, $supported_fields, $outfile, $this->user->uid);
     $downloader->write();
     $downloader->write();
 
 
   }
   }
-}
+}

+ 3 - 3
tripal/includes/tripal.admin.inc

@@ -21,11 +21,11 @@ function tripal_admin_data_collection_form($form, &$form_state) {
   $form['lifespan'] = array(
   $form['lifespan'] = array(
     '#type' => 'textfield',
     '#type' => 'textfield',
     '#title' => t('Collection Lifespan'),
     '#title' => t('Collection Lifespan'),
-    '#description' => t('Enter the number of hours (e.g. 24 is 1 day, 720 is 30 days)
-       that data collections exist.  Collections will be automatically removed after the lifespan
+    '#description' => t('Enter the number of days that data collections exist.  
+       Collections will be automatically removed after the lifespan
        period has passed.  Removal of data collections occurs when the
        period has passed.  Removal of data collections occurs when the
        sites Drupal cron executes.'),
        sites Drupal cron executes.'),
-    '#default_value' => variable_get('tripal_data_collections_lifespan', 7),
+    '#default_value' => variable_get('tripal_data_collections_lifespan', 30),
     '#required' => TRUE,
     '#required' => TRUE,
   );
   );
 
 

+ 36 - 1
tripal/includes/tripal.collections.inc

@@ -46,6 +46,7 @@ function tripal_user_collections_page() {
         $collection->getCreateDate(),
         $collection->getCreateDate(),
         $download_list,
         $download_list,
         l('Delete', 'user/' . $user->uid . '/data-collections/' . $collection_id . '/delete'),
         l('Delete', 'user/' . $user->uid . '/data-collections/' . $collection_id . '/delete'),
+        l('Generate File for Download', 'user/' . $user->uid . '/data-collections/' . $collection_id . '/generate'),
       ),
       ),
     );
     );
   }
   }
@@ -111,4 +112,38 @@ function tripal_user_collections_delete_form_submit($form, &$form_state) {
     }
     }
   }
   }
   drupal_goto('user/' . $user->uid . '/data-collections');
   drupal_goto('user/' . $user->uid . '/data-collections');
-}
+}
+
+function tripal_user_collections_generate_file($form, &$form_state,  $uid, $collection_id) {
+  $form_state['collection_id'] = $collection_id;
+  $form['#submit'][] = 'tripal_user_collections_delete_form_submit';
+
+  $collection  = new TripalEntityCollection();
+  $collection->load($collection_id);
+
+  $form = confirm_form($form,
+      t('Click the button below to generate the collection filed: %title',
+          array('%title' => $collection->getName())), 'user/' . $uid . '/data-collections',
+      '<p>' .t('This action cannot be undone.') .'</p>', t('Generate File'), t('Cancel'), 'confirm');
+
+  return $form;
+}
+/**
+ * Deletes a user's collection.
+ *
+ * @param $collection_id
+ *   The ID of the collection to delete.
+ */
+function tripal_user_collections_generate_file_submit($form, &$form_state) {
+  global $user;
+  $collection_id = $form_state['collection_id'];
+  $collection  = new TripalEntityCollection();
+  $collection->load($collection_id);
+
+  // Add the job to write the collection download files.
+  $args = array($collection_id);
+  tripal_add_job('Create data collection files for ' . $user->name, 'tripal',
+      'tripal_create_collection_files', $args, $user->uid, 10, array());
+      
+  drupal_goto('user/' . $user->uid . '/data-collections');
+}

+ 11 - 0
tripal/tripal.module

@@ -361,6 +361,17 @@ function tripal_menu() {
     'file' => 'includes/tripal.collections.inc',
     'file' => 'includes/tripal.collections.inc',
     'file path' => drupal_get_path('module', 'tripal'),
     'file path' => drupal_get_path('module', 'tripal'),
   );
   );
+  $items['user/%/data-collections/%/generate'] = array (
+    'title' => 'Generate a file for download of a Collections',
+    'description' => 'Deletes a data collection.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_user_collections_generate_file', 1, 3),
+    'access callback' => 'tripal_accesss_user_collections',
+    'access arguments' => array(1),
+    'type' => MENU_CALLBACK,
+    'file' => 'includes/tripal.collections.inc',
+    'file path' => drupal_get_path('module', 'tripal'),
+  );
 
 
   $items['admin/tripal/data-collections'] = array(
   $items['admin/tripal/data-collections'] = array(
     'title' => 'Data Collections',
     'title' => 'Data Collections',