本文整理汇总了PHP中Criteria::getLimit方法的典型用法代码示例。如果您正苦于以下问题:PHP Criteria::getLimit方法的具体用法?PHP Criteria::getLimit怎么用?PHP Criteria::getLimit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Criteria
的用法示例。
在下文中一共展示了Criteria::getLimit方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getMostCounted
/**
* returns the most counted object, sorted from the most counted to the less
* one. The possible options are :
* * limit : maximal number of counters to be returned
* * order : asc or desc, based on the counter field.
*
* @param Criteria $c
* @param array $options
*/
public static function getMostCounted(Criteria $c = null, $options = array())
{
if ($c == null) {
$c = new Criteria();
}
if (!$c->getLimit()) {
$c->setLimit(sfConfig::get('app_sfPropelActAsCountableBehaviorPlugin_limit', 10));
}
$c->addDescendingOrderByColumn(sfCounterPeer::COUNTER);
$counters = self::getCounters($c, $options);
$model_counters = array();
$model_counts = array();
$objects = array();
$result = array();
foreach ($counters as $counter) {
if (!isset($model_counters[$counter->getCountableModel()])) {
$model_counters[$counter->getCountableModel()] = array();
}
$model_counters[$counter->getCountableModel()][] = $counter->getCountableId();
$model_counts[$counter->getCountableModel()][$counter->getCountableId()] = $counter->getCounter();
}
foreach ($model_counters as $model => $countables) {
$peer = get_class(call_user_func(array(new $model(), 'getPeer')));
$countable_objects = call_user_func(array($peer, 'retrieveByPKs'), $countables);
foreach ($countable_objects as $object) {
$object->forceCounter($model_counts[$model][$object->getId()]);
$objects[$object->getCounter()][] = $object;
}
}
krsort($objects);
foreach ($objects as $count => $counted) {
foreach ($counted as $object) {
$result[] = $object;
}
}
return $result;
}
示例2: doCount
/**
* Executes a COUNT query using either a simple SQL rewrite or, for more complex queries, a
* sub-select of the SQL created by createSelectSql() and returns the statement.
*
* @param Criteria $criteria A Criteria.
* @param PropelPDO $con A PropelPDO connection to use.
* @return PDOStatement The resultset statement.
* @throws PropelException
* @see createSelectSql()
*/
public static function doCount(Criteria $criteria, PropelPDO $con = null)
{
$dbMap = Propel::getDatabaseMap($criteria->getDbName());
$db = Propel::getDB($criteria->getDbName());
if ($con === null) {
$con = Propel::getConnection($criteria->getDbName(), Propel::CONNECTION_READ);
}
$stmt = null;
if ($criteria->isUseTransaction()) {
$con->beginTransaction();
}
$needsComplexCount = $criteria->getGroupByColumns() || $criteria->getOffset() || $criteria->getLimit() || $criteria->getHaving() || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers());
try {
$params = array();
if ($needsComplexCount) {
if (self::needsSelectAliases($criteria)) {
if ($criteria->getHaving()) {
throw new PropelException('Propel cannot create a COUNT query when using HAVING and duplicate column names in the SELECT part');
}
self::turnSelectColumnsToAliases($criteria);
}
$selectSql = self::createSelectSql($criteria, $params);
$sql = 'SELECT COUNT(*) FROM (' . $selectSql . ') propelmatch4cnt';
} else {
// Replace SELECT columns with COUNT(*)
$criteria->clearSelectColumns()->addSelectColumn('COUNT(*)');
$sql = self::createSelectSql($criteria, $params);
}
$stmt = $con->prepare($sql);
self::populateStmtValues($stmt, $params, $dbMap, $db);
$stmt->execute();
if ($criteria->isUseTransaction()) {
$con->commit();
}
} catch (Exception $e) {
if ($stmt !== null) {
$stmt = null;
}
if ($criteria->isUseTransaction()) {
$con->rollBack();
}
Propel::log($e->getMessage(), Propel::LOG_ERR);
throw new PropelException(sprintf('Unable to execute COUNT statement [%s]', $sql), $e);
}
return $stmt;
}
示例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: testMergeWithFurtherModified
public function testMergeWithFurtherModified()
{
$c1 = new Criteria();
$c2 = new Criteria();
$c2->setLimit(123);
$c1->mergeWith($c2);
$this->assertEquals(123, $c1->getLimit(), 'mergeWith() makes the merge');
$c2->setLimit(456);
$this->assertEquals(123, $c1->getLimit(), 'further modifying a merged criteria does not affect the merger');
}
示例5: testLimit
public function testLimit()
{
$c = new Criteria();
$this->assertEquals(0, $c->getLimit(), 'Limit is 0 by default');
$c2 = $c->setLimit(1);
$this->assertEquals(1, $c->getLimit(), 'Limit is set by setLimit');
$this->assertSame($c, $c2, 'setLimit() returns the current Criteria');
}
示例6: count
/**
* Retorna a quantidade de registro existentes
*
* @param Criteria $criteria
* @return int $n Número de linhas
*/
public static function count(Criteria $criteria = NULL)
{
$db = new MysqlDB();
$class = get_called_class();
$table = $class::TABLE;
$q = "SELECT count(*) as count FROM {$table}";
$criteriaConfig = $class::configure();
if (empty($criteria) && empty($criteriaConfig)) {
$db->query($q);
return $db->getRow()->count;
}
if (!empty($criteriaConfig)) {
if (empty($criteria)) {
$criteria = new Criteria();
}
$criteria->merge($criteriaConfig);
}
if ($criteria->getConditions()) {
$conditions = array();
$used = array();
$i = 2;
$q .= ' WHERE (';
foreach ($criteria->getConditions() as $c) {
$label = $c[3];
while (array_search($label, $used)) {
$label .= $i++;
}
if (is_array($c)) {
$conditions[] = $c[0] . ' ' . $c[1] . ' :' . $label;
} else {
$conditions[] = $c;
}
$used[] = $label;
}
$q .= implode(' AND ', $conditions) . ')';
$q = str_replace('AND ) OR ( AND', ') OR (', $q);
if ($criteria->getSqlConditions()) {
$q .= ' AND ' . $criteria->getSqlConditions();
}
} elseif ($criteria->getSqlConditions()) {
$q .= ' WHERE ' . $criteria->getSqlConditions();
}
if ($criteria->getOrder()) {
$q .= ' ORDER BY ' . $criteria->getOrder();
}
if ($criteria->getLimit()) {
$q .= ' LIMIT ' . $criteria->getLimit();
}
$db->query($q);
foreach ($criteria->getConditions() as $c) {
if (!is_array($c)) {
continue;
}
$db->bind(':' . $c[3], $c[2]);
}
return $db->getRow()->count;
}
示例7: createSelectSql
//.........这里部分代码省略.........
if (!empty($joins)) {
for ($i=0, $joinSize=count($joins); $i < $joinSize; $i++) {
$join =& $joins[$i];
$join1 = $join->getLeftColumn();
$join2 = $join->getRightColumn();
$tableName = substr($join1, 0, strpos($join1, '.'));
$table = $criteria->getTableForAlias($tableName);
if ($table !== null) {
$fromClause[] = $table . ' ' . $tableName;
} else {
$fromClause[] = $tableName;
}
$dot = strpos($join2, '.');
$tableName = substr($join2, 0, $dot);
$table = $criteria->getTableForAlias($tableName);
if ($table !== null) {
$fromClause[] = $table . ' ' . $tableName;
} else {
$fromClause[] = $tableName;
$table = $tableName;
}
$ignoreCase = ($criteria->isIgnoreCase() && ($dbMap->getTable($table)->getColumn(substr($join2, $dot + 1))->getType() == "string"));
if ($ignoreCase) {
$whereClause[] = $db->ignoreCase($join1) . '=' . $db->ignoreCase($join2);
} else {
$whereClause[] = $join1 . '=' . $join2;
}
if ($join->getJoinType()) {
$leftTable = $fromClause[count($fromClause) - 2];
$rightTable = $fromClause[count($fromClause) - 1];
$onClause = $whereClause[count($whereClause) - 1];
unset($whereClause[count($whereClause) - 1]);
$fromClause [] = $leftTable . ' ' . $join->getJoinType() . ' ' . $rightTable . ' ON ' . $onClause;
// remove all references to joinTables made by selectColumns, criteriaColumns
for ($i = 0, $fromClauseSize=count($fromClause); $i < $fromClauseSize; $i++) {
if ($fromClause[$i] == $leftTable || $fromClause[$i] == $rightTable) {
unset($fromClause[$i]);
}
}
} // If join type
} // Join for loop
} // If Joins
*/
// Add the GROUP BY columns
$groupByClause = $groupBy;
$having = $criteria->getHaving();
$havingString = null;
if ($having !== null) {
$sb = "";
$having->appendPsTo($sb, $params);
$havingString = $sb;
}
if (!empty($orderBy)) {
foreach ($orderBy as $orderByColumn) {
// Add function expression as-is.
if (strpos($orderByColumn, '(') !== false) {
$orderByClause[] = $orderByColumn;
continue;
}
// Split orderByColumn (i.e. "table.column DESC")
$dotPos = strpos($orderByColumn, '.');
if ($dotPos !== false) {
$tableName = substr($orderByColumn, 0, $dotPos);
$columnName = substr($orderByColumn, $dotPos + 1);
} else {
$tableName = '';
$columnName = $orderByColumn;
}
$spacePos = strpos($columnName, ' ');
if ($spacePos !== false) {
$direction = substr($columnName, $spacePos);
$columnName = substr($columnName, 0, $spacePos);
} else {
$direction = '';
}
$tableAlias = $tableName;
if ($aliasTableName = $criteria->getTableForAlias($tableName)) {
$tableName = $aliasTableName;
}
$columnAlias = $columnName;
if ($asColumnName = $criteria->getColumnForAs($columnName)) {
$columnName = $asColumnName;
}
$column = $tableName ? $dbMap->getTable($tableName)->getColumn($columnName) : null;
if ($column && $column->getType() == 'string') {
$orderByClause[] = $db->ignoreCaseInOrderBy("{$tableAlias}.{$columnAlias}") . $direction;
$selectClause[] = $db->ignoreCaseInOrderBy("{$tableAlias}.{$columnAlias}");
} else {
$orderByClause[] = $orderByColumn;
}
}
}
// Build the SQL from the arrays we compiled
$sql = "SELECT " . ($selectModifiers ? implode(" ", $selectModifiers) . " " : "") . implode(", ", $selectClause) . " FROM " . (!empty($joinClause) && count($fromClause) > 1 && substr(get_class($db), 0, 7) == 'DBMySQL' ? "(" . implode(", ", $fromClause) . ")" : implode(", ", $fromClause)) . ($joinClause ? ' ' . implode(' ', $joinClause) : '') . ($whereClause ? " WHERE " . implode(" AND ", $whereClause) : "") . ($groupByClause ? " GROUP BY " . implode(",", $groupByClause) : "") . ($havingString ? " HAVING " . $havingString : "") . ($orderByClause ? " ORDER BY " . implode(",", $orderByClause) : "");
Propel::log($sql . ' [LIMIT: ' . $criteria->getLimit() . ', OFFSET: ' . $criteria->getOffset() . ']', Propel::LOG_DEBUG);
return $sql;
}
示例8: getLastModified
function getLastModified($criteria = null)
{
if (empty($criteria)) {
$criteria = new Criteria(1, intNBCriteriaVal(1));
}
$criteria->setSort('_NBsys_update_time');
$criteria->setOrder('DESC');
$_prevLimit = $criteria->getLimit();
$criteria->setLimit(1);
$objects =& $this->getObjects($criteria, false, '_NBsys_update_time');
if (count($objects) > 0) {
$lastModified = $objects[0]->getVar('_NBsys_update_time');
} else {
$lastModified = -1;
}
$criteria->setLimit($_prevLimit);
return $lastModified;
}
示例9: createSelectSql
//.........这里部分代码省略.........
}
// add 'em to the queues..
if ($joinType = $join->getJoinType()) {
// real join
if (!$fromClause) {
$fromClause[] = $leftTable . $leftTableAlias;
}
$joinTables[] = $rightTable . $rightTableAlias;
$joinClause[] = $join->getJoinType() . ' ' . $rightTable . $rightTableAlias . " ON ({$condition})";
} else {
// implicit join, translates to a where
$fromClause[] = $leftTable . $leftTableAlias;
$fromClause[] = $rightTable . $rightTableAlias;
$whereClause[] = $condition;
}
}
// Unique from clause elements
$fromClause = array_unique($fromClause);
$fromClause = array_diff($fromClause, array(''));
// tables should not exist in both the from and join clauses
if ($joinTables && $fromClause) {
foreach ($fromClause as $fi => $ftable) {
if (in_array($ftable, $joinTables)) {
unset($fromClause[$fi]);
}
}
}
// Add the GROUP BY columns
$groupByClause = $groupBy;
$having = $criteria->getHaving();
$havingString = null;
if ($having !== null) {
$sb = "";
$having->appendPsTo($sb, $params);
$havingString = $sb;
}
if (!empty($orderBy)) {
foreach ($orderBy as $orderByColumn) {
// Add function expression as-is.
if (strpos($orderByColumn, '(') !== false) {
$orderByClause[] = $orderByColumn;
continue;
}
// Split orderByColumn (i.e. "table.column DESC")
$dotPos = strrpos($orderByColumn, '.');
if ($dotPos !== false) {
$tableName = substr($orderByColumn, 0, $dotPos);
$columnName = substr($orderByColumn, $dotPos + 1);
} else {
$tableName = '';
$columnName = $orderByColumn;
}
$spacePos = strpos($columnName, ' ');
if ($spacePos !== false) {
$direction = substr($columnName, $spacePos);
$columnName = substr($columnName, 0, $spacePos);
} else {
$direction = '';
}
$tableAlias = $tableName;
if ($aliasTableName = $criteria->getTableForAlias($tableName)) {
$tableName = $aliasTableName;
}
$columnAlias = $columnName;
if ($asColumnName = $criteria->getColumnForAs($columnName)) {
$columnName = $asColumnName;
}
$column = $tableName ? $dbMap->getTable($tableName)->getColumn($columnName) : null;
if ($criteria->isIgnoreCase() && $column && $column->isText()) {
$orderByClause[] = $db->ignoreCaseInOrderBy("{$tableAlias}.{$columnAlias}") . $direction;
$selectClause[] = $db->ignoreCaseInOrderBy("{$tableAlias}.{$columnAlias}");
} else {
$orderByClause[] = $orderByColumn;
}
}
}
if (empty($fromClause) && $criteria->getPrimaryTableName()) {
$fromClause[] = $criteria->getPrimaryTableName();
}
// from / join tables quoten if it is necessary
if ($db->useQuoteIdentifier()) {
$fromClause = array_map(array($db, 'quoteIdentifierTable'), $fromClause);
$joinClause = $joinClause ? $joinClause : array_map(array($db, 'quoteIdentifierTable'), $joinClause);
}
// build from-clause
$from = '';
if (!empty($joinClause) && count($fromClause) > 1) {
$from .= implode(" CROSS JOIN ", $fromClause);
} else {
$from .= implode(", ", $fromClause);
}
$from .= $joinClause ? ' ' . implode(' ', $joinClause) : '';
// Build the SQL from the arrays we compiled
$sql = "SELECT " . ($selectModifiers ? implode(" ", $selectModifiers) . " " : "") . implode(", ", $selectClause) . " FROM " . $from . ($whereClause ? " WHERE " . implode(" AND ", $whereClause) : "") . ($groupByClause ? " GROUP BY " . implode(",", $groupByClause) : "") . ($havingString ? " HAVING " . $havingString : "") . ($orderByClause ? " ORDER BY " . implode(",", $orderByClause) : "");
// APPLY OFFSET & LIMIT to the query.
if ($criteria->getLimit() || $criteria->getOffset()) {
$db->applyLimit($sql, $criteria->getOffset(), $criteria->getLimit());
}
return $sql;
}
示例10: getPopulars
/**
* Returns the most popular tags with their associated weight. See
* sfPropelActAsTaggableToolkit::normalize for more details.
*
* The first optionnal parameter permits to add some restrictions on the
* objects the selected tags are related to.
* The second optionnal parameter permits to restrict the tag selection with
* different criterias
*
* @param Criteria $c
* @param array $options
* @return array
*/
public static function getPopulars($c = null, $options = array())
{
if (null === $c) {
$c = new Criteria();
}
if (!$c->getLimit()) {
$c->setLimit(sfConfig::get('app_sfPropelActAsTaggableBehaviorPlugin_limit', 100));
}
$all_tags = TagPeer::getAllWithCount($c, $options);
return sfPropelActAsTaggableToolkit::normalize($all_tags);
}
示例11: doCount
/**
* Executes a COUNT query using either a simple SQL rewrite or, for more complex queries, a
* sub-select of the SQL created by createSelectSql() and returns the statement.
*
* @param Criteria $criteria A Criteria.
* @param PropelPDO $con A PropelPDO connection to use.
* @return PDOStatement The resultset statement.
* @throws PropelException
* @see createSelectSql()
*/
public static function doCount(Criteria $criteria, PropelPDO $con = null)
{
$dbMap = Propel::getDatabaseMap($criteria->getDbName());
$db = Propel::getDB($criteria->getDbName());
if ($con === null) {
$con = Propel::getConnection($criteria->getDbName(), Propel::CONNECTION_READ);
}
$stmt = null;
if ($criteria->isUseTransaction()) {
$con->beginTransaction();
}
$needsComplexCount = $criteria->getGroupByColumns() || $criteria->getOffset() || $criteria->getLimit() || $criteria->getHaving() || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers());
try {
$params = array();
if ($needsComplexCount) {
$selectSql = self::createSelectSql($criteria, $params);
$sql = 'SELECT COUNT(*) FROM (' . $selectSql . ') AS propelmatch4cnt';
} else {
// Replace SELECT columns with COUNT(*)
$criteria->clearSelectColumns()->addSelectColumn('COUNT(*)');
$sql = self::createSelectSql($criteria, $params);
}
$stmt = $con->prepare($sql);
self::populateStmtValues($stmt, $params, $dbMap, $db);
$stmt->execute();
if ($criteria->isUseTransaction()) {
$con->commit();
}
} catch (Exception $e) {
if ($stmt) {
$stmt = null;
}
// close
if ($criteria->isUseTransaction()) {
$con->rollBack();
}
Propel::log($e->getMessage(), Propel::LOG_ERR);
throw new PropelException($e);
}
return $stmt;
}