public function PartyQuery::joinAttachedEntity in Party 8.2
Same name and namespace in other branches
- 7 includes/party.extender.inc \PartyQuery::joinAttachedEntity()
Create a join to an attached entity.
Parameters
$data_set string|array: Either a data set name or a data set array.
$delta int: Optionally provide a delta to join to.
$type string: The type of join. Typically one of INNER, LEFT OUTER and RIGHT OUTER. Defaults to INNER.
Return value
string The table alias for the attached entity.
2 calls to PartyQuery::joinAttachedEntity()
- PartyQuery::joinField in includes/
party.extender.inc - Create a join to an field on an attached entity.
- PartyQuery::propertyCondition in includes/
party.extender.inc - Set a simple property condition on an attached entity.
File
- includes/
party.extender.inc, line 98 - Class to aid querying parties and attached entities.
Class
- PartyQuery
- Query extender for party attached entities.
Code
public function joinAttachedEntity($data_set, $alias = NULL, $delta = NULL, $type = 'INNER') {
// Get hold of our data set definition.
if (is_scalar($data_set)) {
$data_set_definition = party_get_data_set_info($data_set);
if (empty($data_set_definition)) {
throw new Exception(t('Unknown data set: @data_set', array(
'@data_set' => $data_set,
)));
}
$data_set = $data_set_definition;
}
// Find or create our join the the party_attached_entity table.
if (!isset($this->party_attached_entity[$type])) {
$this->party_attached_entity[$type] = $this
->addJoin($type, 'party_attached_entity', 'pae', "%alias.pid = {$this->base_alias}.pid");
}
$pae_alias = $this->party_attached_entity[$type];
// Find or create our join to the entity table.
$data_set_key = implode(':', array(
$data_set['set_name'],
$delta,
$type,
));
if (!isset($this->data_sets[$data_set_key])) {
// Get hold of our entity info for building our join.
$entity_info = entity_get_info($data_set['entity type']);
if (empty($entity_info)) {
throw new Exception(t('Unknown entity: @entity_type', array(
'@entity_type' => $data_set['entity type'],
)));
}
// Build our conditions as an array which we'll implode with ANDs.
$conditions = array(
"%alias.{$entity_info['entity keys']['id']} = {$pae_alias}.eid",
"{$pae_alias}.data_set = :data_set",
);
// Build our arguments array.
$arguments = array(
':data_set' => $data_set['set_name'],
);
// If we're joining a specific delta, we need some additional conditions.
if (isset($delta)) {
$conditions[] = "{$pae_alias}.delta = :delta";
$arguments[':delta'] = $delta;
}
// Create our join.
$this->data_sets[$data_set_key] = $this
->addJoin($type, $entity_info['base table'], $data_set['set_name'], implode(' AND ', $conditions), $arguments);
}
return $this->data_sets[$data_set_key];
}