Add series

This commit is contained in:
Didier Corbière 2013-09-17 01:08:23 +01:00
parent 7bb5144337
commit e6de4593be
3 changed files with 75 additions and 20 deletions

View file

@ -81,6 +81,8 @@ class BookExport
$this->mExport->SetProperty($i++, 'Isbn');
$this->mExport->SetProperty($i++, 'Rights');
$this->mExport->SetProperty($i++, 'Publisher');
$this->mExport->SetProperty($i++, 'Serie');
$this->mExport->SetProperty($i++, 'SerieIndex');
$this->mExport->AddContent();
}
@ -101,6 +103,8 @@ class BookExport
$this->mExport->SetProperty($i++, $inBookInfo->mIsbn);
$this->mExport->SetProperty($i++, $inBookInfo->mRights);
$this->mExport->SetProperty($i++, $inBookInfo->mPublisher);
$this->mExport->SetProperty($i++, $inBookInfo->mSerie);
$this->mExport->SetProperty($i++, $inBookInfo->mSerieIndex);
$this->mExport->AddContent();
}

View file

@ -29,6 +29,8 @@ class BookInfos
public $mIsbn = '';
public $mRights = '';
public $mPublisher = '';
public $mSerie = '';
public $mSerieIndex = '';
/**
* Loads book infos from an epub file
@ -41,23 +43,26 @@ class BookInfos
public function LoadFromEpub($inFileName)
{
// Load the epub file
$epub = new EPub($inFileName, 'ZipFile');
$ePub = new EPub($inFileName, 'ZipFile');
// Get the epub infos
$this->mFormat = 'epub';
$this->mPath = pathinfo($inFileName, PATHINFO_DIRNAME);
$this->mName = pathinfo($inFileName, PATHINFO_FILENAME);
$this->mUuid = $epub->Uuid();
$this->mUri = $epub->Uri();
$this->mTitle = $epub->Title();
$this->mAuthors = $epub->Authors();
$this->mLanguage = $epub->Language();
$this->mDescription = $epub->Description();
$this->mSubjects = $epub->Subjects();
$this->mCover = $epub->getCoverItem();
$this->mIsbn = $epub->ISBN();
$this->mRights = $epub->Copyright();
$this->mPublisher = $epub->Publisher();
$this->mUuid = $ePub->Uuid();
$this->mUri = $ePub->Uri();
$this->mTitle = $ePub->Title();
$this->mAuthors = $ePub->Authors();
$this->mLanguage = $ePub->Language();
$this->mDescription = $ePub->Description();
$this->mSubjects = $ePub->Subjects();
$cover = $ePub->Cover();
$this->mCover = ($cover['found'] !== false) ? $cover['found'] : '';
$this->mIsbn = $ePub->ISBN();
$this->mRights = $ePub->Copyright();
$this->mPublisher = $ePub->Publisher();
$this->mSerie = $ePub->Serie();
$this->mSerieIndex = $ePub->SerieIndex();
}
}

View file

@ -141,10 +141,11 @@ class CalibreDbLoader
*/
private function AddBook($inBookInfo)
{
$sql = 'insert into books(title, sort, uuid, path) values(:title, :sort, :uuid, :path)';
$sql = 'insert into books(title, sort, series_index, uuid, path) values(:title, :sort, :serieindex, :uuid, :path)';
$stmt = $this->mDb->prepare($sql);
$stmt->bindParam(':title', $inBookInfo->mTitle);
$stmt->bindParam(':sort', $inBookInfo->mTitle);
$stmt->bindParam(':serieindex', $inBookInfo->mSerieIndex);
$stmt->bindParam(':uuid', $inBookInfo->mUuid);
$stmt->bindParam(':path', $inBookInfo->mPath);
$stmt->execute();
@ -184,7 +185,52 @@ class CalibreDbLoader
$stmt->bindParam(':value', $inBookInfo->mUri);
$stmt->execute();
}
// Add the authors in the db
// Add the book serie
if (!empty($inBookInfo->mSerie)) {
// Get the serie id
$sql = 'select id from series where name=:serie';
$stmt = $this->mDb->prepare($sql);
$stmt->bindParam(':serie', $inBookInfo->mSerie);
$stmt->execute();
$post = $stmt->fetchObject();
if ($post) {
$idSerie = $post->id;
}
else {
// Add a new serie
$sql = 'insert into series(name, sort) values(:serie, :sort)';
$stmt = $this->mDb->prepare($sql);
$stmt->bindParam(':serie', $inBookInfo->mSerie);
$stmt->bindParam(':sort', $inBookInfo->mSerie);
$stmt->execute();
// Get the serie id
$sql = 'select id from series where name=:serie';
$stmt = $this->mDb->prepare($sql);
$stmt->bindParam(':serie', $inBookInfo->mSerie);
$stmt->execute();
$idSerie = null;
while ($post = $stmt->fetchObject()) {
if (!isset($idSerie)) {
$idSerie = $post->id;
}
else {
$error = sprintf('Multiple series for name: %s', $inBookInfo->mSerie);
throw new Exception($error);
}
}
if (!isset($idSerie)) {
$error = sprintf('Cannot find serie id for name: %s', $inBookInfo->mSerie);
throw new Exception($error);
}
}
// Add the book serie link
$sql = 'insert into books_series_link(book, series) values(:idBook, :idSerie)';
$stmt = $this->mDb->prepare($sql);
$stmt->bindParam(':idBook', $idBook, PDO::PARAM_INT);
$stmt->bindParam(':idSerie', $idSerie, PDO::PARAM_INT);
$stmt->execute();
}
// Add the book authors
foreach ($inBookInfo->mAuthors as $authorSort => $author) {
// Get the author id
$sql = 'select id from authors where name=:author';
@ -221,13 +267,13 @@ class CalibreDbLoader
$error = sprintf('Cannot find author id for name: %s', $author);
throw new Exception($error);
}
// Add the book author link
$sql = 'insert into books_authors_link(book, author) values(:idBook, :idAuthor)';
$stmt = $this->mDb->prepare($sql);
$stmt->bindParam(':idBook', $idBook, PDO::PARAM_INT);
$stmt->bindParam(':idAuthor', $idAuthor, PDO::PARAM_INT);
$stmt->execute();
}
// Add the book author link
$sql = 'insert into books_authors_link(book, author) values(:idBook, :idAuthor)';
$stmt = $this->mDb->prepare($sql);
$stmt->bindParam(':idBook', $idBook, PDO::PARAM_INT);
$stmt->bindParam(':idAuthor', $idAuthor, PDO::PARAM_INT);
$stmt->execute();
}
}