You are here

function party_devel_generate_party_add_party in Party 8.2

Same name and namespace in other branches
  1. 7 modules/party_devel/devel_generate.inc \party_devel_generate_party_add_party()

Create one party. Used by both batch and non-batch code branches.

Parameters

$results: array of options

2 calls to party_devel_generate_party_add_party()
party_devel_generate_batch_parties_add_party in modules/party_devel/devel_generate_batch.inc
party_devel_generate_parties in modules/party_devel/devel_generate.inc
The main API function for creating parties

File

modules/party_devel/devel_generate.inc, line 67
Devel generate code.

Code

function party_devel_generate_party_add_party(&$results) {
  $party = array();
  $party = party_create($party);

  // Insert new data:
  // Save default parameters back into the $product object.
  $party->merged = 0;
  $party->language = LANGUAGE_NONE;

  // Save party fields
  module_load_include('inc', 'devel_generate', 'devel_generate.fields');
  devel_generate_fields($party, 'party', 'party');

  // save the party
  $party
    ->save();
  $users = $results['users'];

  // If party_user is enabled sometimes attach a user
  if (module_exists('party_user') && rand(0, 2) > 1) {
    $uid = $users[array_rand($users)];
    party_attach_entity($party, $uid, 'user');
  }

  // Attach a selection of data sets
  $data_sets = party_get_party_data_sets($party);
  foreach ($data_sets as $id => $name) {
    if ($name == 'user') {
      continue;
    }
    $data_set_controller = party_get_crm_controller($party, $name);
    $entity = $data_set_controller
      ->getEntity(0, TRUE);

    // Devel generate requires that a language be set.
    if (!isset($entity->language)) {
      $entity->language = LANGUAGE_NONE;
    }
    module_load_include('inc', 'devel_generate', 'devel_generate.fields');
    devel_generate_fields($entity, $data_set_controller
      ->getDataInfo('entity type'), $data_set_controller
      ->getDataInfo('entity bundle'));
    if (field_info_instance($data_set_controller
      ->getDataInfo('entity type'), 'field_name', $data_set_controller
      ->getDataInfo('entity bundle'))) {
      $entity->field_name[LANGUAGE_NONE][0]['value'] = party_generate_label();
    }
    entity_save($data_set_controller
      ->getDataInfo('entity type'), $entity);
    $party
      ->save();
  }
}