本文整理汇总了PHP中Propel\Runtime\ActiveQuery\Criteria类的典型用法代码示例。如果您正苦于以下问题:PHP Criteria类的具体用法?PHP Criteria怎么用?PHP Criteria使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Criteria类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addJoinProduct
/**
* Join products and their URLs
*
* @param Criteria $query
*/
protected function addJoinProduct(Criteria &$query)
{
// Join RewritingURL with Product to have only visible products
$join = new Join();
$join->addExplicitCondition(RewritingUrlTableMap::TABLE_NAME, 'VIEW_ID', null, ProductTableMap::TABLE_NAME, 'ID', null);
$join->setJoinType(Criteria::INNER_JOIN);
$query->addJoinObject($join, 'productJoin');
// Get only visible products
$query->addJoinCondition('productJoin', ProductTableMap::VISIBLE, 1, Criteria::EQUAL, \PDO::PARAM_INT);
}
示例2: testCreateSelectSqlPart
public function testCreateSelectSqlPart()
{
Propel::getServiceContainer()->setAdapter('oracle', new OracleAdapter());
$db = Propel::getServiceContainer()->getAdapter();
$c = new Criteria();
$c->addSelectColumn(BookTableMap::COL_ID);
$c->addAsColumn('book_ID', BookTableMap::COL_ID);
$fromClause = [];
$selectSql = $db->createSelectSqlPart($c, $fromClause);
$this->assertEquals('SELECT book.id, book.id AS book_ID', $selectSql, 'createSelectSqlPart() returns a SQL SELECT clause with both select and as columns');
$this->assertEquals(['book'], $fromClause, 'createSelectSqlPart() adds the tables from the select columns to the from clause');
}
示例3: testDoInsert
public function testDoInsert()
{
try {
$c = new Criteria();
$c->setPrimaryTableName(BookTableMap::TABLE_NAME);
$c->add(BookTableMap::AUTHOR_ID, 'lkhlkhj');
$c->doInsert(Propel::getServiceContainer()->getWriteConnection(BookTableMap::DATABASE_NAME));
$this->fail('Missing expected exception on BAD SQL');
} catch (PropelException $e) {
$this->assertContains('[INSERT INTO `book` (`AUTHOR_ID`) VALUES (:p1)]', $e->getMessage(), 'SQL query is written in the exception message');
}
}
示例4: testAppendPsToCreatesAnInConditionUsingATableAlias
public function testAppendPsToCreatesAnInConditionUsingATableAlias()
{
$c = new Criteria();
$c->addAlias('bar_alias', 'bar');
$cton = new InCriterion($c, 'bar_alias.COL', array('foo'));
$params = array();
$ps = '';
$cton->appendPsTo($ps, $params);
$this->assertEquals('bar_alias.COL IN (:p1)', $ps);
$expected = array(array('table' => 'bar', 'column' => 'COL', 'value' => 'foo'));
$this->assertEquals($expected, $params);
}
示例5: testClonedCriteriaNotAffected2
public function testClonedCriteriaNotAffected2()
{
$this->c->addCond('cond1', "INVOICE.COST1", "1000", Criteria::GREATER_EQUAL);
$this->c->addCond('cond2', "INVOICE.COST2", "2000", Criteria::LESS_EQUAL);
$this->c->combine(['cond1', 'cond2'], Criteria::LOGICAL_AND, 'cond12');
$this->c->addCond('cond3', "INVOICE.COST3", "8000", Criteria::GREATER_EQUAL);
$this->c->addCond('cond4', "INVOICE.COST4", "9000", Criteria::LESS_EQUAL);
$this->c->combine(['cond3', 'cond4'], Criteria::LOGICAL_AND, 'cond34');
$clonedCriteria = clone $this->c;
$expect1 = $this->getSql("SELECT FROM ");
$params1 = [];
$result1 = $this->c->createSelectSql($params1);
$this->assertEquals($expect1, $result1);
$this->c->addCond('cond5', "INVOICE.COST5", "5000", Criteria::GREATER_EQUAL);
$this->c->combine(['cond34', 'cond5'], Criteria::LOGICAL_AND);
$expect2 = $this->getSql("SELECT FROM INVOICE WHERE ((INVOICE.COST3>=:p1 AND INVOICE.COST4<=:p2) AND INVOICE.COST5>=:p3)");
$expect_params2 = [['table' => 'INVOICE', 'column' => 'COST3', 'value' => '8000'], ['table' => 'INVOICE', 'column' => 'COST4', 'value' => '9000'], ['table' => 'INVOICE', 'column' => 'COST5', 'value' => '5000']];
$params2 = [];
$result2 = $this->c->createSelectSql($params2);
$this->assertEquals($expect2, $result2);
$this->assertEquals($expect_params2, $params2);
// Cloned criteria should not be affected by the combine of cond34 above
// we should still be able to use it in the clone for another combine
$clonedCriteria->combine(['cond12', 'cond34'], Criteria::LOGICAL_OR);
$expect3 = $this->getSql("SELECT FROM INVOICE WHERE ((INVOICE.COST1>=:p1 AND INVOICE.COST2<=:p2) OR (INVOICE.COST3>=:p3 AND INVOICE.COST4<=:p4))");
$expect_params3 = [['table' => 'INVOICE', 'column' => 'COST1', 'value' => '1000'], ['table' => 'INVOICE', 'column' => 'COST2', 'value' => '2000'], ['table' => 'INVOICE', 'column' => 'COST3', 'value' => '8000'], ['table' => 'INVOICE', 'column' => 'COST4', 'value' => '9000']];
$params3 = [];
$result3 = $clonedCriteria->createSelectSql($params3);
$this->assertEquals($expect3, $result3);
$this->assertEquals($expect_params3, $params3);
}
示例6: addSelectFields
/**
* @param Criteria $criteria
* @param string $alias
*/
public function addSelectFields(Criteria $criteria, $alias = null)
{
if (null === $alias) {
$criteria->addSelectField(AuthorEntityMap::COL_ID);
$criteria->addSelectField(AuthorEntityMap::COL_FIRSTNAME);
$criteria->addSelectField(AuthorEntityMap::COL_LASTNAME);
$criteria->addSelectField(AuthorEntityMap::COL_EMAIL);
} else {
$criteria->addSelectField($alias . '.id');
$criteria->addSelectField($alias . '.firstName');
$criteria->addSelectField($alias . '.lastName');
$criteria->addSelectField($alias . '.email');
}
}
示例7: testDoInsert
public function testDoInsert()
{
$con = Propel::getServiceContainer()->getWriteConnection(BookTableMap::DATABASE_NAME);
try {
$c = new Criteria();
$c->setPrimaryTableName(BookTableMap::TABLE_NAME);
$c->add(BookTableMap::AUTHOR_ID, 'lkhlkhj');
$db = Propel::getServiceContainer()->getAdapter($c->getDbName());
$c->doInsert($con);
$this->fail('Missing expected exception on BAD SQL');
} catch (PropelException $e) {
if ($db->isGetIdBeforeInsert()) {
$this->assertContains($this->getSql('[INSERT INTO book (AUTHOR_ID,ID) VALUES (:p1,:p2)]'), $e->getMessage(), 'SQL query is written in the exception message');
} else {
$this->assertContains($this->getSql('[INSERT INTO `book` (`AUTHOR_ID`) VALUES (:p1)]'), $e->getMessage(), 'SQL query is written in the exception message');
}
}
}
示例8: testDoSelectOrderByRank
public function testDoSelectOrderByRank()
{
$c = new Criteria();
$c->add(SortableTable12TableMap::SCOPE_COL, 1);
$objects = SortableTable12Query::doSelectOrderByRank($c)->getArrayCopy();
$oldRank = 0;
while ($object = array_shift($objects)) {
$this->assertTrue($object->getRank() > $oldRank);
$oldRank = $object->getRank();
}
$c = new Criteria();
$c->add(SortableTable12TableMap::SCOPE_COL, 1);
$objects = SortableTable12Query::doSelectOrderByRank($c, Criteria::DESC)->getArrayCopy();
$oldRank = 10;
while ($object = array_shift($objects)) {
$this->assertTrue($object->getRank() < $oldRank);
$oldRank = $object->getRank();
}
}
示例9: init
/**
* Init some properties with the help of outer class
* @param Criteria $criteria The outer class
*/
public function init(Criteria $criteria)
{
try {
$db = Propel::getServiceContainer()->getAdapter($criteria->getDbName());
$this->setAdapter($db);
} catch (\Exception $e) {
// we are only doing this to allow easier debugging, so
// no need to throw up the exception, just make note of it.
Propel::log("Could not get a AdapterInterface, sql may be wrong", Propel::LOG_ERR);
}
// init $this->realtable
$realtable = $criteria->getTableForAlias($this->table);
$this->realtable = $realtable ? $realtable : $this->table;
}
示例10: testCombineDirtyOperators
public function testCombineDirtyOperators()
{
$this->c->addCond('cond1', "INVOICE.COST1", "1000", Criteria::GREATER_EQUAL);
$this->c->addCond('cond2', "INVOICE.COST2", "2000", Criteria::LESS_EQUAL);
$this->c->combine(['cond1', 'cond2'], 'AnD', 'cond12');
$this->c->addCond('cond3', "INVOICE.COST3", "8000", Criteria::GREATER_EQUAL);
$this->c->addCond('cond4', "INVOICE.COST4", "9000", Criteria::LESS_EQUAL);
$this->c->combine(['cond3', 'cond4'], 'aNd', 'cond34');
$this->c->combine(['cond12', 'cond34'], 'oR');
$expect = $this->getSql("SELECT FROM INVOICE WHERE ((INVOICE.COST1>=:p1 AND INVOICE.COST2<=:p2) OR (INVOICE.COST3>=:p3 AND INVOICE.COST4<=:p4))");
$expect_params = [['table' => 'INVOICE', 'column' => 'COST1', 'value' => '1000'], ['table' => 'INVOICE', 'column' => 'COST2', 'value' => '2000'], ['table' => 'INVOICE', 'column' => 'COST3', 'value' => '8000'], ['table' => 'INVOICE', 'column' => 'COST4', 'value' => '9000']];
$params = [];
$result = $this->c->createSelectSql($params);
$this->assertEquals($expect, $result);
$this->assertEquals($expect_params, $params);
}
示例11: toCriteria
/**
* @inheritdoc
*/
public function toCriteria()
{
$criteria = new Criteria();
if ($this->filterTransfer->getLimit() !== null) {
$criteria->setLimit($this->filterTransfer->getLimit());
}
if ($this->filterTransfer->getOffset() !== null) {
$criteria->setOffset($this->filterTransfer->getOffset());
}
if ($this->filterTransfer->getOrderBy() !== null) {
if ($this->filterTransfer->getOrderDirection() === 'ASC') {
$criteria->addAscendingOrderByColumn($this->filterTransfer->getOrderBy());
} elseif ($this->filterTransfer->getOrderDirection() === 'DESC') {
$criteria->addDescendingOrderByColumn($this->filterTransfer->getOrderBy());
}
}
return $criteria;
}
示例12: addJoinProductI18n
/**
* Join products and their URLs
*
* @param Criteria $query
*/
protected function addJoinProductI18n(Criteria &$query)
{
// Join RewritingURL with Product to have only visible products
$join = new Join();
$join->addExplicitCondition(RewritingUrlTableMap::TABLE_NAME, 'VIEW_ID', null, ProductTableMap::TABLE_NAME, 'ID', null);
$join->setJoinType(Criteria::INNER_JOIN);
$query->addJoinObject($join, 'productJoin');
$query->addJoinCondition('productJoin', ProductTableMap::VISIBLE, 1, Criteria::EQUAL, \PDO::PARAM_INT);
// Join RewritingURL with ProductI18n to have product title for it's image
$joinI18n = new Join();
$joinI18n->addExplicitCondition(RewritingUrlTableMap::TABLE_NAME, 'VIEW_ID', null, ProductI18nTableMap::TABLE_NAME, 'ID', null);
$joinI18n->addExplicitCondition(RewritingUrlTableMap::TABLE_NAME, 'VIEW_LOCALE', null, ProductI18nTableMap::TABLE_NAME, 'LOCALE', null);
$joinI18n->setJoinType(Criteria::INNER_JOIN);
$query->addJoinObject($joinI18n);
// Join RewritingURL with ProductImage to have image file
$joinImage = new Join();
$joinImage->addExplicitCondition(RewritingUrlTableMap::TABLE_NAME, 'VIEW_ID', null, ProductImageTableMap::TABLE_NAME, 'PRODUCT_ID', null);
$joinImage->setJoinType(Criteria::INNER_JOIN);
$query->addJoinObject($joinImage, 'productImageJoin');
$query->addJoinCondition('productImageJoin', ProductImageTableMap::VISIBLE, 1, Criteria::EQUAL, \PDO::PARAM_INT);
}
示例13: buildPkeyCriteria
/**
* Builds a Criteria object containing the primary key for this object.
*
* Unlike buildCriteria() this method includes the primary key values regardless
* of whether or not they have been modified.
*
* @return Criteria The Criteria object containing value(s) for primary key(s).
*/
public function buildPkeyCriteria()
{
$criteria = new Criteria(CustomerTitleI18nTableMap::DATABASE_NAME);
$criteria->add(CustomerTitleI18nTableMap::ID, $this->id);
$criteria->add(CustomerTitleI18nTableMap::LOCALE, $this->locale);
return $criteria;
}
示例14: buildCriteria
/**
* Build a Criteria object containing the values of all modified columns in this object.
*
* @return Criteria The Criteria object containing all modified values.
*/
public function buildCriteria()
{
$criteria = new Criteria(WishlistProductTableMap::DATABASE_NAME);
if ($this->isColumnModified(WishlistProductTableMap::COL_WISHLIST_PRODUCT_ID)) {
$criteria->add(WishlistProductTableMap::COL_WISHLIST_PRODUCT_ID, $this->wishlist_product_id);
}
if ($this->isColumnModified(WishlistProductTableMap::COL_WISHLIST_ID)) {
$criteria->add(WishlistProductTableMap::COL_WISHLIST_ID, $this->wishlist_id);
}
if ($this->isColumnModified(WishlistProductTableMap::COL_PRODUCT_ID)) {
$criteria->add(WishlistProductTableMap::COL_PRODUCT_ID, $this->product_id);
}
if ($this->isColumnModified(WishlistProductTableMap::COL_WISHLIST_PRODUCT_COMMENT)) {
$criteria->add(WishlistProductTableMap::COL_WISHLIST_PRODUCT_COMMENT, $this->wishlist_product_comment);
}
if ($this->isColumnModified(WishlistProductTableMap::COL_CREATED_AT)) {
$criteria->add(WishlistProductTableMap::COL_CREATED_AT, $this->created_at);
}
if ($this->isColumnModified(WishlistProductTableMap::COL_UPDATED_AT)) {
$criteria->add(WishlistProductTableMap::COL_UPDATED_AT, $this->updated_at);
}
return $criteria;
}
示例15: testCreateSelectSqlPartAliasAll
public function testCreateSelectSqlPartAliasAll()
{
$db = Propel::getServiceContainer()->getAdapter(BookTableMap::DATABASE_NAME);
$c = new Criteria();
$c->addSelectColumn(BookTableMap::COL_ID);
$c->addAsColumn('book_id', BookTableMap::COL_ID);
$fromClause = [];
$selectSql = $db->createSelectSqlPart($c, $fromClause, true);
$this->assertEquals('SELECT book.id AS book_id_1, book.id AS book_id', $selectSql, 'createSelectSqlPart() aliases all columns if passed true as last parameter');
$this->assertEquals([], $fromClause, 'createSelectSqlPart() does not add the tables from an all-aliased list of select columns');
}