You are here

function party_user_create_party_for_user in Party 7

Same name and namespace in other branches
  1. 8.2 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 229
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, FALSE);
  }
  party_save($party);
  $account = is_object($user) ? $user : user_load($user);
  $party
    ->getDataSetController('user')
    ->attachEntity($account)
    ->save();
  return $party;
}