当前位置: 首页>>代码示例>>PHP>>正文


PHP Bookstore\Book类代码示例

本文整理汇总了PHP中Propel\Tests\Bookstore\Book的典型用法代码示例。如果您正苦于以下问题:PHP Book类的具体用法?PHP Book怎么用?PHP Book使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Book类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testFormatALotOfResults

 public function testFormatALotOfResults()
 {
     $nbBooks = 50;
     $con = Propel::getConnection(BookPeer::DATABASE_NAME);
     Propel::disableInstancePooling();
     $book = new Book();
     for ($i = 0; $i < $nbBooks; $i++) {
         $book->clear();
         $book->setTitle('BookTest' . $i);
         $book->save($con);
     }
     $stmt = $con->query('SELECT * FROM book');
     $formatter = new PropelOnDemandFormatter();
     $formatter->init(new ModelCriteria('bookstore', 'Book'));
     $books = $formatter->format($stmt);
     $this->assertTrue($books instanceof PropelOnDemandCollection, 'PropelOnDemandFormatter::format() returns a PropelOnDemandCollection');
     $this->assertEquals($nbBooks, count($books), 'PropelOnDemandFormatter::format() returns a collection that counts as many rows as the results in the query');
     $i = 0;
     foreach ($books as $book) {
         $this->assertTrue($book instanceof Book, 'PropelOnDemandFormatter::format() returns a collection of Model objects');
         $this->assertEquals('BookTest' . $i, $book->getTitle(), 'PropelOnDemandFormatter::format() returns the model objects matching the query');
         $i++;
     }
     Propel::enableInstancePooling();
 }
开发者ID:RafalFilipek,项目名称:Propel2,代码行数:25,代码来源:PropelOnDemandFormatterTest.php

示例2: testClear

 public function testClear()
 {
     $b = new Book();
     $b->setNew(false);
     $b->clear();
     $this->assertTrue($b->isNew(), 'clear() sets the object to new');
     $b = new Book();
     $b->setDeleted(true);
     $b->clear();
     $this->assertFalse($b->isDeleted(), 'clear() sets the object to not deleted');
 }
开发者ID:rouffj,项目名称:Propel2,代码行数:11,代码来源:AbstractOMBuilderTest.php

示例3: createBooks

 protected function createBooks($nb = 15, $con = null)
 {
     BookQuery::create()->deleteAll($con);
     $books = new ObjectCollection();
     $books->setModel('\\Propel\\Tests\\Bookstore\\Book');
     for ($i = 0; $i < $nb; $i++) {
         $b = new Book();
         $b->setTitle('Book' . $i);
         $books[] = $b;
     }
     $books->save($con);
 }
开发者ID:norfil,项目名称:Propel2,代码行数:12,代码来源:PropelModelPagerTest.php

示例4: testSerializeObjectWithCollections

 public function testSerializeObjectWithCollections()
 {
     $book1 = new Book();
     $book1->setTitle('Foo5');
     $book1->setISBN('1234');
     $book2 = new Book();
     $book2->setTitle('Foo6');
     $book2->setISBN('1234');
     $author = new Author();
     $author->setFirstName('JAne');
     $author->addBook($book1);
     $author->addBook($book2);
     $author->save();
     $a = clone $author;
     $sa = serialize($a);
     $author->clearAllReferences();
     $this->assertEquals($author, unserialize($sa));
 }
开发者ID:norfil,项目名称:Propel2,代码行数:18,代码来源:BaseObjectSerializeTest.php

示例5: testGroupByArray

 public function testGroupByArray()
 {
     $stephenson = new Author();
     $stephenson->setFirstName("Neal");
     $stephenson->setLastName("Stephenson");
     $stephenson->save();
     $byron = new Author();
     $byron->setFirstName("George");
     $byron->setLastName("Byron");
     $byron->save();
     $phoenix = new Book();
     $phoenix->setTitle("Harry Potter and the Order of the Phoenix");
     $phoenix->setISBN("043935806X");
     $phoenix->setAuthor($stephenson);
     $phoenix->save();
     $qs = new Book();
     $qs->setISBN("0380977427");
     $qs->setTitle("Quicksilver");
     $qs->setAuthor($stephenson);
     $qs->save();
     $dj = new Book();
     $dj->setISBN("0140422161");
     $dj->setTitle("Don Juan");
     $dj->setAuthor($stephenson);
     $dj->save();
     $td = new Book();
     $td->setISBN("067972575X");
     $td->setTitle("The Tin Drum");
     $td->setAuthor($byron);
     $td->save();
     $authors = AuthorQuery::create()->leftJoinBook()->select(array('FirstName', 'LastName'))->withColumn('COUNT(Book.Id)', 'nbBooks')->groupBy(array('FirstName', 'LastName'))->orderByLastName()->find();
     $expectedSql = 'SELECT COUNT(book.id) AS nbBooks, author.first_name AS "FirstName", author.last_name AS "LastName" FROM author LEFT JOIN book ON (author.id=book.author_id) GROUP BY author.first_name,author.last_name ORDER BY author.last_name ASC';
     $this->assertEquals($expectedSql, $this->con->getLastExecutedQuery());
     $this->assertEquals(2, count($authors));
     $this->assertEquals('George', $authors[0]['FirstName']);
     $this->assertEquals(1, $authors[0]['nbBooks']);
     $this->assertEquals('Neal', $authors[1]['FirstName']);
     $this->assertEquals(3, $authors[1]['nbBooks']);
 }
