本文整理汇总了PHP中Book::isNew方法的典型用法代码示例。如果您正苦于以下问题:PHP Book::isNew方法的具体用法?PHP Book::isNew怎么用?PHP Book::isNew使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Book
的用法示例。
在下文中一共展示了Book::isNew方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testIsNew
public function testIsNew()
{
$book = new Book();
$this->assertEquals($book->isNew(), true);
$book->id = 123;
$this->assertEquals($book->isNew(), false);
}
示例2: doSave
/**
* Performs the work of inserting or updating the row in the database.
*
* If the object is new, it inserts it; otherwise an update is performed.
* All related objects are also updated in this method.
*
* @param PropelPDO $con
* @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
* @throws PropelException
* @see save()
*/
protected function doSave(PropelPDO $con)
{
$affectedRows = 0;
// initialize var to track total num of affected rows
if (!$this->alreadyInSave) {
$this->alreadyInSave = true;
// We call the save method on the following object(s) if they
// were passed to this object by their coresponding set
// method. This object relates to these object(s) by a
// foreign key reference.
if ($this->aCategory !== null) {
if ($this->aCategory->isModified() || $this->aCategory->isNew()) {
$affectedRows += $this->aCategory->save($con);
}
$this->setCategory($this->aCategory);
}
if ($this->aBook !== null) {
if ($this->aBook->isModified() || $this->aBook->isNew()) {
$affectedRows += $this->aBook->save($con);
}
$this->setBook($this->aBook);
}
if ($this->isNew()) {
$this->modifiedColumns[] = ArticlePeer::ID;
}
// If this object has been modified, then save it to the database.
if ($this->isModified()) {
if ($this->isNew()) {
$pk = ArticlePeer::doInsert($this, $con);
$affectedRows += 1;
// we are assuming that there is only 1 row per doInsert() which
// should always be true here (even though technically
// BasePeer::doInsert() can insert multiple rows).
$this->setId($pk);
//[IMV] update autoincrement primary key
$this->setNew(false);
} else {
$affectedRows += ArticlePeer::doUpdate($this, $con);
}
$this->resetModified();
// [HL] After being saved an object is no longer 'modified'
}
if ($this->collAuthorArticles !== null) {
foreach ($this->collAuthorArticles as $referrerFK) {
if (!$referrerFK->isDeleted()) {
$affectedRows += $referrerFK->save($con);
}
}
}
if ($this->collAttachments !== null) {
foreach ($this->collAttachments as $referrerFK) {
if (!$referrerFK->isDeleted()) {
$affectedRows += $referrerFK->save($con);
}
}
}
$this->alreadyInSave = false;
}
return $affectedRows;
}
示例3: 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');
}
示例4: testSaveCanInsertNonEmptyObjects
public function testSaveCanInsertNonEmptyObjects()
{
$b = new Book();
$b->setTitle('foo');
$b->setIsbn('124');
$b->save();
$this->assertFalse($b->isNew());
$this->assertNotNull($b->getId());
}
示例5: testSetterCollectionWithManyToManyModifiedByReferenceWithAnExistingObject
public function testSetterCollectionWithManyToManyModifiedByReferenceWithAnExistingObject()
{
// Ensure no data
BookQuery::create()->deleteAll();
BookClubListQuery::create()->deleteAll();
BookListRelQuery::create()->deleteAll();
$book = new Book();
$book->setTitle('foo');
$book->save();
// The object isn't "new"
$this->assertFalse($book->isNew());
$bookClubList = new BookClubList();
$books = $bookClubList->getBooks();
// Add the object by reference
$books[] = $book;
$bookClubList->setBooks($books);
$bookClubList->save();
$this->assertEquals(1, BookQuery::create()->count());
$this->assertEquals(1, BookListRelQuery::create()->count());
$this->assertEquals(1, BookClubListQuery::create()->count());
}
示例6: testHasKeyId
public function testHasKeyId()
{
// after setting a key ID on a new object, it shall still be considered new but shall be aware of it's key ID.
$book = new Book();
$book->setKeyId(1);
$this->assertTrue($book->hasKeyId(), 'New object should be aware of its key when it was explicitly set via setKeyId.');
$this->assertTrue($book->isNew(), 'New object should still be new after its key was explicitly set via setKeyId.');
// make sure it works when calling the explicit setters for the columns making up the primary key.
$book = new Book();
$book->setBookId(1);
$this->assertTrue($book->hasKeyId(), 'New object should be aware of its key when it was explicitly set via setters.');
$this->assertTrue($book->isNew(), 'New object should still be new after its key was explicitly set via setters.');
}
示例7: testCreateDelete
public function testCreateDelete()
{
$connection = $this->getT4Connection();
Book::setConnection($connection);
$book = new Book();
$book->title = 'War and peace';
$book->author = 'Tolstoi';
$this->assertTrue($book->isNew());
$this->assertFalse($book->isDeleted());
$book->save();
$this->assertFalse($book->isNew());
$this->assertTrue($book->wasNew());
$this->assertFalse($book->isDeleted());
$this->assertEquals(1, $book->getPk());
$book1 = Book::findByPK(1);
$this->assertEquals(1, $book1->getPk());
$this->assertEquals('War and peace', $book1->title);
$this->assertEquals('Tolstoi', $book1->author);
$book->delete();
$this->assertFalse($book->isNew());
$this->assertTrue($book->wasNew());
$this->assertTrue($book->isDeleted());
$count = $connection->query("SELECT COUNT(*) FROM `books`")->fetchScalar();
$this->assertEquals(0, $count);
}
示例8: doSave
/**
* Performs the work of inserting or updating the row in the database.
*
* If the object is new, it inserts it; otherwise an update is performed.
* All related objects are also updated in this method.
*
* @param PropelPDO $con
* @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
* @throws PropelException
* @see save()
*/
protected function doSave(PropelPDO $con)
{
$affectedRows = 0;
// initialize var to track total num of affected rows
if (!$this->alreadyInSave) {
$this->alreadyInSave = true;
// We call the save method on the following object(s) if they
// were passed to this object by their coresponding set
// method. This object relates to these object(s) by a
// foreign key reference.
if ($this->aBook !== null) {
if ($this->aBook->isModified() || $this->aBook->isNew()) {
$affectedRows += $this->aBook->save($con);
}
$this->setBook($this->aBook);
}
if ($this->aItemRelatedByPackageId !== null) {
if ($this->aItemRelatedByPackageId->isModified() || $this->aItemRelatedByPackageId->isNew()) {
$affectedRows += $this->aItemRelatedByPackageId->save($con);
}
$this->setItemRelatedByPackageId($this->aItemRelatedByPackageId);
}
if ($this->isNew() || $this->isModified()) {
// persist changes
if ($this->isNew()) {
$this->doInsert($con);
} else {
$this->doUpdate($con);
}
$affectedRows += 1;
$this->resetModified();
}
if ($this->sectionsScheduledForDeletion !== null) {
if (!$this->sectionsScheduledForDeletion->isEmpty()) {
SectionHasItemQuery::create()->filterByPrimaryKeys($this->sectionsScheduledForDeletion->getPrimaryKeys(false))->delete($con);
$this->sectionsScheduledForDeletion = null;
}
foreach ($this->getSections() as $section) {
if ($section->isModified()) {
$section->save($con);
}
}
}
if ($this->itemsRelatedByIdScheduledForDeletion !== null) {
if (!$this->itemsRelatedByIdScheduledForDeletion->isEmpty()) {
ItemQuery::create()->filterByPrimaryKeys($this->itemsRelatedByIdScheduledForDeletion->getPrimaryKeys(false))->delete($con);
$this->itemsRelatedByIdScheduledForDeletion = null;
}
}
if ($this->collItemsRelatedById !== null) {
foreach ($this->collItemsRelatedById as $referrerFK) {
if (!$referrerFK->isDeleted()) {
$affectedRows += $referrerFK->save($con);
}
}
}
if ($this->sectionHasItemsScheduledForDeletion !== null) {
if (!$this->sectionHasItemsScheduledForDeletion->isEmpty()) {
SectionHasItemQuery::create()->filterByPrimaryKeys($this->sectionHasItemsScheduledForDeletion->getPrimaryKeys(false))->delete($con);
$this->sectionHasItemsScheduledForDeletion = null;
}
}
if ($this->collSectionHasItems !== null) {
foreach ($this->collSectionHasItems as $referrerFK) {
if (!$referrerFK->isDeleted()) {
$affectedRows += $referrerFK->save($con);
}
}
}
$this->alreadyInSave = false;
}
return $affectedRows;
}