本文整理汇总了PHP中BookQuery::create方法的典型用法代码示例。如果您正苦于以下问题:PHP BookQuery::create方法的具体用法?PHP BookQuery::create怎么用?PHP BookQuery::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BookQuery
的用法示例。
在下文中一共展示了BookQuery::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFilterById
/**
* testFilterById
*
* Various test for filterById functions
* Id's are autoincrement so we have to use a Select to get current ID's
*
*/
public function testFilterById()
{
// find by single id
$book = PropelQuery::from('Book b')->where('b.Title like ?', 'Don%')->orderBy('b.ISBN', 'desc')->findOne();
$c = BookQuery::create()->filterById($book->getId());
$book2 = $c->findOne();
$this->assertTrue($book2 instanceof Book);
$this->assertEquals('Don Juan', $book2->getTitle());
//find range
$booksAll = PropelQuery::from('Book b')->orderBy('b.ID', 'asc')->find();
$booksIn = BookQuery::create()->filterById(array($booksAll[1]->getId(), $booksAll[2]->getId()))->find();
$this->assertTrue($booksIn[0] == $booksAll[1]);
$this->assertTrue($booksIn[1] == $booksAll[2]);
// filter by min value with greater equal
$booksIn = null;
$booksIn = BookQuery::create()->filterById(array('min' => $booksAll[2]->getId()))->find();
$this->assertTrue($booksIn[1] == $booksAll[3]);
// filter by max value with less equal
$booksIn = null;
$booksIn = BookQuery::create()->filterById(array('max' => $booksAll[1]->getId()))->find();
$this->assertTrue($booksIn[1] == $booksAll[1]);
// check backwards compatibility:
// SELECT FROM `book` WHERE book.id IN (:p1,:p2)
// must be the same as
// SELECT FROM `book` WHERE (book.id>=:p1 AND book.id<=:p2)
$minMax = BookQuery::create()->filterById(array('min' => $booksAll[1]->getId(), 'max' => $booksAll[2]->getId()))->find();
$In = BookQuery::create()->filterById(array($booksAll[1]->getId(), $booksAll[2]->getId()))->find();
$this->assertTrue($minMax[0] === $In[0]);
$this->assertTrue(count($minMax->getData()) === count($In->getData()));
}
示例2: testGetResultsRespectsFormatter
public function testGetResultsRespectsFormatter()
{
$this->createBooks(5);
$query = BookQuery::create();
$query->setFormatter(ModelCriteria::FORMAT_ARRAY);
$pager = new PropelModelPager($query, 4);
$pager->setPage(1);
$pager->init();
$this->assertTrue($pager->getResults() instanceof PropelArrayCollection, 'getResults() returns a PropelArrayCollection if the query uses array hydration');
}
示例3: testSerializeHydratedObject
public function testSerializeHydratedObject()
{
$book = new Book();
$book->setTitle('Foo3');
$book->setISBN('1234');
$book->save();
BookPeer::clearInstancePool();
$book = BookQuery::create()->findOneByTitle('Foo3');
$sb = serialize($book);
$this->assertEquals($book, unserialize($sb));
}
示例4: testLocales
public function testLocales()
{
$q = \BookQuery::create();
$q->setLocale('de');
$q->filterByTitle('Herr der Ringe');
$b = $q->findOne();
$this->assertNotNull($b);
$q = \BookQuery::create();
$q->setLocale('de');
$q->filterByTitle('Yubiwa Monogatari', null, 'ja-latn-JP');
$b = $q->findOne();
$this->assertNotNull($b);
}
示例5: findOrCreateOne
public function findOrCreateOne($book_name)
{
# Attempt to find book
$book = BookQuery::create()->filterByName($book_name)->findOne();
# Return or create book
if ($book) {
return $book;
} else {
$book = new Book();
$book->setName($book_name)->save();
return $book;
}
}
示例6: getBookByName
function getBookByName($book_name)
{
# Get book object (if possible)
$book_object = BookQuery::create()->findOneByName($book_name);
# Get book object by abbreviation (if necessary)
if (!$book_object) {
$book_abbreviation_object = BookAbbreviationQuery::create()->findOneByName($book_name);
if ($book_abbreviation_object) {
$book_object = $book_abbreviation_object->getBook();
}
}
# Return book object
return $book_object;
}
示例7: testGetNbResults
public function testGetNbResults()
{
BookQuery::create()->deleteAll();
$pager = $this->getPager(4, 1);
$this->assertEquals(0, $pager->getNbResults(), 'getNbResults() returns 0 when there are no results');
$this->createBooks(5);
$pager = $this->getPager(4, 1);
$this->assertEquals(5, $pager->getNbResults(), 'getNbResults() returns the total number of results');
$pager = $this->getPager(2, 1);
$this->assertEquals(5, $pager->getNbResults(), 'getNbResults() returns the total number of results');
$pager = $this->getPager(2, 2);
$this->assertEquals(5, $pager->getNbResults(), 'getNbResults() returns the total number of results');
$pager = $this->getPager(7, 6);
$this->assertEquals(5, $pager->getNbResults(), 'getNbResults() returns the total number of results');
$pager = $this->getPager(0, 0);
$this->assertEquals(5, $pager->getNbResults(), 'getNbResults() returns the total number of results');
}
示例8: getVersesByReference
function getVersesByReference($reference_string)
{
# Get reference data
$reference_data = getReferenceData($reference_string);
# Get book object
$book_object = BookQuery::create()->filterByName($reference_data['book'])->findOne();
if (!$book_object) {
return false;
}
# Get verses object
$verses_object = VerseQuery::create()->filterByBook($book_object)->filterByChapterNumber($reference_data['chapter'])->_if($reference_data['verses'])->filterByVerseNumber($reference_data['verses'])->_endif()->find();
if (!$verses_object) {
return false;
}
# Return verses object
return $verses_object;
}
示例9: getPassageData
function getPassageData($reference_string, $bible_code = 'kjv')
{
# Stop if no reference string provided
if (!$reference_string) {
return;
}
# Get reference data
$reference_data = getReferenceData($reference_string);
# Get bible object
$bible_object = BibleQuery::create()->filterByCode($bible_code)->findOne();
# Get book object
$book_object = BookQuery::create()->filterByName($reference_data['book'])->findOne();
# Define passage data
$passage_data = ['bible' => ['code' => ['default' => $bible_object->getCode(), 'formatted' => strtoupper($bible_object->getCode())], 'id' => $bible_object->getId(), 'name' => $bible_object->getName()], 'book' => ['id' => $book_object->getId(), 'name' => $book_object->getName()], 'chapter' => ['number' => $reference_data['chapter']], 'reference' => ['string' => $reference_string], 'verses' => $reference_data['verses']];
# Return passage data
return $passage_data;
}
示例10: testIsPrimary
public function testIsPrimary()
{
$q = AuthorQuery::create()->joinBook();
$joins = $q->getJoins();
$join = $joins['Book'];
$with = new ModelWith($join);
$this->assertTrue($with->isPrimary(), 'A ModelWith initialized from a primary join is primary');
$q = BookQuery::create()->joinAuthor()->joinReview();
$joins = $q->getJoins();
$join = $joins['Review'];
$with = new ModelWith($join);
$this->assertTrue($with->isPrimary(), 'A ModelWith initialized from a primary join is primary');
$q = AuthorQuery::create()->join('Author.Book')->join('Book.Publisher');
$joins = $q->getJoins();
$join = $joins['Publisher'];
$with = new ModelWith($join);
$this->assertFalse($with->isPrimary(), 'A ModelWith initialized from a non-primary join is not primary');
}
示例11: testSetterOneToManyReplacesOldObjectsByNewObjects
public function testSetterOneToManyReplacesOldObjectsByNewObjects()
{
// Ensure no data
BookQuery::create()->deleteAll();
AuthorQuery::create()->deleteAll();
$books = new PropelObjectCollection();
foreach (array('foo', 'bar') as $title) {
$b = new Book();
$b->setTitle($title);
$books[] = $b;
}
$a = new Author();
$a->setBooks($books);
$a->save();
$books = $a->getBooks();
$this->assertEquals('foo', $books[0]->getTitle());
$this->assertEquals('bar', $books[1]->getTitle());
$books = new PropelObjectCollection();
foreach (array('bam', 'bom') as $title) {
$b = new Book();
$b->setTitle($title);
$books[] = $b;
}
$a->setBooks($books);
$a->save();
$books = $a->getBooks();
$this->assertEquals('bam', $books[0]->getTitle());
$this->assertEquals('bom', $books[1]->getTitle());
$this->assertEquals(1, AuthorQuery::create()->count());
$this->assertEquals(2, BookQuery::create()->count());
}
示例12: testClone
public function testClone()
{
$bookQuery1 = BookQuery::create()->filterByPrice(1);
$bookQuery2 = clone $bookQuery1;
$bookQuery2->filterByPrice(2);
$params = array();
$sql = BasePeer::createSelectSql($bookQuery1, $params);
$this->assertEquals('SELECT FROM `book` WHERE book.PRICE=:p1', $sql, 'conditions applied on a cloned query don\'t get applied on the original query');
}
示例13: delete
/**
* Removes this object from datastore and sets delete attribute.
*
* @param PropelPDO $con
* @return void
* @throws PropelException
* @see BaseObject::setDeleted()
* @see BaseObject::isDeleted()
*/
public function delete(PropelPDO $con = null)
{
if ($this->isDeleted()) {
throw new PropelException("This object has already been deleted.");
}
if ($con === null) {
$con = Propel::getConnection(BookPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
}
$con->beginTransaction();
try {
$deleteQuery = BookQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
$ret = $this->preDelete($con);
if ($ret) {
$deleteQuery->delete($con);
$this->postDelete($con);
$con->commit();
$this->setDeleted(true);
} else {
$con->commit();
}
} catch (Exception $e) {
$con->rollBack();
throw $e;
}
}
示例14: testPruneSimpleKey
public function testPruneSimpleKey()
{
BookstoreDataPopulator::depopulate();
BookstoreDataPopulator::populate();
$nbBooks = BookQuery::create()->prune()->count();
$this->assertEquals(4, $nbBooks, 'prune() does nothing when passed a null object');
$testBook = BookQuery::create()->findOne();
$nbBooks = BookQuery::create()->prune($testBook)->count();
$this->assertEquals(3, $nbBooks, 'prune() removes an object from the result');
}
示例15: countBooks
/**
* Returns the number of related Book objects.
*
* @param Criteria $criteria
* @param boolean $distinct
* @param PropelPDO $con
* @return int Count of related Book objects.
* @throws PropelException
*/
public function countBooks(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
{
if (null === $this->collBooks || null !== $criteria) {
if ($this->isNew() && null === $this->collBooks) {
return 0;
} else {
$query = BookQuery::create(null, $criteria);
if ($distinct) {
$query->distinct();
}
return $query->filterByAuthor($this)->count($con);
}
} else {
return count($this->collBooks);
}
}