public function TripalEntityCollection::addBundle

3.x TripalEntityCollection.inc public TripalEntityCollection::addBundle($details)

Creates a new tripal_collection_bundle entry.

Parameters

$details: An association array containing the details for a collection. The details must include the following key/value pairs:

  • 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.

Throws

Exception

File

tripal/includes/TripalEntityCollection.inc, line 210

Class

TripalEntityCollection

Code

public function addBundle($details) {
  if (!$details['bundle_name']) {
    throw new Exception("Must provide a 'bundle_name' to TripalEntityCollection::addFields().");
  }
  if (!$details['ids']) {
    throw new Exception("Must provide a 'ids' to TripalEntityCollection::addFields().");
  }
  if (!$details['fields']) {
    throw new Exception("Must provide a 'fields' to TripalEntityCollection::addFields().");
  }

  try {
    $collection_bundle_id = db_insert('tripal_collection_bundle')
      ->fields(array(
        'bundle_name' => $details['bundle_name'],
        'ids' => serialize($details['ids']),
        'fields' => serialize($details['fields']),
        'collection_id' => $this->collection_id,
      ))
      ->execute();

    // Now load the job into this object.
    $this->load($this->collection_id);
  }
  catch (Exception $e) {
    throw new Exception('Cannot create collection: ' . $e->getMessage());
  }
}