Solar_Sql_Adapter::_selectCompound PHP Method

_selectCompound() protected method

Builds a compound SELECT command string from its component parts, without the LIMIT portions; those are left to the individual adapters.
protected _selectCompound ( array $parts ) : string
$parts array The parts of the SELECT statement, generally from a Solar_Sql_Select object.
return string A SELECT command string.
    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;
    }