本文整理汇总了PHP中ModelCriteria类的典型用法代码示例。如果您正苦于以下问题:PHP ModelCriteria类的具体用法?PHP ModelCriteria怎么用?PHP ModelCriteria使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ModelCriteria类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testExplainPlanFromObject
public function testExplainPlanFromObject()
{
BookstoreDataPopulator::depopulate($this->con);
BookstoreDataPopulator::populate($this->con);
$db = Propel::getDb(BookPeer::DATABASE_NAME);
$c = new ModelCriteria('bookstore', 'Book');
$c->join('Book.Author');
$c->where('Author.FirstName = ?', 'Neal');
$c->select('Title');
$explain = $c->explain($this->con);
if ($db instanceof DBMySQL) {
$this->assertEquals(sizeof($explain), 2, 'Explain plan return two lines');
// explain can change sometime, test can't be strict
$this->assertArrayHasKey('select_type', $explain[0], 'Line 1, select_type key exist');
$this->assertArrayHasKey('table', $explain[0], 'Line 1, table key exist');
$this->assertArrayHasKey('type', $explain[0], 'Line 1, type key exist');
$this->assertArrayHasKey('possible_keys', $explain[0], 'Line 1, possible_keys key exist');
$this->assertArrayHasKey('select_type', $explain[1], 'Line 2, select_type key exist');
$this->assertArrayHasKey('table', $explain[1], 'Line 2, table key exist');
$this->assertArrayHasKey('type', $explain[1], 'Line 2, type key exist');
$this->assertArrayHasKey('possible_keys', $explain[1], 'Line 2, possible_keys key exist');
} elseif ($db instanceof DBOracle) {
$this->assertTrue(sizeof($explain) > 2, 'Explain plan return more than 2 lines');
} else {
$this->markTestSkipped('Cannot test explain plan on adapter ' . get_class($db));
}
}
示例2: union
/**
* Produces a union-query from two queries.
*
* @todo Implement support for ORDER, LIMIT etc.
*
* @param ModelCriteria $mc1
* @param ModelCriteria $mc2
* @return mixed
*/
public static function union(ModelCriteria $mc1, ModelCriteria $mc2)
{
$dbMap = Propel::getDatabaseMap($mc1->getDbName());
$db = Propel::getDB($mc1->getDbName());
$con = Propel::getConnection($mc1->getDbName(), Propel::CONNECTION_READ);
// we may modify criteria, so copy it first
$c1 = clone $mc1;
$c2 = clone $mc2;
// check that the columns of the main class are already added (if this is the primary ModelCriteria)
if (!$c1->hasSelectClause() && !$c1->getPrimaryCriteria()) {
$c1->addSelfSelectColumns();
}
if (!$c2->hasSelectClause() && !$c2->getPrimaryCriteria()) {
$c2->addSelfSelectColumns();
}
$con->beginTransaction();
try {
$params = array();
$sql1 = BasePeer::createSelectSql($c1, $params);
$sql2 = BasePeer::createSelectSql($c2, $params);
$stmt = $con->prepare("({$sql1}) UNION ALL ({$sql2})");
$db->bindValues($stmt, $params, $dbMap);
$stmt->execute();
$con->commit();
} catch (PropelException $e) {
$con->rollback();
throw $e;
}
return $c1->getFormatter()->init($c1)->format($stmt);
}
示例3: loadByType
public function loadByType(&$model)
{
$C = new ModelCriteria();
$C->addClause(ModelCriteria::EQUALS, 'type', $model->type);
$models = self::select($model->modelName, $C);
if (count($models) > 0) {
$model = $models[0];
return TRUE;
}
return FALSE;
}
示例4: __construct
/**
* Constructor
*
* @param \ModelCriteria|string $modelOrQuery A query object, or model class as string.
* @param array $options
*/
public function __construct($modelOrQuery, array $options = array())
{
if (is_string($modelOrQuery)) {
$this->model = $modelOrQuery;
$this->query = \PropelQuery::from($this->model);
} else {
if ($modelOrQuery instanceof \ModelCriteria) {
$this->query = $modelOrQuery;
$this->model = $this->query->getModelName();
} else {
throw new \Exception('Invalid argument');
}
}
parent::__construct($options);
}
示例5: getChartDatasetData
public static function getChartDatasetData(\ModelCriteria $q)
{
$data = array('raw' => array(), 'daily' => array(), 'weekly' => array(), 'monthly' => array());
$cache = self::getGemCache();
$rates = $q->select(array('rateDatetime', 'rate'))->filterByRateDatetime(date("Y-m-d 00:00:00", strtotime("-1 week")), \Criteria::GREATER_EQUAL)->find();
/*
* use these 3 arrays to maintain the values over which we calculate the moving average
* every value is added to the array, but we pop off values older then the specified threshold (day, week, month)
*/
$dailyValues = array();
$weeklyValues = array();
$monthlyValues = array();
foreach ($rates as $rateEntry) {
$date = new DateTime("{$rateEntry['rateDatetime']}");
$date->setTimezone(new DateTimeZone('UTC'));
$timestamp = $date->getTimestamp();
$dailyValues[$timestamp] = $rateEntry['rate'];
$weeklyValues[$timestamp] = $rateEntry['rate'];
$monthlyValues[$timestamp] = $rateEntry['rate'];
$rateEntry['rate'] = round($rateEntry['rate'], 2);
foreach ($dailyValues as $keyTimestamp => $value) {
if ($timestamp - $keyTimestamp > 86400) {
unset($dailyValues[$keyTimestamp]);
} else {
break;
}
}
foreach ($weeklyValues as $keyTimestamp => $value) {
if ($timestamp - $keyTimestamp > 604800) {
unset($weeklyValues[$keyTimestamp]);
} else {
break;
}
}
foreach ($monthlyValues as $keyTimestamp => $value) {
if ($timestamp - $keyTimestamp > 18144000) {
unset($monthlyValues[$keyTimestamp]);
} else {
break;
}
}
$data['raw'][] = array($timestamp * 1000, $rateEntry['rate']);
$data['daily'][] = array($timestamp * 1000, round(array_sum($dailyValues) / count($dailyValues), 2));
$data['weekly'][] = array($timestamp * 1000, round(array_sum($weeklyValues) / count($weeklyValues), 2));
$data['monthly'][] = array($timestamp * 1000, round(array_sum($monthlyValues) / count($monthlyValues), 2));
}
return $data;
}
示例6: testPreAndPostDelete
public function testPreAndPostDelete()
{
$c = new ModelCriteria('bookstore', 'Book');
$books = $c->find();
$count = count($books);
$book = $books->shift();
$this->con->lastAffectedRows = 0;
$c = new ModelCriteriaWithPreAndPostDeleteHook('bookstore', 'Book', 'b');
$c->where('b.Id = ?', $book->getId());
$nbBooks = $c->delete($this->con);
$this->assertEquals(12, $this->con->lastAffectedRows, 'postDelete() is called after delete() even if preDelete() returns not null');
$this->con->lastAffectedRows = 0;
$c = new ModelCriteriaWithPreAndPostDeleteHook('bookstore', 'Book');
$nbBooks = $c->deleteAll($this->con);
$this->assertEquals(12, $this->con->lastAffectedRows, 'postDelete() is called after deleteAll() even if preDelete() returns not null');
}
示例7: testGetConsumerByKey
public function testGetConsumerByKey()
{
$consumerKey = 'bar';
$this->query->expects($this->once())->method('filterByConsumerKey')->with($this->equalTo('bar'));
$this->query->expects($this->once())->method('findOne');
$this->consumerProvider->getConsumerByKey($consumerKey);
}
示例8: __construct
public function __construct($table, $groupField, $name, $joinCriterion)
{
parent::__construct();
$this->name = $name;
$this->selectTable($table);
$this->selectField($groupField, "group_field");
$this->groupBy($groupField);
$this->joinCriterion = $joinCriterion;
}
示例9: __construct
/**
* Initializes internal state of BasePagePropertyQuery object.
*
* @param string $dbName The dabase name
* @param string $modelName The phpName of a model, e.g. 'Book'
* @param string $modelAlias The alias for the model in this query, e.g. 'b'
*/
public function __construct($dbName = null, $modelName = null, $modelAlias = null)
{
if (null === $dbName) {
$dbName = 'rapila';
}
if (null === $modelName) {
$modelName = 'PageProperty';
}
parent::__construct($dbName, $modelName, $modelAlias);
}
示例10: __construct
/**
* Initializes internal state of BaseUcConfigurationQuery object.
*
* @param string $dbName The dabase name
* @param string $modelName The phpName of a model, e.g. 'Book'
* @param string $modelAlias The alias for the model in this query, e.g. 'b'
*/
public function __construct($dbName = null, $modelName = null, $modelAlias = null)
{
if (null === $dbName) {
$dbName = 'cpu';
}
if (null === $modelName) {
$modelName = 'UcConfiguration';
}
parent::__construct($dbName, $modelName, $modelAlias);
}
示例11: __construct
/**
* Initializes internal state of BaseGalleryFolderQuery object.
*
* @param string $dbName The dabase name
* @param string $modelName The phpName of a model, e.g. 'Book'
* @param string $modelAlias The alias for the model in this query, e.g. 'b'
*/
public function __construct($dbName = null, $modelName = null, $modelAlias = null)
{
if (null === $dbName) {
$dbName = 'propel';
}
if (null === $modelName) {
$modelName = 'GalleryFolder';
}
parent::__construct($dbName, $modelName, $modelAlias);
}
示例12: __construct
/**
* Initializes internal state of BaseJournalEntryImageQuery object.
*
* @param string $dbName The dabase name
* @param string $modelName The phpName of a model, e.g. 'Book'
* @param string $modelAlias The alias for the model in this query, e.g. 'b'
*/
public function __construct($dbName = null, $modelName = null, $modelAlias = null)
{
if (null === $dbName) {
$dbName = 'rapila';
}
if (null === $modelName) {
$modelName = 'JournalEntryImage';
}
parent::__construct($dbName, $modelName, $modelAlias);
}
示例13: __construct
/**
* Initializes internal state of BaseGastofacturacionQuery object.
*
* @param string $dbName The dabase name
* @param string $modelName The phpName of a model, e.g. 'Book'
* @param string $modelAlias The alias for the model in this query, e.g. 'b'
*/
public function __construct($dbName = null, $modelName = null, $modelAlias = null)
{
if (null === $dbName) {
$dbName = 'itrade';
}
if (null === $modelName) {
$modelName = 'Gastofacturacion';
}
parent::__construct($dbName, $modelName, $modelAlias);
}
示例14: __construct
/**
* Initializes internal state of BaseExpedienteanticipoQuery object.
*
* @param string $dbName The dabase name
* @param string $modelName The phpName of a model, e.g. 'Book'
* @param string $modelAlias The alias for the model in this query, e.g. 'b'
*/
public function __construct($dbName = null, $modelName = null, $modelAlias = null)
{
if (null === $dbName) {
$dbName = 'itrade';
}
if (null === $modelName) {
$modelName = 'Expedienteanticipo';
}
parent::__construct($dbName, $modelName, $modelAlias);
}
示例15: __construct
/**
* Initializes internal state of BaseLanguageObjectHistoryQuery object.
*
* @param string $dbName The dabase name
* @param string $modelName The phpName of a model, e.g. 'Book'
* @param string $modelAlias The alias for the model in this query, e.g. 'b'
*/
public function __construct($dbName = null, $modelName = null, $modelAlias = null)
{
if (null === $dbName) {
$dbName = 'rapila';
}
if (null === $modelName) {
$modelName = 'LanguageObjectHistory';
}
parent::__construct($dbName, $modelName, $modelAlias);
}