开发者ID:SwissalpS,项目名称:Propel2,代码行数:39,代码来源:ModelCriteriaGroupByArrayTest.php

示例6: testUtf8

 public function testUtf8()
 {
     $this->markTestSkipped('Skipped because of weird behavior on some platforms');
     $db = Propel::getServiceContainer()->getAdapter(BookPeer::DATABASE_NAME);
     $title = "Смерть на брудершафт. Младенец и черт";
     //        1234567890123456789012345678901234567
     //                 1         2         3
     $a = new Author();
     $a->setFirstName("Б.");
     $a->setLastName("АКУНИН");
     $p = new Publisher();
     $p->setName("Детектив российский, остросюжетная проза");
     $b = new Book();
     $b->setTitle($title);
     $b->setISBN("B-59246");
     $b->setAuthor($a);
     $b->setPublisher($p);
     $b->save();
     $b->reload();
     $this->assertEquals(37, iconv_strlen($b->getTitle(), 'utf-8'), "Expected 37 characters (not bytes) in title.");
     $this->assertTrue(strlen($b->getTitle()) > iconv_strlen($b->getTitle(), 'utf-8'), "Expected more bytes than characters in title.");
 }
开发者ID:norfil,项目名称:Propel2,代码行数:22,代码来源:CharacterEncodingTest.php

示例7: setUp

 protected function setUp()
 {
     parent::setUp();
     BookstoreDataPopulator::populate();
     $cr = new Criteria();
     $cr->add(AuthorPeer::LAST_NAME, "Rowling");
     $cr->add(AuthorPeer::FIRST_NAME, "J.K.");
     $rowling = AuthorPeer::doSelectOne($cr);
     $this->authorId = $rowling->getId();
     $book = new Book();
     $book->setTitle("Harry Potter and the Philosopher's Stone");
     $book->setISBN("1234");
     $book->setAuthor($rowling);
     $book->save();
     $this->books[] = $book->getId();
     $book = new Book();
     $book->setTitle("Harry Potter and the Chamber of Secrets");
     $book->setISBN("1234");
     $book->setAuthor($rowling);
     $book->save();
     $this->books[] = $book->getId();
     $book = new Book();
     $book->setTitle("Harry Potter and the Prisoner of Azkaban");
     $book->setISBN("1234");
     $book->setAuthor($rowling);
     $book->save();
     $this->books[] = $book->getId();
     $book = new Book();
     $book->setTitle("Harry Potter and the Goblet of Fire");
     $book->setISBN("1234");
     $book->setAuthor($rowling);
     $book->save();
     $this->books[] = $book->getId();
     $book = new Book();
     $book->setTitle("Harry Potter and the Half-Blood Prince");
     $book->setISBN("1234");
     $book->setAuthor($rowling);
     $book->save();
     $this->books[] = $book->getId();
     $book = new Book();
     $book->setTitle("Harry Potter and the Deathly Hallows");
     $book->setISBN("1234");
     $book->setAuthor($rowling);
     $book->save();
     $this->books[] = $book->getId();
 }
开发者ID:RafalFilipek,项目名称:Propel2,代码行数:46,代码来源:PropelPagerTest.php

