You are here

function party_hat_hats_unassign in Party 8.2

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

Unassign hats

Parameters

$party:

$hats: An array of hat maching names to unassign.

1 call to party_hat_hats_unassign()
party_hat_rules_unassign_hat in modules/party_hat/party_hat.rules.inc
Implement the unassign hat rule.

File

modules/party_hat/party_hat.module, line 484
party_hat.module Provides an extensible access system for parties.

Code

function party_hat_hats_unassign($party, $hats) {

  // Get the hat items from the party object
  $hat_items = field_get_items('party', $party, 'party_hat');
  foreach ($hats as $hat) {
    $has_hat = FALSE;
    foreach ($hat_items as $delta => $item) {
      if ($item['hat_name'] == $hat) {
        $has_hat = TRUE;
        unset($hat_items[$delta]);
      }
    }

    // Don't remove the hat if its not assigned
    if (!$has_hat) {
      continue;
    }
    $unassigned_hats[] = $hat;
  }
  $party->party_hat[LANGUAGE_NONE] = $hat_items;
  party_save($party);
  if (isset($unassigned_hats)) {
    if (module_exists('rules')) {
      rules_invoke_all('party_hat_unassign_hats', $party, $unassigned_hats);
    }
    else {
      module_invoke_all('party_hat_unassign_hats', $party, $unassigned_hats);
    }
  }
}