protected function _selectCompound($parts)
{
// the select statement to build up
$stmt = '';
// default parts of each 'compound' element
$default = array('type' => null, 'spec' => null);
// combine the compound elements
foreach ((array) $parts['compound'] as $compound) {
// make sure we have the default elements
$compound = array_merge($default, $compound);
// is it an array of select parts?
if (is_array($compound['spec'])) {
// yes, build a select string from them
$select = $this->_select($compound['spec']);
} else {
// no, assume it's already a select string
$select = $compound['spec'];
}
// do we need to add the compound type?
// note that the first compound type will be ignored.
if ($stmt) {
$stmt .= strtoupper($compound['type']) . "\n";
}
// now add the select itself
$stmt .= "(" . $select . ")\n";
}
// add any overall order
if (!empty($parts['order'])) {
$stmt .= "ORDER BY\n ";
$stmt .= implode(",\n ", $parts['order']) . "\n";
}
// done!
return $stmt;
}