示例8: setUp

 protected function setUp()
 {
     parent::setUp();
     $book1 = new Book();
     $book1->setId(9012);
     $book1->setTitle('Don Juan');
     $book1->setISBN('0140422161');
     $book1->setPrice(12.99);
     $book1->setAuthorId(5678);
     $book1->setPublisherId(1234);
     $book1->resetModified();
     $book2 = new Book();
     $book2->setId(58);
     $book2->setTitle('Harry Potter and the Order of the Phoenix');
     $book2->setISBN('043935806X');
     $book2->setPrice(10.99);
     $book2->resetModified();
     $this->coll = new ObjectCollection();
     $this->coll->setModel('\\Propel\\Tests\\Bookstore\\Book');
     $this->coll[] = $book1;
     $this->coll[] = $book2;
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:22,代码来源:CollectionConvertTest.php

示例9: testFindOneWithOneToManyCustomOrder

 public function testFindOneWithOneToManyCustomOrder()
 {
     $author1 = new Author();
     $author1->setFirstName('AA');
     $author2 = new Author();
     $author2->setFirstName('BB');
     $book1 = new Book();
     $book1->setTitle('Aaa');
     $book1->setAuthor($author1);
     $book1->save();
     $book2 = new Book();
     $book2->setTitle('Bbb');
     $book2->setAuthor($author2);
     $book2->save();
     $book3 = new Book();
     $book3->setTitle('Ccc');
     $book3->setAuthor($author1);
     $book3->save();
     $authors = AuthorQuery::create()->setFormatter(ModelCriteria::FORMAT_ARRAY)->leftJoin('Propel\\Tests\\Bookstore\\Author.Book')->orderBy('Book.Title')->with('Book')->find();
     $this->assertEquals(2, count($authors), 'with() used on a many-to-many doesn\'t change the main object count');
 }
开发者ID:rouffj,项目名称:Propel2,代码行数:21,代码来源:ArrayFormatterWithTest.php

示例10: testFindPkDoesNotCallPreSelectWhenUsingInstancePool

 public function testFindPkDoesNotCallPreSelectWhenUsingInstancePool()
 {
     $b = new Book();
     $b->setTitle('foo');
     $b->setISBN('FA404');
     $b->save();
     $q = new mySecondBookQuery();
     $this->assertFalse($q::$preSelectWasCalled);
     $q->findPk($b->getId());
     $this->assertFalse($q::$preSelectWasCalled);
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:11,代码来源:QueryBuilderTest.php

示例11: populate

 public static function populate($con = null)
 {
     if ($con === null) {
         $con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
     }
     $con->beginTransaction();
     // Add publisher records
     // ---------------------
     $scholastic = new Publisher();
     $scholastic->setName("Scholastic");
     // do not save, will do later to test cascade
     $morrow = new Publisher();
     $morrow->setName("William Morrow");
     $morrow->save($con);
     $morrow_id = $morrow->getId();
     $penguin = new Publisher();
     $penguin->setName("Penguin");
     $penguin->save();
     $penguin_id = $penguin->getId();
     $vintage = new Publisher();
     $vintage->setName("Vintage");
     $vintage->save($con);
     $vintage_id = $vintage->getId();
     $rowling = new Author();
     $rowling->setFirstName("J.K.");
     $rowling->setLastName("Rowling");
     // no save()
     $stephenson = new Author();
     $stephenson->setFirstName("Neal");
     $stephenson->setLastName("Stephenson");
     $stephenson->save($con);
     $stephenson_id = $stephenson->getId();
     $byron = new Author();
     $byron->setFirstName("George");
     $byron->setLastName("Byron");
     $byron->save($con);
     $byron_id = $byron->getId();
     $grass = new Author();
     $grass->setFirstName("Gunter");
     $grass->setLastName("Grass");
     $grass->save($con);
     $grass_id = $grass->getId();
     $phoenix = new Book();
     $phoenix->setTitle("Harry Potter and the Order of the Phoenix");
     $phoenix->setISBN("043935806X");
     $phoenix->setAuthor($rowling);
     $phoenix->setPublisher($scholastic);
     $phoenix->setPrice(10.99);
     $phoenix->save($con);
     $phoenix_id = $phoenix->getId();
     $qs = new Book();
     $qs->setISBN("0380977427");
     $qs->setTitle("Quicksilver");
     $qs->setPrice(11.99);
     $qs->setAuthor($stephenson);
     $qs->setPublisher($morrow);
     $qs->save($con);
     $qs_id = $qs->getId();
     $dj = new Book();
     $dj->setISBN("0140422161");
     $dj->setTitle("Don Juan");
     $dj->setPrice(12.99);
     $dj->setAuthor($byron);
     $dj->setPublisher($penguin);
     $dj->save($con);
     $dj_id = $dj->getId();
     $td = new Book();
     $td->setISBN("067972575X");
     $td->setTitle("The Tin Drum");
     $td->setPrice(13.99);
     $td->setAuthor($grass);
     $td->setPublisher($vintage);
     $td->save($con);
     $td_id = $td->getId();
     $r1 = new Review();
     $r1->setBook($phoenix);
     $r1->setReviewedBy("Washington Post");
     $r1->setRecommended(true);
     $r1->setReviewDate(time());
     $r1->save($con);
     $r1_id = $r1->getId();
     $r2 = new Review();
     $r2->setBook($phoenix);
     $r2->setReviewedBy("New York Times");
     $r2->setRecommended(false);
     $r2->setReviewDate(time());
     $r2->save($con);
     $r2_id = $r2->getId();
     $blob_path = _LOB_SAMPLE_FILE_PATH . '/tin_drum.gif';
     $clob_path = _LOB_SAMPLE_FILE_PATH . '/tin_drum.txt';
     $m1 = new Media();
     $m1->setBook($td);
     $m1->setCoverImage(file_get_contents($blob_path));
     // CLOB is broken in PDO OCI, see http://pecl.php.net/bugs/bug.php?id=7943
     if (get_class(Propel::getServiceContainer()->getAdapter()) != "OracleAdapter") {
         $m1->setExcerpt(file_get_contents($clob_path));
     }
     $m1->save($con);
     // Add book list records
     // ---------------------
//.........这里部分代码省略.........
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:101,代码来源:BookstoreDataPopulator.php

示例12: testfromCSV

 /**
  * @dataProvider toCsvDataProvider
  */
 public function testfromCSV($expected)
 {
     $book = new Book();
     $book->fromCSV($expected);
     // FIXME: fromArray() doesn't take related objects into account
     $book->resetModified();
     $author = $this->book->getAuthor();
     $this->book->setAuthor(null);
     $this->book->setAuthorId($author->getId());
     $publisher = $this->book->getPublisher();
     $this->book->setPublisher(null);
     $this->book->setPublisherId($publisher->getId());
     $this->book->resetModified();
     $this->assertEquals($this->book, $book);
 }
开发者ID:disider,项目名称:Propel2,代码行数:18,代码来源:ActiveRecordConvertTest.php

示例13: testFindOneWithEmptyLeftJoin

 public function testFindOneWithEmptyLeftJoin()
 {
     // save a book with no author
     $b = new Book();
     $b->setTitle('Foo');
     $b->setISBN('FA404');
     $b->save();
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
     $c->setFormatter(ModelCriteria::FORMAT_ON_DEMAND);
     $c->where('Propel\\Tests\\Bookstore\\Book.Title = ?', 'Foo');
     $c->leftJoin('Propel\\Tests\\Bookstore\\Book.Author');
     $c->with('Author');
     $c->limit(1);
     $con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
     $books = $c->find($con);
     foreach ($books as $book) {
         break;
     }
     $count = $con->getQueryCount();
     $author = $book->getAuthor();
     $this->assertNull($author, 'Related object is not hydrated if empty');
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:22,代码来源:OnDemandFormatterWithTest.php

示例14: testSetterCollectionReplacesOldObjectsByNewObjects

 public function testSetterCollectionReplacesOldObjectsByNewObjects()
 {
     // Ensure no data
     BookQuery::create()->deleteAll();
     BookClubListQuery::create()->deleteAll();
     BookListRelQuery::create()->deleteAll();
     $books = new ObjectCollection();
     foreach (array('foo', 'bar') as $title) {
         $b = new Book();
         $b->setTitle($title);
         $books[] = $b;
     }
     $bookClubList = new BookClubList();
     $bookClubList->setBooks($books);
     $bookClubList->save();
     $books = $bookClubList->getBooks();
     $this->assertEquals('foo', $books[0]->getTitle());
     $this->assertEquals('bar', $books[1]->getTitle());
     $books = new ObjectCollection();
     foreach (array('bam', 'bom') as $title) {
         $b = new Book();
         $b->setTitle($title);
         $books[] = $b;
     }
     $bookClubList->setBooks($books);
     $bookClubList->save();
     $books = $bookClubList->getBooks();
     $this->assertEquals('bam', $books[0]->getTitle());
     $this->assertEquals('bom', $books[1]->getTitle());
     $this->assertEquals(1, BookClubListQuery::create()->count());
     $this->assertEquals(2, BookListRelQuery::create()->count());
     $this->assertEquals(4, BookQuery::create()->count());
 }
开发者ID:rouffj,项目名称:Propel2,代码行数:33,代码来源:GeneratedObjectRelTest.php

示例15: testFindPkComplexAddsObjectToInstancePool

 public function testFindPkComplexAddsObjectToInstancePool()
 {
     $b = new Book();
     $b->setTitle('foo');
     $b->setISBN('FA404');
     $b->save($this->con);
     BookTableMap::clearInstancePool();
     BookQuery::create('b')->findPk($b->getId(), $this->con);
     $count = $this->con->getQueryCount();
     $book = BookQuery::create()->findPk($b->getId(), $this->con);
     $this->assertEquals($b, $book);
     $this->assertEquals($count, $this->con->getQueryCount());
 }
开发者ID:naldz,项目名称:cyberden,代码行数:13,代码来源:QueryBuilderTest.php


注:本文中的Propel\Tests\Bookstore\Book类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。