Browse Source

Fixed bug with creating collection in views

Stephen Ficklin 7 years ago
parent
commit
d26f0d365c

+ 7 - 2
tripal/api/tripal.collections.api.inc

@@ -25,6 +25,10 @@
 /**
  * Creates a collection of entities for a given user.
  *
+ * Use this function if you want to create a new collection with an bundle.
+ * Otherwise, a new colleciton can also be created by creating an new instance
+ * of a TripalEntityCollection object.
+ *
  * @param  $details
  *   An association array containing the details for a collection. The
  *   details must include the following key/value pairs:
@@ -47,6 +51,7 @@ function tripal_create_collection($details) {
     $collection = new TripalEntityCollection();
     $collection->create($details);
     $collection_id = $collection->getCollectionID();
+    $collection->addBundle($details);
 
     drupal_set_message(t("Collection '%name' created with %num_recs record(s). Check the !view for generate file links.",
       array(
@@ -55,13 +60,13 @@ function tripal_create_collection($details) {
         '!view' => l('data collections page', 'user/' . $user->uid . '/data-collections'),
       ))
     );
-
+    return $collection;
   }
   catch (Exception $e) {
     drupal_set_message(t("Failed to create the collection '%name': " . $e->getMessage(), array('%name' =>  $details['collection_name'])), 'error');
     return FALSE;
   }
-  return $collection;
+
 }
 
 /**

+ 3 - 3
tripal/includes/TripalEntityCollection.inc

@@ -207,7 +207,7 @@ class TripalEntityCollection {
    *
    * @throws Exception
    */
-  public function addBundle($details, $collection_id) {
+  public function addBundle($details) {
     if (!$details['bundle_name']) {
       throw new Exception("Must provide a 'bundle_name' to TripalEntityCollection::addFields().");
     }
@@ -224,12 +224,12 @@ class TripalEntityCollection {
           'bundle_name' => $details['bundle_name'],
           'ids' => serialize($details['ids']),
           'fields' => serialize($details['fields']),
-          'collection_id' => $collection_id,
+          'collection_id' => $this->collection_id,
         ))
         ->execute();
 
       // Now load the job into this object.
-      $this->load($collection_id);
+      $this->load($this->collection_id);
     }
     catch (Exception $e) {
       throw new Exception('Cannot create collection: ' . $e->getMessage());

+ 5 - 3
tripal/includes/TripalJob.inc

@@ -283,9 +283,11 @@ class TripalJob {
     try {
 
       // Include the necessary files needed to run the job.
-      foreach ($this->job->includes as $path) {
-        if ($path) {
-          require_once $path;
+      if (is_array($this->job->includes)) {
+        foreach ($this->job->includes as $path) {
+          if ($path) {
+            require_once $path;
+          }
         }
       }
 

+ 1 - 2
tripal/views_handlers/tripal_views_handler_area_collections.inc

@@ -261,7 +261,6 @@ function tripal_views_handler_area_collections_form_submit($form, $form_state) {
     }
   }
 
-
   // Get the entity Ids that match results
   $query->range['length'] = $view->total_rows;
   $results = $query->execute();
@@ -272,9 +271,9 @@ function tripal_views_handler_area_collections_form_submit($form, $form_state) {
   $collection = tripal_create_collection(array(
     'uid'  => $uid,
     'collection_name' => $collection_name,
+    'description'  => $description,
     'bundle_name' => $bundle_name,
     'ids' => $entities,
     'fields' => $selected_fids,
-    'description'  => $description,
   ));
 }