QQueryBuilder::AddJoinItem PHP Method

AddJoinItem() public method

public AddJoinItem ( $strJoinTableName, $strJoinTableAlias, $strTableName, $strColumnName, $strLinkedColumnName, QQCondition $objJoinCondition = null )
$objJoinCondition QQCondition
    public function AddJoinItem($strJoinTableName, $strJoinTableAlias, $strTableName, $strColumnName, $strLinkedColumnName, QQCondition $objJoinCondition = null)
    {
        $strJoinItem = sprintf('LEFT JOIN %s%s%s AS %s%s%s ON %s%s%s.%s%s%s = %s%s%s.%s%s%s', $this->strEscapeIdentifierBegin, $strJoinTableName, $this->strEscapeIdentifierEnd, $this->strEscapeIdentifierBegin, $this->GetTableAlias($strJoinTableAlias), $this->strEscapeIdentifierEnd, $this->strEscapeIdentifierBegin, $this->GetTableAlias($strTableName), $this->strEscapeIdentifierEnd, $this->strEscapeIdentifierBegin, $strColumnName, $this->strEscapeIdentifierEnd, $this->strEscapeIdentifierBegin, $this->GetTableAlias($strJoinTableAlias), $this->strEscapeIdentifierEnd, $this->strEscapeIdentifierBegin, $strLinkedColumnName, $this->strEscapeIdentifierEnd);
        $strJoinIndex = $strJoinItem;
        try {
            $strConditionClause = null;
            if ($objJoinCondition && ($strConditionClause = $objJoinCondition->GetWhereClause($this, false))) {
                $strJoinItem .= ' AND ' . $strConditionClause;
            }
        } catch (QCallerException $objExc) {
            $objExc->IncrementOffset();
            throw $objExc;
        }
        /* If this table has already been joined, then we need to check for the following:
        				1. Condition wasn't specified before and we aren't specifying one now
        					Do Nothing --b/c nothing was changed or updated
        				2. Condition wasn't specified before but we ARE specifying one now
        					Update the indexed item in the joinArray with the new JoinItem WITH Condition
        				3. Condition WAS specified before but we aren't specifying one now
        					Do Nothing -- we need to keep the old condition intact
        				4. Condition WAS specified before and we are specifying the SAME one now
        					Do Nothing --b/c nothing was changed or updated
        				5. Condition WAS specified before and we are specifying a DIFFERENT one now
        					Do Nothing -- we need to keep the old condition intact
        					TODO: throw an excpetion of mismatched conditions -- but this could be too
        					intensive from a code processing standpoint
        			*/
        if (array_key_exists($strJoinIndex, $this->strJoinArray)) {
            // Case 1 and 2
            if (!array_key_exists($strJoinIndex, $this->strJoinConditionArray)) {
                // Case 1
                if (!$strConditionClause) {
                    return;
                    // Case 2
                } else {
                    $this->strJoinArray[$strJoinIndex] = $strJoinItem;
                    $this->strJoinConditionArray[$strJoinIndex] = $strConditionClause;
                    return;
                }
            }
            // Case 3
            if (!$strConditionClause) {
                return;
            }
            // Case 4
            if ($strConditionClause == $this->strJoinConditionArray[$strJoinIndex]) {
                return;
            }
            // Case 5
            throw new QCallerException('You have two different Join Conditions on the same Expanded Table: ' . $strJoinIndex . "\r\n[" . $this->strJoinConditionArray[$strJoinIndex] . ']   vs.   [' . $strConditionClause . ']');
        }
        // Create the new JoinItem in teh JoinArray
        $this->strJoinArray[$strJoinIndex] = $strJoinItem;
        // If there is a condition, record that condition against this JoinIndex
        if ($strConditionClause) {
            $this->strJoinConditionArray[$strJoinIndex] = $strConditionClause;
        }
    }

Usage Example

Example #1
0
 protected function addJoinTable(QQueryBuilder $objBuilder, $strJoinTableAlias, $strParentAlias, QQCondition $objJoinCondition = null)
 {
     $objBuilder->AddJoinItem($this->strTableName, $strJoinTableAlias, $strParentAlias, $this->objParentNode->_PrimaryKey, $this->strForeignKey, $objJoinCondition);
 }