protected function autoJoinTables(array $options)
{
// we must be careful that the query doesn't specify any options that may join
// tables or change the selected columns
if (!is_array($options['types']) || count($options['types']) !== 1 || !empty($options['selects']) || !empty($options['wheres']) || !empty($options['joins']) || $options['callback'] !== 'entity_row_to_elggstar' || $options['count']) {
// Too dangerous to auto-join
return $options;
}
$join_types = ['object' => 'ElggObject', 'user' => 'ElggUser', 'group' => 'ElggGroup', 'site' => 'ElggSite'];
// We use reset() because $options['types'] may not have a numeric key
$type = reset($options['types']);
if (empty($join_types[$type])) {
return $options;
}
// Get the columns we'll need to select. We can't use st.* because the order_by
// clause may reference "guid", which MySQL will complain about being ambiguous
if (!is_callable([$join_types[$type], 'getExternalAttributes'])) {
// for some reason can't get external attributes.
return $options;
}
$attributes = $join_types[$type]::getExternalAttributes();
foreach (array_keys($attributes) as $col) {
$options['selects'][] = "st.{$col}";
}
// join the secondary table
$options['joins'][] = "JOIN {$this->db->prefix}{$type}s_entity st ON (e.guid = st.guid)";
return $options;
}