本文整理汇总了PHP中ModelCriteria::select方法的典型用法代码示例。如果您正苦于以下问题:PHP ModelCriteria::select方法的具体用法?PHP ModelCriteria::select怎么用?PHP ModelCriteria::select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModelCriteria
的用法示例。
在下文中一共展示了ModelCriteria::select方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}
示例3: testSelectArrayWithColumn
public function testSelectArrayWithColumn()
{
BookstoreDataPopulator::depopulate($this->con);
BookstoreDataPopulator::populate($this->con);
$c = new ModelCriteria('bookstore', 'Book');
$c->join('Book.Author');
$c->withColumn('LOWER(Book.Title)', 'LowercaseTitle');
$c->select(array('LowercaseTitle', 'Book.Title'));
$c->orderBy('Book.Title');
$rows = $c->find($this->con);
$expectedSQL = 'SELECT LOWER(book.TITLE) AS LowercaseTitle, book.TITLE AS "Book.Title" FROM `book` INNER JOIN `author` ON (book.AUTHOR_ID=author.ID) ORDER BY book.TITLE ASC';
$this->assertEquals($expectedSQL, $this->con->getLastExecutedQuery(), 'find() called after select(array) can cope with a column added with withColumn()');
$expectedRows = array(array('LowercaseTitle' => 'don juan', 'Book.Title' => 'Don Juan'), array('LowercaseTitle' => 'harry potter and the order of the phoenix', 'Book.Title' => 'Harry Potter and the Order of the Phoenix'), array('LowercaseTitle' => 'quicksilver', 'Book.Title' => 'Quicksilver'), array('LowercaseTitle' => 'the tin drum', 'Book.Title' => 'The Tin Drum'));
$this->assertEquals(serialize($rows->getData()), serialize($expectedRows), 'find() called after select(array) can cope with a column added with withColumn()');
}
示例4: testGetSelectReturnsArrayWhenSelectingAllColumns
public function testGetSelectReturnsArrayWhenSelectingAllColumns()
{
$c = new ModelCriteria('bookstore', 'Book');
$c->select('*');
$this->assertEquals(array('Book.Id', 'Book.Title', 'Book.ISBN', 'Book.Price', 'Book.PublisherId', 'Book.AuthorId'), $c->getSelect());
}
示例5: testWithColumnAndSelect
public function testWithColumnAndSelect()
{
$c = new ModelCriteria('bookstore', 'Author');
$c->join('Book');
$c->withColumn('COUNT(Book.Id)', 'NbBooks');
$c->select(array('FirstName', 'LastName'));
$collection = $c->find();
$this->assertThat($collection, $this->isInstanceOf('PropelCollection'));
foreach ($collection as $array) {
$this->assertArrayHasKey('FirstName', $array);
$this->assertArrayHasKey('LastName', $array);
$this->assertArrayHasKey('NbBooks', $array);
}
}
示例6: testQuotingAliases
public function testQuotingAliases()
{
$c = new ModelCriteria('bookstore', 'Book');
$c->withColumn('book.title', 'Book Title (*.)');
$c->select('Book Title (*.)');
$c->where('Book.Isbn = ?', '0380977427');
$title = $c->findOne();
$expectedSQL = "SELECT book.title AS `Book Title (*.)` FROM `book` WHERE book.isbn = '0380977427' LIMIT 1";
$this->assertEquals($expectedSQL, $this->con->getLastExecutedQuery());
$this->assertEquals('Quicksilver', $title);
}