You are here

public function PartyDefaultDataSet::__construct in Party 7

Same name and namespace in other branches
  1. 8.2 includes/party.data.inc \PartyDefaultDataSet::__construct()

Constructor

Parameters

string $data_set: The data set name.

party $party: The party object.

File

includes/party.data.inc, line 238
Provides the default class for managing party - Attached entity relationships.

Class

PartyDefaultDataSet
Class PartyDefaultDataSet

Code

public function __construct($data_set, Party $party) {

  // Check that this is a valid data set
  if (party_get_data_set_info($data_set)) {
    $this->data_set = $data_set;
  }
  else {

    // Throw an exception.
    throw new Exception(t('Failed to construct data set controller for invalid dataset %data_set.', array(
      '%data_set' => $data_set,
    )));
  }
  $this->party = $party;
  if (!empty($this->party->pid)) {

    // Without attached entities, this controller is pretty useless, so let's
    // assume anyone wants them loaded, but we'll do so using stubs to save a
    // full entity load.
    $query = db_select('party_attached_entity', 'ae')
      ->fields('ae', array(
      'delta',
      'eid',
    ))
      ->condition('pid', $this->party->pid, '=')
      ->condition('data_set', $this->data_set);
    $result = $query
      ->execute()
      ->fetchAllAssoc('delta');

    // Iterate over our results creating stub entities, setting a flag for us
    // to detect that it is a stub.
    foreach ($result as $delta => $entity) {
      $this->entities[$delta] = entity_create_stub_entity($this
        ->getDataInfo('entity type'), array(
        0 => $entity->eid,
        2 => $this
          ->getDataInfo('entity bundle'),
      ));
      $this->entities[$delta]->is_stub = TRUE;
    }
  }
}