本文整理汇总了PHP中Criteria::getAsColumns方法的典型用法代码示例。如果您正苦于以下问题:PHP Criteria::getAsColumns方法的具体用法?PHP Criteria::getAsColumns怎么用?PHP Criteria::getAsColumns使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Criteria
的用法示例。
在下文中一共展示了Criteria::getAsColumns方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prepareCriteriaForSelect
public static function prepareCriteriaForSelect(Criteria $criteria)
{
if ($criteria->hasSelectClause()) {
$asColumns = $criteria->getAsColumns();
if (count($asColumns) == 1 && isset($asColumns['_score'])) {
$criteria = clone $criteria;
MetadataProfilePeer::addSelectColumns($criteria);
}
} else {
$criteria = clone $criteria;
MetadataProfilePeer::addSelectColumns($criteria);
}
// Set the correct dbName
$criteria->setDbName(self::DATABASE_NAME);
// attach default criteria
MetadataProfilePeer::attachCriteriaFilter($criteria);
return $criteria;
}
示例2: doSelectStmt
/**
* Prepares the Criteria object and uses the parent doSelect() method to execute a PDOStatement.
*
* Use this method directly if you want to work with an executed statement durirectly (for example
* to perform your own object hydration).
*
* @param Criteria $criteria The Criteria object used to build the SELECT statement.
* @param PropelPDO $con The connection to use
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
* @return PDOStatement The executed PDOStatement object.
* @see BasePeer::doSelect()
*/
public static function doSelectStmt(Criteria $criteria, PropelPDO $con = null)
{
$con = PermissionPeer::alternativeCon($con);
if ($criteria->hasSelectClause()) {
$asColumns = $criteria->getAsColumns();
if (count($asColumns) == 1 && isset($asColumns['_score'])) {
$criteria = clone $criteria;
PermissionPeer::addSelectColumns($criteria);
}
} else {
$criteria = clone $criteria;
PermissionPeer::addSelectColumns($criteria);
}
// Set the correct dbName
$criteria->setDbName(self::DATABASE_NAME);
// attach default criteria
PermissionPeer::attachCriteriaFilter($criteria);
// BasePeer returns a PDOStatement
return BasePeer::doSelect($criteria, $con);
}
示例3: turnSelectColumnsToAliases
/**
* Ensures uniqueness of select column names by turning them all into aliases
* This is necessary for queries on more than one table when the tables share a column name
* Moved from BasePeer to DBAdapter and turned from static to non static
*
* @see http://propel.phpdb.org/trac/ticket/795
*
* @param Criteria $criteria
* @return Criteria The input, with Select columns replaced by aliases
*/
public function turnSelectColumnsToAliases(Criteria $criteria)
{
$selectColumns = $criteria->getSelectColumns();
// clearSelectColumns also clears the aliases, so get them too
$asColumns = $criteria->getAsColumns();
$criteria->clearSelectColumns();
$columnAliases = $asColumns;
// add the select columns back
foreach ($selectColumns as $clause) {
// Generate a unique alias
$baseAlias = preg_replace('/\\W/', '_', $clause);
$alias = $baseAlias;
// If it already exists, add a unique suffix
$i = 0;
while (isset($columnAliases[$alias])) {
$i++;
$alias = $baseAlias . '_' . $i;
}
// Add it as an alias
$criteria->addAsColumn($alias, $clause);
$columnAliases[$alias] = $clause;
}
// Add the aliases back, don't modify them
foreach ($asColumns as $name => $clause) {
$criteria->addAsColumn($name, $clause);
}
return $criteria;
}
示例4: testMergeWithAsColumns
public function testMergeWithAsColumns()
{
$c1 = new Criteria();
$c1->addAsColumn('foo', BookPeer::TITLE);
$c1->addAsColumn('bar', BookPeer::ID);
$c2 = new Criteria();
$c1->mergeWith($c2);
$this->assertEquals(array('foo' => BookPeer::TITLE, 'bar' => BookPeer::ID), $c1->getAsColumns(), 'mergeWith() does not remove an existing as columns');
$c1 = new Criteria();
$c2 = new Criteria();
$c2->addAsColumn('foo', BookPeer::TITLE);
$c2->addAsColumn('bar', BookPeer::ID);
$c1->mergeWith($c2);
$this->assertEquals(array('foo' => BookPeer::TITLE, 'bar' => BookPeer::ID), $c1->getAsColumns(), 'mergeWith() merges the select columns to an empty as');
$c1 = new Criteria();
$c1->addAsColumn('foo', BookPeer::TITLE);
$c2 = new Criteria();
$c2->addAsColumn('bar', BookPeer::ID);
$c1->mergeWith($c2);
$this->assertEquals(array('foo' => BookPeer::TITLE, 'bar' => BookPeer::ID), $c1->getAsColumns(), 'mergeWith() merges the select columns after the existing as columns');
}
示例5: 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;
}
示例6: createSelectSql
/**
* Method to create select SQL.
*
* @param Criteria $criteria object used to create the SELECT statement.
* @param String $tableName
* @param Array &$params
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
private function createSelectSql($criteria, $tableName, &$params)
{
$db = Propel::getDB($criteria->getDbName());
// redundant definition $selectModifiers = array();
$selectClause = array();
$fromClause = array();
$joinClause = array();
$joinTables = array();
$whereClause = array();
$orderByClause = array();
$groupByClause = array();
$orderBy = $criteria->getOrderByColumns();
$groupBy = $criteria->getGroupByColumns();
$ignoreCase = $criteria->isIgnoreCase();
$select = $criteria->getSelectColumns();
$aliases = $criteria->getAsColumns();
$fromClause[] = $criteria->getDBArrayTable();
// simple copy
$selectModifiers = $criteria->getSelectModifiers();
// get selected columns
foreach ($select as $columnName) {
$tableName = null;
$selectClause[] = $columnName;
// the full column name: e.g. MAX(books.price)
$parenPos = strpos($columnName, '(');
$dotPos = strpos($columnName, '.');
// [HL] I think we really only want to worry about adding stuff to
// the fromClause if this function has a TABLE.COLUMN in it at all.
// e.g. COUNT(*) should not need this treatment -- or there needs to
// be special treatment for '*'
if ($dotPos !== false) {
if ($parenPos === false) {
// table.column
$tableName = substr($columnName, 0, $dotPos);
} else {
// FUNC(table.column)
$tableName = substr($columnName, $parenPos + 1, $dotPos - ($parenPos + 1));
// functions may contain qualifiers so only take the last
// word as the table name.
// COUNT(DISTINCT books.price)
$lastSpace = strpos($tableName, ' ');
if ($lastSpace !== false) {
// COUNT(DISTINCT books.price)
$tableName = substr($tableName, $lastSpace + 1);
}
}
$tableName2 = $criteria->getTableForAlias($tableName);
if ($tableName2 !== null) {
$fromClause[] = $tableName2 . ' ' . $tableName;
} else {
$fromClause[] = $tableName;
}
}
// if $dotPost !== null
}
// set the aliases
foreach ($aliases as $alias => $col) {
$selectClause[] = $col . " AS " . $alias;
}
// add the criteria to WHERE clause
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);
$cri['table'] = $criterion->table;
$cri['field'] = $criterion->column;
$cri['comparison'] = $criterion->comparison == '=' ? '==' : $criterion->comparison;
$cri['value'] = $criterion->getValue();
$sb = "";
$sb .= "\$row['" . $cri['field'] . "'] " . $cri['comparison'] . "'" . $cri['value'] . "'";
$params[] = $cri;
//$criterion->appendPsTo($sb, $params);
$whereClause[] = $sb;
}
// Unique from clause elements
$fromClause = array_unique($fromClause);
if (!empty($orderBy)) {
//.........这里部分代码省略.........
示例7: createSelectSql
/**
* Method to create an SQL query based on values in a Criteria.
*
* This method creates only prepared statement SQL (using ? where values
* will go). The second parameter ($params) stores the values that need
* to be set before the statement is executed. The reason we do it this way
* is to let the Creole layer handle all escaping & value formatting.
*
* @param Criteria $criteria Criteria for the SELECT query.
* @param array &$params Parameters that are to be replaced in prepared statement.
* @return string
* @throws PropelException Trouble creating the query string.
*/
public static function createSelectSql(Criteria $criteria, &$params)
{
$db = Propel::getDB($criteria->getDbName());
$dbMap = Propel::getDatabaseMap($criteria->getDbName());
// redundant definition $selectModifiers = array();
$selectClause = array();
$fromClause = array();
$joinClause = array();
$joinTables = array();
$whereClause = array();
$orderByClause = array();
// redundant definition $groupByClause = array();
$orderBy = $criteria->getOrderByColumns();
$groupBy = $criteria->getGroupByColumns();
$ignoreCase = $criteria->isIgnoreCase();
$select = $criteria->getSelectColumns();
$aliases = $criteria->getAsColumns();
// simple copy
$selectModifiers = $criteria->getSelectModifiers();
// get selected columns
foreach ($select as $columnName) {
// expect every column to be of "table.column" formation
// it could be a function: e.g. MAX(books.price)
$tableName = null;
$selectClause[] = $columnName;
// the full column name: e.g. MAX(books.price)
$parenPos = strpos($columnName, '(');
$dotPos = strpos($columnName, '.');
// [HL] I think we really only want to worry about adding stuff to
// the fromClause if this function has a TABLE.COLUMN in it at all.
// e.g. COUNT(*) should not need this treatment -- or there needs to
// be special treatment for '*'
if ($dotPos !== false) {
if ($parenPos === false) {
// table.column
$tableName = substr($columnName, 0, $dotPos);
} else {
// FUNC(table.column)
$tableName = substr($columnName, $parenPos + 1, $dotPos - ($parenPos + 1));
// functions may contain qualifiers so only take the last
// word as the table name.
// COUNT(DISTINCT books.price)
$lastSpace = strpos($tableName, ' ');
if ($lastSpace !== false) {
// COUNT(DISTINCT books.price)
$tableName = substr($tableName, $lastSpace + 1);
}
}
$tableName2 = $criteria->getTableForAlias($tableName);
if ($tableName2 !== null) {
$fromClause[] = $tableName2 . ' ' . $tableName;
} else {
$fromClause[] = $tableName;
}
}
// if $dotPost !== null
}
// 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()) && $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
//.........这里部分代码省略.........
示例8: createSelectSql
/**
* Method to create an SQL query based on values in a Criteria.
*
* This method creates only prepared statement SQL (using ? where values
* will go). The second parameter ($params) stores the values that need
* to be set before the statement is executed. The reason we do it this way
* is to let the PDO layer handle all escaping & value formatting.
*
* @param Criteria $criteria Criteria for the SELECT query.
* @param array &$params Parameters that are to be replaced in prepared statement.
* @return string
* @throws PropelException Trouble creating the query string.
*/
public static function createSelectSql(Criteria $criteria, &$params)
{
$db = Propel::getDB($criteria->getDbName());
$dbMap = Propel::getDatabaseMap($criteria->getDbName());
// redundant definition $selectModifiers = array();
$selectClause = array();
$fromClause = array();
$joinClause = array();
$joinTables = array();
$whereClause = array();
$orderByClause = array();
// redundant definition $groupByClause = array();
$orderBy = $criteria->getOrderByColumns();
$groupBy = $criteria->getGroupByColumns();
$ignoreCase = $criteria->isIgnoreCase();
$select = $criteria->getSelectColumns();
$aliases = $criteria->getAsColumns();
// simple copy
$selectModifiers = $criteria->getSelectModifiers();
// get selected columns
foreach ($select as $columnName) {
// expect every column to be of "table.column" formation
// it could be a function: e.g. MAX(books.price)
$tableName = null;
$selectClause[] = $columnName;
// the full column name: e.g. MAX(books.price)
$parenPos = strrpos($columnName, '(');
$dotPos = strrpos($columnName, '.', $parenPos !== false ? $parenPos : 0);
// [HL] I think we really only want to worry about adding stuff to
// the fromClause if this function has a TABLE.COLUMN in it at all.
// e.g. COUNT(*) should not need this treatment -- or there needs to
// be special treatment for '*'
if ($dotPos !== false) {
if ($parenPos === false) {
// table.column
$tableName = substr($columnName, 0, $dotPos);
} else {
// FUNC(table.column)
$tableName = substr($columnName, $parenPos + 1, $dotPos - ($parenPos + 1));
// functions may contain qualifiers so only take the last
// word as the table name.
// COUNT(DISTINCT books.price)
$lastSpace = strpos($tableName, ' ');
if ($lastSpace !== false) {
// COUNT(DISTINCT books.price)
$tableName = substr($tableName, $lastSpace + 1);
}
}
$tableName2 = $criteria->getTableForAlias($tableName);
if ($tableName2 !== null) {
$fromClause[] = $tableName2 . ' ' . $tableName;
} else {
$fromClause[] = $tableName;
}
}
// if $dotPost !== null
}
// 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
//.........这里部分代码省略.........