|
@@ -60,10 +60,16 @@ class TripalEntityCollection {
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
+ // Delete from the tripal collection table.
|
|
|
db_delete('tripal_collection')
|
|
|
->condition('collection_id', $this->collection_id)
|
|
|
->execute();
|
|
|
|
|
|
+ // Delete the field groups from the tripal_bundle_collection table.
|
|
|
+ db_delete('tripal_collection_bundle')
|
|
|
+ ->condition('collection_id', $this->collection_id)
|
|
|
+ ->execute();
|
|
|
+
|
|
|
// Remove any files that may have been created
|
|
|
foreach ($this->downloaders as $class_name => $label) {
|
|
|
tripal_load_include_downloader_class($class_name);
|
|
@@ -125,7 +131,7 @@ class TripalEntityCollection {
|
|
|
$bundle_name = "";
|
|
|
if (count($this->bundles) > 1) {
|
|
|
foreach ($this->bundles as $bundle) {
|
|
|
- $bundle_name = $this->bundles[0]->bundle_name;
|
|
|
+ $bundle_name = $bundle->bundle_name;
|
|
|
$ids[$bundle_name] = $this->getEntityIDs($bundle_name);
|
|
|
$fields[$bundle_name] = $this->getFields($bundle_name);
|
|
|
}
|
|
@@ -144,30 +150,66 @@ class TripalEntityCollection {
|
|
|
// supported for this basket.
|
|
|
foreach ($this->fields as $field_group) {
|
|
|
foreach ($field_group as $field_id) {
|
|
|
- $field = field_info_field_by_id($field_id);
|
|
|
- if (!$field) {
|
|
|
- continue;
|
|
|
+ // Check is $field_groups is an array because if it is that means we
|
|
|
+ // nested arrays we need to deal with.
|
|
|
+ if (is_array($field_id)) {
|
|
|
+ foreach ($field_id as $field) {
|
|
|
+ $field_info = field_info_field_by_id($field);
|
|
|
+ if (!$field_info) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $field_name = $field_info['field_name'];
|
|
|
+ $field_type = $field_info['type'];
|
|
|
+ $field_module = $field_info['module'];
|
|
|
+ $instance = field_info_instance('TripalEntity', $field_name, $bundle_name);
|
|
|
+
|
|
|
+ $downloaders = array();
|
|
|
+
|
|
|
+ // All fields should support the Tab and CSV downloaders.
|
|
|
+ tripal_load_include_downloader_class('TripalTabDownloader');
|
|
|
+ $this->downloaders['TripalTabDownloader'] = TripalTabDownloader::$label;
|
|
|
+ tripal_load_include_downloader_class('TripalCSVDownloader');
|
|
|
+ $this->downloaders['TripalCSVDownloader'] = TripalCSVDownloader::$label;
|
|
|
+
|
|
|
+ if (tripal_load_include_field_class($field_type)) {
|
|
|
+ $settings = $field_type::$default_instance_settings;
|
|
|
+ if (array_key_exists('download_formatters', $settings)) {
|
|
|
+ foreach ($settings['download_formatters'] as $class_name) {
|
|
|
+ if (!array_key_exists($class_name, $this->downloaders)) {
|
|
|
+ tripal_load_include_downloader_class($class_name);
|
|
|
+ $this->downloaders[$class_name] = $class_name::$label;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- $field_name = $field['field_name'];
|
|
|
- $field_type = $field['type'];
|
|
|
- $field_module = $field['module'];
|
|
|
- $instance = field_info_instance('TripalEntity', $field_name, $bundle_name);
|
|
|
-
|
|
|
- $downloaders = array();
|
|
|
-
|
|
|
- // All fields should support the Tab and CSV downloaders.
|
|
|
- tripal_load_include_downloader_class('TripalTabDownloader');
|
|
|
- $this->downloaders['TripalTabDownloader'] = TripalTabDownloader::$label;
|
|
|
- tripal_load_include_downloader_class('TripalCSVDownloader');
|
|
|
- $this->downloaders['TripalCSVDownloader'] = TripalCSVDownloader::$label;
|
|
|
-
|
|
|
- if (tripal_load_include_field_class($field_type)) {
|
|
|
- $settings = $field_type::$default_instance_settings;
|
|
|
- if (array_key_exists('download_formatters', $settings)) {
|
|
|
- foreach ($settings['download_formatters'] as $class_name) {
|
|
|
- if (!array_key_exists($class_name, $this->downloaders)) {
|
|
|
- tripal_load_include_downloader_class($class_name);
|
|
|
- $this->downloaders[$class_name] = $class_name::$label;
|
|
|
+ else {
|
|
|
+ $field = field_info_field_by_id($field_id);
|
|
|
+ if (!$field) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $field_name = $field['field_name'];
|
|
|
+ $field_type = $field['type'];
|
|
|
+ $field_module = $field['module'];
|
|
|
+ $instance = field_info_instance('TripalEntity', $field_name, $bundle_name);
|
|
|
+
|
|
|
+ $downloaders = array();
|
|
|
+
|
|
|
+ // All fields should support the Tab and CSV downloaders.
|
|
|
+ tripal_load_include_downloader_class('TripalTabDownloader');
|
|
|
+ $this->downloaders['TripalTabDownloader'] = TripalTabDownloader::$label;
|
|
|
+ tripal_load_include_downloader_class('TripalCSVDownloader');
|
|
|
+ $this->downloaders['TripalCSVDownloader'] = TripalCSVDownloader::$label;
|
|
|
+
|
|
|
+ if (tripal_load_include_field_class($field_type)) {
|
|
|
+ $settings = $field_type::$default_instance_settings;
|
|
|
+ if (array_key_exists('download_formatters', $settings)) {
|
|
|
+ foreach ($settings['download_formatters'] as $class_name) {
|
|
|
+ if (!array_key_exists($class_name, $this->downloaders)) {
|
|
|
+ tripal_load_include_downloader_class($class_name);
|
|
|
+ $this->downloaders[$class_name] = $class_name::$label;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -177,16 +219,14 @@ class TripalEntityCollection {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Creates a new collection.
|
|
|
+ * Creates a new unique collection ID used as a look up against the
|
|
|
+ * tripal_collection_bundle to find fields, ids, and bundles.
|
|
|
*
|
|
|
* @param $details
|
|
|
* An association array containing the details for a collection. The
|
|
|
* details must include the following key/value pairs:
|
|
|
* - uid: The ID of the user that owns the collection
|
|
|
* - collection_name: The name of the collection
|
|
|
- * - bundle_name: The name of the TripalEntity content type.
|
|
|
- * - ids: An array of the entity IDs that form the collection.
|
|
|
- * - fields: An array of the field IDs that the collection is limited to.
|
|
|
* - description: A user supplied description for the collection.
|
|
|
*
|
|
|
* @throws Exception
|
|
@@ -222,7 +262,7 @@ class TripalEntityCollection {
|
|
|
))
|
|
|
->execute();
|
|
|
// Now add the second table with bundle info.
|
|
|
- $this->add($details, $collection_id);
|
|
|
+ $this->addFields($details, $collection_id);
|
|
|
// Now load the job into this object.
|
|
|
$this->load($collection_id);
|
|
|
}
|
|
@@ -243,7 +283,7 @@ class TripalEntityCollection {
|
|
|
*
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
- public function add($details, $collection_id) {
|
|
|
+ public function addFields($details, $collection_id) {
|
|
|
if (!$details['bundle_name']) {
|
|
|
throw new Exception("Must provide a 'bundle_name' key to TripalEntityCollection::add().");
|
|
|
}
|
|
@@ -446,7 +486,6 @@ class TripalEntityCollection {
|
|
|
$extension = $formatter::$default_extension;
|
|
|
$create_date = $this->getCreateDate(FALSE);
|
|
|
$outfile = preg_replace('/[^\w]/', '_', ucwords($this->collection_name)) . '_collection' . '_' . $create_date . '.' . $extension;
|
|
|
-
|
|
|
return $outfile;
|
|
|
}
|
|
|
|
|
@@ -486,7 +525,6 @@ class TripalEntityCollection {
|
|
|
*/
|
|
|
public function getOutfileURL($formatter) {
|
|
|
$outfile = $this->getOutfilePath($formatter);
|
|
|
- return file_create_url($outfile);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -508,10 +546,10 @@ class TripalEntityCollection {
|
|
|
}
|
|
|
|
|
|
$outfile = $this->getOutfile($formatter);
|
|
|
-
|
|
|
- $downloader = new $formatter($this->bundles, $this->ids, $this->fields, $outfile, $this->user->uid);
|
|
|
-
|
|
|
- return $downloader->getURL();
|
|
|
+ // Make sure the user directory exists
|
|
|
+ $user_dir = 'public://tripal/users/' . $this->user->uid;
|
|
|
+ $outfilePath = $user_dir. '/' . $outfile;
|
|
|
+ return $outfilePath;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -539,33 +577,62 @@ class TripalEntityCollection {
|
|
|
$supported_fields = array();
|
|
|
foreach ($this->fields as $field_group) {
|
|
|
foreach ($field_group as $field_id) {
|
|
|
- // If the formatter is TripalTabDownloader or TripalCSVDownloader then
|
|
|
- // we always want to support the field.
|
|
|
- if ($formatter == 'TripalTabDownloader' or $formatter == 'TripalCSVDownloader') {
|
|
|
- if (!in_array($field_id, $supported_fields)) {
|
|
|
- $supported_fields[] = $field_id;
|
|
|
+ // Check is $field_id is an array because if it is that means we
|
|
|
+ // nested arrays we need to deal with.
|
|
|
+ if (is_array($field_id)) {
|
|
|
+ foreach ($field_id as $field) {
|
|
|
+ // If the formatter is TripalTabDownloader or TripalCSVDownloader then
|
|
|
+ // we always want to support the field.
|
|
|
+ if ($formatter == 'TripalTabDownloader' or $formatter == 'TripalCSVDownloader') {
|
|
|
+ if (!in_array($field, $supported_fields)) {
|
|
|
+ $supported_fields[] = $field;
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Otherwise, find out if the formatter specified is supporte by the
|
|
|
+ // field and if so then add it to our list of supported fields.
|
|
|
+ $field_info = field_info_field_by_id($field);
|
|
|
+ $field_name = $field_info['field_name'];
|
|
|
+ $field_type = $field_info['type'];
|
|
|
+ if (tripal_load_include_field_class($field_type)) {
|
|
|
+ $settings = $field_type::$default_instance_settings;
|
|
|
+ if (array_key_exists('download_formatters', $settings)) {
|
|
|
+ if (in_array($formatter, $settings['download_formatters'])) {
|
|
|
+ $supported_fields[] = $field;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- continue;
|
|
|
}
|
|
|
-
|
|
|
- // Otherwise, find out if the formatter specified is supporte by the
|
|
|
- // field and if so then add it to our list of supported fields.
|
|
|
- $field = field_info_field_by_id($field_id);
|
|
|
- $field_name = $field['field_name'];
|
|
|
- $field_type = $field['type'];
|
|
|
- if (tripal_load_include_field_class($field_type)) {
|
|
|
- $settings = $field_type::$default_instance_settings;
|
|
|
- if (array_key_exists('download_formatters', $settings)) {
|
|
|
- if (in_array($formatter, $settings['download_formatters'])) {
|
|
|
+ else {
|
|
|
+ // If the formatter is TripalTabDownloader or TripalCSVDownloader then
|
|
|
+ // we always want to support the field.
|
|
|
+ if ($formatter == 'TripalTabDownloader' or $formatter == 'TripalCSVDownloader') {
|
|
|
+ if (!in_array($field_id, $supported_fields)) {
|
|
|
$supported_fields[] = $field_id;
|
|
|
}
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Otherwise, find out if the formatter specified is supporte by the
|
|
|
+ // field and if so then add it to our list of supported fields.
|
|
|
+ $field = field_info_field_by_id($field_id);
|
|
|
+ $field_name = $field['field_name'];
|
|
|
+ $field_type = $field['type'];
|
|
|
+ if (tripal_load_include_field_class($field_type)) {
|
|
|
+ $settings = $field_type::$default_instance_settings;
|
|
|
+ if (array_key_exists('download_formatters', $settings)) {
|
|
|
+ if (in_array($formatter, $settings['download_formatters'])) {
|
|
|
+ $supported_fields[] = $field_id;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$downloader = new $formatter($this->bundles, $this->ids, $supported_fields, $outfile, $this->user->uid);
|
|
|
- //print_r($downloader);
|
|
|
$downloader->write();
|
|
|
|
|
|
}
|