本文整理汇总了PHP中Criteria::getJoins方法的典型用法代码示例。如果您正苦于以下问题:PHP Criteria::getJoins方法的具体用法?PHP Criteria::getJoins怎么用?PHP Criteria::getJoins使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Criteria
的用法示例。
在下文中一共展示了Criteria::getJoins方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testMergeWithJoins
public function testMergeWithJoins()
{
$c1 = new Criteria();
$c1->addJoin(BookPeer::AUTHOR_ID, AuthorPeer::ID, Criteria::LEFT_JOIN);
$c2 = new Criteria();
$c1->mergeWith($c2);
$joins = $c1->getJoins();
$this->assertEquals(1, count($joins), 'mergeWith() does not remove an existing join');
$this->assertEquals('LEFT JOIN author ON (book.AUTHOR_ID=author.ID)', $joins[0]->toString(), 'mergeWith() does not remove an existing join');
$c1 = new Criteria();
$c2 = new Criteria();
$c2->addJoin(BookPeer::AUTHOR_ID, AuthorPeer::ID, Criteria::LEFT_JOIN);
$c1->mergeWith($c2);
$joins = $c1->getJoins();
$this->assertEquals(1, count($joins), 'mergeWith() merge joins to an empty join');
$this->assertEquals('LEFT JOIN author ON (book.AUTHOR_ID=author.ID)', $joins[0]->toString(), 'mergeWith() merge joins to an empty join');
$c1 = new Criteria();
$c1->addJoin(BookPeer::AUTHOR_ID, AuthorPeer::ID, Criteria::LEFT_JOIN);
$c2 = new Criteria();
$c2->addJoin(BookPeer::PUBLISHER_ID, PublisherPeer::ID, Criteria::INNER_JOIN);
$c1->mergeWith($c2);
$joins = $c1->getJoins();
$this->assertEquals(2, count($joins), 'mergeWith() merge joins to an existing join');
$this->assertEquals('LEFT JOIN author ON (book.AUTHOR_ID=author.ID)', $joins[0]->toString(), 'mergeWith() merge joins to an empty join');
$this->assertEquals('INNER JOIN publisher ON (book.PUBLISHER_ID=publisher.ID)', $joins[1]->toString(), 'mergeWith() merge joins to an empty join');
}
示例2: testAddJoin_Duplicate
/**
* Tests adding duplicate joins.
* @link http://propel.phpdb.org/trac/ticket/613
*/
public function testAddJoin_Duplicate()
{
$c = new Criteria();
$c->addJoin("tbl.COL1", "tbl.COL2", Criteria::LEFT_JOIN);
$c->addJoin("tbl.COL1", "tbl.COL2", Criteria::LEFT_JOIN);
$this->assertEquals(1, count($c->getJoins()), "Expected not to have duplciate LJOIN added.");
$c->addJoin("tbl.COL1", "tbl.COL2", Criteria::RIGHT_JOIN);
$c->addJoin("tbl.COL1", "tbl.COL2", Criteria::RIGHT_JOIN);
$this->assertEquals(2, count($c->getJoins()), "Expected 1 new right join to be added.");
$c->addJoin("tbl.COL1", "tbl.COL2");
$c->addJoin("tbl.COL1", "tbl.COL2");
$this->assertEquals(3, count($c->getJoins()), "Expected 1 new implicit join to be added.");
$c->addJoin("tbl.COL3", "tbl.COL4");
$this->assertEquals(4, count($c->getJoins()), "Expected new col join to be added.");
}
示例3: mergeWith
/**
* Add the content of a Criteria to the current Criteria
* In case of conflict, the current Criteria keeps its properties
*
* @param Criteria $criteria The criteria to read properties from
* @param string $operator The logical operator used to combine conditions
* Defaults to Criteria::LOGICAL_AND, also accapts Criteria::LOGICAL_OR
* This parameter is deprecated, use _or() instead
*
* @return Criteria The current criteria object
*/
public function mergeWith(Criteria $criteria, $operator = null)
{
// merge limit
$limit = $criteria->getLimit();
if ($limit != 0 && $this->getLimit() == 0) {
$this->limit = $limit;
}
// merge offset
$offset = $criteria->getOffset();
if ($offset != 0 && $this->getOffset() == 0) {
$this->offset = $offset;
}
// merge select modifiers
$selectModifiers = $criteria->getSelectModifiers();
if ($selectModifiers && !$this->selectModifiers) {
$this->selectModifiers = $selectModifiers;
}
// merge select columns
$this->selectColumns = array_merge($this->getSelectColumns(), $criteria->getSelectColumns());
// merge as columns
$commonAsColumns = array_intersect_key($this->getAsColumns(), $criteria->getAsColumns());
if (!empty($commonAsColumns)) {
throw new PropelException('The given criteria contains an AsColumn with an alias already existing in the current object');
}
$this->asColumns = array_merge($this->getAsColumns(), $criteria->getAsColumns());
// merge orderByColumns
$orderByColumns = array_merge($this->getOrderByColumns(), $criteria->getOrderByColumns());
$this->orderByColumns = array_unique($orderByColumns);
// merge groupByColumns
$groupByColumns = array_merge($this->getGroupByColumns(), $criteria->getGroupByColumns());
$this->groupByColumns = array_unique($groupByColumns);
// merge where conditions
if ($operator == Criteria::LOGICAL_OR) {
$this->_or();
}
$isFirstCondition = true;
foreach ($criteria->getMap() as $key => $criterion) {
if ($isFirstCondition && $this->defaultCombineOperator == Criteria::LOGICAL_OR) {
$this->addOr($criterion, null, null, false);
$this->defaultCombineOperator == Criteria::LOGICAL_AND;
} elseif ($this->containsKey($key)) {
$this->addAnd($criterion);
} else {
$this->add($criterion);
}
$isFirstCondition = false;
}
// merge having
if ($having = $criteria->getHaving()) {
if ($this->getHaving()) {
$this->addHaving($this->getHaving()->addAnd($having));
} else {
$this->addHaving($having);
}
}
// merge alias
$commonAliases = array_intersect_key($this->getAliases(), $criteria->getAliases());
if (!empty($commonAliases)) {
throw new PropelException('The given criteria contains an alias already existing in the current object');
}
$this->aliases = array_merge($this->getAliases(), $criteria->getAliases());
// merge join
$this->joins = array_merge($this->getJoins(), $criteria->getJoins());
return $this;
}
示例4: createSelectSql
//.........这里部分代码省略.........
foreach ($aliases as $alias => $col) {
$selectClause[] = $col . " AS " . $alias;
}
// add the criteria to WHERE clause
// this will also add the table names to the FROM clause if they are not already
// invluded via a LEFT JOIN
foreach ($criteria->keys() as $key) {
$criterion = $criteria->getCriterion($key);
$someCriteria = $criterion->getAttachedCriterion();
$someCriteriaLength = count($someCriteria);
$table = null;
for ($i = 0; $i < $someCriteriaLength; $i++) {
$tableName = $someCriteria[$i]->getTable();
$table = $criteria->getTableForAlias($tableName);
if ($table !== null) {
$fromClause[] = $table . ' ' . $tableName;
} else {
$fromClause[] = $tableName;
$table = $tableName;
}
$ignoreCase = ($criteria->isIgnoreCase() || $someCriteria[$i]->isIgnoreCase()) && $dbMap->getTable($table)->getColumn($someCriteria[$i]->getColumn())->getType() == "string";
$someCriteria[$i]->setIgnoreCase($ignoreCase);
}
$criterion->setDB($db);
$sb = "";
$criterion->appendPsTo($sb, $params);
$whereClause[] = $sb;
}
// handle RIGHT (straight) joins
// Loop through the joins,
// joins with a null join type will be added to the FROM clause and the condition added to the WHERE clause.
// joins of a specified type: the LEFT side will be added to the fromClause and the RIGHT to the joinClause
// New Code.
foreach ((array) $criteria->getJoins() as $join) {
// we'll only loop if there's actually something here
// The join might have been established using an alias name
$leftTable = $join->getLeftTableName();
$leftTableAlias = '';
if ($realTable = $criteria->getTableForAlias($leftTable)) {
$leftTableAlias = " {$leftTable}";
$leftTable = $realTable;
}
$rightTable = $join->getRightTableName();
$rightTableAlias = '';
if ($realTable = $criteria->getTableForAlias($rightTable)) {
$rightTableAlias = " {$rightTable}";
$rightTable = $realTable;
}
// determine if casing is relevant.
if ($ignoreCase = $criteria->isIgnoreCase()) {
$leftColType = $dbMap->getTable($leftTable)->getColumn($join->getLeftColumnName())->getType();
$rightColType = $dbMap->getTable($rightTable)->getColumn($join->getRightColumnName())->getType();
$ignoreCase = $leftColType == 'string' || $rightColType == 'string';
}
// build the condition
if ($ignoreCase) {
$condition = $db->ignoreCase($join->getLeftColumn()) . '=' . $db->ignoreCase($join->getRightColumn());
} else {
$condition = $join->getLeftColumn() . '=' . $join->getRightColumn();
}
// add 'em to the queues..
if ($joinType = $join->getJoinType()) {
if (!$fromClause) {
$fromClause[] = $leftTable . $leftTableAlias;
}
$joinTables[] = $rightTable . $rightTableAlias;
示例5: doDelete
/**
* Method to perform deletes based on values and keys in a
* Criteria.
*
* @param Criteria $criteria The criteria to use.
* @param PropelPDO $con A PropelPDO connection object.
* @return int The number of rows affected by last statement execution. For most
* uses there is only one delete statement executed, so this number
* will correspond to the number of rows affected by the call to this
* method. Note that the return value does require that this information
* is returned (supported) by the PDO driver.
* @throws PropelException
*/
public static function doDelete(Criteria $criteria, PropelPDO $con)
{
$db = Propel::getDB($criteria->getDbName());
$dbMap = Propel::getDatabaseMap($criteria->getDbName());
//join are not supported with DELETE statement
if (count($criteria->getJoins())) {
throw new PropelException('Delete does not support join');
}
// Set up a list of required tables (one DELETE statement will
// be executed per table)
$tables = $criteria->getTablesColumns();
if (empty($tables)) {
throw new PropelException("Cannot delete from an empty Criteria");
}
$affectedRows = 0;
// initialize this in case the next loop has no iterations.
foreach ($tables as $tableName => $columns) {
$whereClause = array();
$params = array();
$stmt = null;
try {
$sql = $db->getDeleteFromClause($criteria, $tableName);
foreach ($columns as $colName) {
$sb = "";
$criteria->getCriterion($colName)->appendPsTo($sb, $params);
$whereClause[] = $sb;
}
$sql .= " WHERE " . implode(" AND ", $whereClause);
$stmt = $con->prepare($sql);
self::populateStmtValues($stmt, $params, $dbMap, $db);
$stmt->execute();
$affectedRows = $stmt->rowCount();
} catch (Exception $e) {
Propel::log($e->getMessage(), Propel::LOG_ERR);
throw new PropelException(sprintf('Unable to execute DELETE statement [%s]', $sql), $e);
}
}
// for each table
return $affectedRows;
}
示例6: createSelectSql
//.........这里部分代码省略.........
}
// set the aliases
foreach ($aliases as $alias => $col) {
$selectClause[] = $col . " AS " . $alias;
}
// add the criteria to WHERE clause
// this will also add the table names to the FROM clause if they are not already
// invluded via a LEFT JOIN
foreach ($criteria->keys() as $key) {
$criterion = $criteria->getCriterion($key);
$someCriteria = $criterion->getAttachedCriterion();
$someCriteriaLength = count($someCriteria);
$table = null;
for ($i = 0; $i < $someCriteriaLength; $i++) {
$tableName = $someCriteria[$i]->getTable();
$table = $criteria->getTableForAlias($tableName);
if ($table !== null) {
$fromClause[] = $table . ' ' . $tableName;
} else {
$fromClause[] = $tableName;
$table = $tableName;
}
$ignoreCase = ($criteria->isIgnoreCase() || $someCriteria[$i]->isIgnoreCase()) && strpos($dbMap->getTable($table)->getColumn($someCriteria[$i]->getColumn())->getType(), "VARCHAR") !== false;
$someCriteria[$i]->setIgnoreCase($ignoreCase);
}
$criterion->setDB($db);
$sb = "";
$criterion->appendPsTo($sb, $params);
$whereClause[] = $sb;
}
// Handle joins
// joins with a null join type will be added to the FROM clause and the condition added to the WHERE clause.
// joins of a specified type: the LEFT side will be added to the fromClause and the RIGHT to the joinClause
foreach ((array) $criteria->getJoins() as $join) {
// The join might have been established using an alias name
$leftTable = $join->getLeftTableName();
$leftTableAlias = '';
if ($realTable = $criteria->getTableForAlias($leftTable)) {
$leftTableAlias = " {$leftTable}";
$leftTable = $realTable;
}
$rightTable = $join->getRightTableName();
$rightTableAlias = '';
if ($realTable = $criteria->getTableForAlias($rightTable)) {
$rightTableAlias = " {$rightTable}";
$rightTable = $realTable;
}
// determine if casing is relevant.
if ($ignoreCase = $criteria->isIgnoreCase()) {
$leftColType = $dbMap->getTable($leftTable)->getColumn($join->getLeftColumnName())->getType();
$rightColType = $dbMap->getTable($rightTable)->getColumn($join->getRightColumnName())->getType();
$ignoreCase = $leftColType == 'string' || $rightColType == 'string';
}
// build the condition
$condition = '';
foreach ($join->getConditions() as $index => $conditionDesc) {
if ($ignoreCase) {
$condition .= $db->ignoreCase($conditionDesc['left']) . $conditionDesc['operator'] . $db->ignoreCase($conditionDesc['right']);
} else {
$condition .= implode($conditionDesc);
}
if ($index + 1 < $join->countConditions()) {
$condition .= ' AND ';
}
}
// add 'em to the queues..
示例7: testAddJoin_Duplicate
/**
* Tests adding duplicate joins.
* @link http://trac.propelorm.org/ticket/613
*/
public function testAddJoin_Duplicate()
{
$c = new Criteria();
$c->addJoin("tbl.COL1", "tbl.COL2", Criteria::LEFT_JOIN);
$c->addJoin("tbl.COL1", "tbl.COL2", Criteria::LEFT_JOIN);
$this->assertEquals(1, count($c->getJoins()), "Expected not to have duplicate LEFT JOIN added.");
$c->addJoin("tbl.COL1", "tbl.COL2", Criteria::RIGHT_JOIN);
$c->addJoin("tbl.COL1", "tbl.COL2", Criteria::RIGHT_JOIN);
$this->assertEquals(2, count($c->getJoins()), "Expected 1 new right join to be added.");
$c->addJoin("tbl.COL1", "tbl.COL2");
$c->addJoin("tbl.COL1", "tbl.COL2");
$this->assertEquals(3, count($c->getJoins()), "Expected 1 new implicit join to be added.");
$c->addJoin("tbl.COL1", "tbl.COL2", Criteria::INNER_JOIN);
$this->assertEquals(3, count($c->getJoins()), "Expected to not add any new join\n as INNER JOIN is default joinType and it is already added");
$c->addJoin("tbl.COL3", "tbl.COL4");
$this->assertEquals(4, count($c->getJoins()), "Expected new col join to be added.");
}
示例8: criteriaToQuery
public function criteriaToQuery($criteria)
{
if ($criteria == null) {
$criteria = new Criteria();
}
$db = Database::connection();
// assemble a query string.
// if exactQuery is specified - no problem. just run it. responsibility is on
// the user ;-)
if ($criteria->getExplicitQuery() != null) {
return $criteria->getExplicitQuery();
}
// ok - otherwise now we should counstruct the query
$joins = $criteria->getJoins();
$q = "SELECT ";
if ($criteria->isDistinct()) {
$q .= " DISTINCT ";
if ($criteria->isDistinct() !== true) {
$q .= " ON (" . $criteria->isDistinct() . ") ";
}
}
// check if the query has an explicit list of fields to selec
if ($criteria->getExplicitFields() != null) {
$q .= $criteria->getExplicitFields();
} else {
if ($joins == null) {
$q .= ' ' . $this->tableName . '.* ';
//$this->fieldListString();
} else {
$q .= ' ' . $this->fieldListStringSpecialJoin();
foreach ($joins as $join) {
// get aliased field list
$peer = self::peerForTable($join['foreignTable']);
$q .= ', ' . $peer->fieldListStringSpecialJoin();
}
}
}
if ($criteria->getExplicitFrom() != null) {
$q .= " FROM " . $criteria->getExplicitFrom();
} else {
$q .= " FROM " . $this->tableName;
if ($joins != null) {
foreach ($joins as $join) {
$q .= ', ' . $join['foreignTable'];
}
}
}
$whereString = $criteria->whereString();
if ($joins != null) {
if ($whereString != null) {
$q .= " WHERE (" . $whereString . ') AND';
} else {
$q .= ' WHERE ';
}
$first = true;
foreach ($joins as $join) {
if ($first) {
$first = false;
} else {
$q .= " AND ";
}
$q .= ' ';
if (strpos($join['localKey'], '.') === false) {
$q .= $this->tableName . '.';
}
$q .= $join['localKey'] . ' = ' . $join['foreignTable'] . '.' . $join['foreignKey'] . ' ';
}
} elseif ($whereString != null) {
$q .= " WHERE " . $whereString;
}
$q .= " " . $criteria->groupByString();
$q .= " " . $criteria->orderString();
$q .= " " . $criteria->limitString();
if ($criteria->isForUpdate()) {
$q .= " FOR UPDATE";
}
return $q;
}