QQNode::GetColumnAlias PHP Method

GetColumnAlias() public method

public GetColumnAlias ( QQueryBuilder $objBuilder, $blnExpandSelection = false, QQCondition $objJoinCondition = null )
$objBuilder QQueryBuilder
$objJoinCondition QQCondition
    public function GetColumnAlias(QQueryBuilder $objBuilder, $blnExpandSelection = false, QQCondition $objJoinCondition = null)
    {
        // Make sure our Root Tables Match
        if ($this->_RootTableName != $objBuilder->RootTableName) {
            throw new QCallerException('Cannot use QQNode for "' . $this->_RootTableName . '" when querying against the "' . $objBuilder->RootTableName . '" table', 3);
        }
        // Pull the Begin and End Escape Identifiers from the Database Adapter
        $strBegin = $objBuilder->Database->EscapeIdentifierBegin;
        $strEnd = $objBuilder->Database->EscapeIdentifierEnd;
        // If we are a standard QQNode at the top level column, simply return the column name
        if (get_class($this) == 'QQNode' && is_null($this->objParentNode->_Type)) {
            return sprintf('%s%s%s.%s%s%s', $strBegin, $objBuilder->GetTableAlias($this->objParentNode->_Name), $strEnd, $strBegin, $this->strName, $strEnd);
        } else {
            // Use the Helper to Iterate Through the Parent Chain and get the Parent Alias
            try {
                $strParentAlias = $this->objParentNode->GetColumnAliasHelper($objBuilder, $strBegin, $strEnd, $blnExpandSelection);
                if ($this->strTableName) {
                    // Next, Join the Appropriate Table
                    $objBuilder->AddJoinItem($this->strTableName, $strParentAlias . '__' . $this->strName, $strParentAlias, $this->strName, $this->strPrimaryKey, $objJoinCondition);
                    if ($blnExpandSelection) {
                        call_user_func(array($this->strClassName, 'GetSelectFields'), $objBuilder, $strParentAlias . '__' . $this->strName);
                    }
                }
            } catch (QCallerException $objExc) {
                $objExc->IncrementOffset();
                throw $objExc;
            }
            // Finally, return the final column alias name (Parent Prefix with Current Node Name)
            return sprintf('%s%s%s.%s%s%s', $strBegin, $objBuilder->GetTableAlias($strParentAlias), $strEnd, $strBegin, $this->strName, $strEnd);
        }
    }

Usage Example

Example #1
0
 public function UpdateQueryBuilder(QQueryBuilder $objBuilder)
 {
     if ($this->objNode instanceof QQAssociationNode) {
         $this->objNode->_ChildTableNode->GetColumnAlias($objBuilder, true, null, $this->objSelect);
     } else {
         $this->objNode->GetColumnAlias($objBuilder, true, null, $this->objSelect);
     }
     $objBuilder->AddExpandAsArrayNode($this->objNode);
 }
All Usage Examples Of QQNode::GetColumnAlias