Project

General

Profile

Feature #24043 » exec_SELECT_mmm_query.diff

Administrator Admin, 2010-11-14 14:50

View differences:

t3lib/class.t3lib_db.php (revision )
);
}
/**
* Creates and executes a SELECT query, selecting fields ($select) from four tables joined
* Use $mmmTable together with $firstTable, $secondTable or $thirdTable to select over two or three tables. Or use all four tables to select a full MMM-relation.
* The JOIN is done based on the MMM table, with MMM.first_uid <--> first_table.uid / MMM.second_uid <--> second_table.uid / MMM.third_uid <--> third_table.uid and the respective tablenames
* If you don't provide aliases, they will be automatically added as suffix "_mmm", "_first", "_second", "_third" as soon as one of the tablenames is used twice or more
* The function is very useful for selecting 3 way relations
*
* @param string Field list for SELECT
* @param string Tablename, MMM table
* @param string Optional Tablename, MMM table alias
* @param string Optional Tablename, first table
* @param string Optional Tablename, first table alias
* @param string Optional Tablename, second table
* @param string Optional Tablename, second table alias
* @param string Optional Tablename, third table
* @param string Optional Tablename, third table alias
* @param string Optional additional WHERE clauses put in the end of the query. NOTICE: You must escape values in this argument with $this->fullQuoteStr() yourself! DO NOT PUT IN GROUP BY, ORDER BY or LIMIT! You have to prepend 'AND ' to this parameter yourself!
* @param string Optional GROUP BY field(s), if none, supply blank string.
* @param string Optional ORDER BY field(s), if none, supply blank string.
* @param string Optional LIMIT value ([begin,]max), if none, supply blank string.
* @return pointer MySQL result pointer / DBAL object
* @see exec_SELECTquery()
*/
public function exec_SELECT_mmm_query($select = '*', $mmmTable, $mmmTableAlias = '', $firstTable = FALSE, $firstTableAlias = '', $secondTable = FALSE, $secondTableAlias = '', $thirdTable = FALSE, $thirdTableAlias = '', $whereClause = '', $groupBy = '', $orderBy = '', $limit = '') {
if(!$mmmTableAlias) {
if($mmmTable == $firstTable || $mmmTable == $secondTable || $mmmTable == $thirdTable) {
$mmmTableAlias = $mmmTable.'_mmm';
$tables = $mmmTable . ' AS ' . $mmmTableAlias;
} else {
$mmmTableAlias = $mmmTable;
$tables = $mmmTable;
}
}
if($firstTable) {
if(!$firstTableAlias) {
if($firstTable == $mmmTable || $firstTable == $secondTable || $firstTable == $thirdTable) {
$firstTableAlias = $firstTable.'_first';
$tables .= ' JOIN ' . $firstTable . ' AS ' . $firstTableAlias;
} else {
$firstTableAlias = $firstTable;
$tables .= ' JOIN ' . $firstTable;
}
}
$mmmWhere .= $mmmTableAlias . '.first_table=' . $this->fullQuoteStr($firstTable,$mmmTable) .
' AND ' . $firstTableAlias . '.uid=' . $mmmTableAlias . '.first_uid';
}
if($secondTable) {
if(!$secondTableAlias) {
if($secondTable == $mmmTable || $secondTable == $firstTable || $secondTable == $thirdTable) {
$secondTableAlias = $secondTable.'_second';
$tables .= ' JOIN ' . $secondTable . ' AS ' . $secondTableAlias;
} else {
$secondTableAlias = $secondTable;
$tables .= ' JOIN ' . $secondTable;
}
}
if($mmmWhere) {
$mmmWhere .= ' AND ';
}
$mmmWhere .= $mmmTableAlias . '.second_table=' . $this->fullQuoteStr($secondTable,$mmmTable) .
' AND ' . $secondTableAlias . '.uid=' . $mmmTableAlias . '.second_uid';
}
if($thirdTable) {
if($thirdTableAlias) {
if($thirdTable == $mmmTable || $thirdTable == $firstTable || $thirdTable == $secondTable) {
$thirdTableAlias = $thirdTable.'_third';
$tables .= ' JOIN ' . $thirdTable . ' AS ' . $thirdTableAlias;
} else {
$thirdTableAlias = $thirdTable;
$tables .= ' JOIN ' . $thirdTable;
}
}
if($mmmWhere) {
$mmmWhere .= ' AND ';
}
$mmmWhere .= $mmmTableAlias . '.third_table=' . $this->fullQuoteStr($thirdTable,$mmmTable) .
' AND ' . $thirdTableAlias . '.uid=' . $mmmTableAlias . '.third_uid';
}
if($mmmWhere && $whereClause) {
$mmmWhere = '(' . $mmmWhere . ') AND ' . $whereClause;
} else {
$mmmWhere = $whereClause;
}
return $this->exec_SELECTquery(
$select,
$tables,
$mmmWhere,
$groupBy,
$orderBy,
$limit
);
}
/**
* Executes a select based on input query parts array
*
* Usage: 9
......
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_db.php']);
}
?>
?>
(3-3/5)