public function PartyQuery::joinAttachedEntity in Party 7
Same name and namespace in other branches
- 8.2 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 92 - 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 to the entity table.
$data_set_key = implode(':', array(
$data_set['set_name'],
$delta,
$type,
));
if (!isset($alias)) {
$alias = $data_set['set_name'];
}
// Find or create our join.
if (!isset($this->data_sets[$data_set_key])) {
// Start with the party_attached_entity table.
$data_set_placeholder = ':data_set_' . $this
->nextPlaceholder();
$conditions = "%alias.pid = {$this->base_alias}.pid AND %alias.data_set = {$data_set_placeholder}";
$arguments = array(
$data_set_placeholder => $data_set['set_name'],
);
// If we're joining a specific delta, we need some additional conditions.
if (isset($delta)) {
$delta_placeholder = ':delta_' . $this
->nextPlaceholder();
$conditions .= " AND %alias.delta = {$delta_placeholder}";
$arguments[$delta_placeholder] = $delta;
}
$pae_alias = $this
->addJoin($type, 'party_attached_entity', 'pae', $conditions, $arguments);
// 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'],
)));
}
// Create our join.
$this->data_sets[$data_set_key] = $this
->addJoin($type, $entity_info['base table'], $alias, "%alias.{$entity_info['entity keys']['id']} = {$pae_alias}.eid");
}
return $this->data_sets[$data_set_key];
}