You are here

protected function PartyAcquisition::findMatch in Party 7

Find a match for the given parameters.

Parameters

array $values: An array of party fields to match on. Keys are the field and values are the expected values.

Return value

Party|FALSE Return the matched party or FALSE if no valid match could be found.

1 call to PartyAcquisition::findMatch()
PartyAcquisition::acquire in includes/party.acquisition.inc
Create or acquire a party based off the given parameters.

File

includes/party.acquisition.inc, line 201
Base classes for acquisition processes.

Class

PartyAcquisition
Base class for acquiring parties.

Code

protected function findMatch(array $values) {
  $query = $this
    ->buildQuery($values);

  // If we are set to take the first, we don't need to return more than one.
  // Otherwise return 2 matches so we can ignore multiple matches.
  $limit = $this->context['behavior'] & self::BEHAVIOR_FIRST ? 1 : 2;
  $query
    ->range(0, $limit);

  // Get hold of our results.
  $results = $query
    ->execute()
    ->fetchCol();

  // If we got a single match we can return a party..
  if (count($results) == 1) {
    return party_load(reset($results));
  }

  // Store something helpful in $context.
  $this->context['fail'] = count($results) ? self::FAIL_MULTIPLE_MATCHES : self::FAIL_NO_MATCHES;

  // Otherwise we have nothing to return.
  return FALSE;
}