You are here

function party_user_create_party_for_user in Party 8.2

Same name and namespace in other branches
  1. 7 modules/party_user/party_user.module \party_user_create_party_for_user()

party_user_create_party_for_user

Create a Party for a user and relate them

Parameters

mixed $user The user object or ID:

array $options Hardcoded options to get passed to party_create:

Return value

Party a Party object

See also

party_create

1 call to party_user_create_party_for_user()
party_user_batch_user_sync in modules/party_user/party_user.batch.inc
@file Batch Processor for User Sync

File

modules/party_user/party_user.module, line 341
Support for linking users to parties

Code

function party_user_create_party_for_user($user, $options = array()) {
  $party = party_create($options);
  if (module_exists('party_hat')) {

    // Add in our hats.
    $hats = array();
    foreach (variable_get('party_user_registration_hats', array()) as $hat_name) {
      $hats[] = $hat_name;
    }
    party_hat_hats_assign($party, $hats);
  }
  party_save($party);
  $data_set_controller = party_get_crm_controller($party, 'user');
  $account = is_object($user) ? $user : user_load($user);
  $data_set_controller
    ->attachEntity($account);
  $data_set_controller
    ->save();

  // This will fail if a plugin that relies on anything other than user is used
  $party = party_save($party);
}