function tripal_create_collection
3.x tripal.collections.api.inc | tripal_create_collection($details) |
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.
Parameters
$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.
Return value
TripalEntityCollection An instance of a TripalEntityCollection class or FALSE on failure.
Related topics
1 call to tripal_create_collection()
- tripal_views_handler_area_collections_form_submit in tripal/
views_handlers/ tripal_views_handler_area_collections.inc
File
- tripal/
api/ tripal.collections.api.inc, line 47 - Provides the API for working with Data collections. This includes creation, experiation, and retreival.
Code
function tripal_create_collection($details) {
global $user;
try {
$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 to generate file links.",
array(
'%name' => $details['collection_name'],
'%num_recs' => count($details['ids']),
'!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;
}
}