Add series
This commit is contained in:
parent
7bb5144337
commit
e6de4593be
|
@ -81,6 +81,8 @@ class BookExport
|
||||||
$this->mExport->SetProperty($i++, 'Isbn');
|
$this->mExport->SetProperty($i++, 'Isbn');
|
||||||
$this->mExport->SetProperty($i++, 'Rights');
|
$this->mExport->SetProperty($i++, 'Rights');
|
||||||
$this->mExport->SetProperty($i++, 'Publisher');
|
$this->mExport->SetProperty($i++, 'Publisher');
|
||||||
|
$this->mExport->SetProperty($i++, 'Serie');
|
||||||
|
$this->mExport->SetProperty($i++, 'SerieIndex');
|
||||||
$this->mExport->AddContent();
|
$this->mExport->AddContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,6 +103,8 @@ class BookExport
|
||||||
$this->mExport->SetProperty($i++, $inBookInfo->mIsbn);
|
$this->mExport->SetProperty($i++, $inBookInfo->mIsbn);
|
||||||
$this->mExport->SetProperty($i++, $inBookInfo->mRights);
|
$this->mExport->SetProperty($i++, $inBookInfo->mRights);
|
||||||
$this->mExport->SetProperty($i++, $inBookInfo->mPublisher);
|
$this->mExport->SetProperty($i++, $inBookInfo->mPublisher);
|
||||||
|
$this->mExport->SetProperty($i++, $inBookInfo->mSerie);
|
||||||
|
$this->mExport->SetProperty($i++, $inBookInfo->mSerieIndex);
|
||||||
|
|
||||||
$this->mExport->AddContent();
|
$this->mExport->AddContent();
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,8 @@ class BookInfos
|
||||||
public $mIsbn = '';
|
public $mIsbn = '';
|
||||||
public $mRights = '';
|
public $mRights = '';
|
||||||
public $mPublisher = '';
|
public $mPublisher = '';
|
||||||
|
public $mSerie = '';
|
||||||
|
public $mSerieIndex = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads book infos from an epub file
|
* Loads book infos from an epub file
|
||||||
|
@ -41,23 +43,26 @@ class BookInfos
|
||||||
public function LoadFromEpub($inFileName)
|
public function LoadFromEpub($inFileName)
|
||||||
{
|
{
|
||||||
// Load the epub file
|
// Load the epub file
|
||||||
$epub = new EPub($inFileName, 'ZipFile');
|
$ePub = new EPub($inFileName, 'ZipFile');
|
||||||
|
|
||||||
// Get the epub infos
|
// Get the epub infos
|
||||||
$this->mFormat = 'epub';
|
$this->mFormat = 'epub';
|
||||||
$this->mPath = pathinfo($inFileName, PATHINFO_DIRNAME);
|
$this->mPath = pathinfo($inFileName, PATHINFO_DIRNAME);
|
||||||
$this->mName = pathinfo($inFileName, PATHINFO_FILENAME);
|
$this->mName = pathinfo($inFileName, PATHINFO_FILENAME);
|
||||||
$this->mUuid = $epub->Uuid();
|
$this->mUuid = $ePub->Uuid();
|
||||||
$this->mUri = $epub->Uri();
|
$this->mUri = $ePub->Uri();
|
||||||
$this->mTitle = $epub->Title();
|
$this->mTitle = $ePub->Title();
|
||||||
$this->mAuthors = $epub->Authors();
|
$this->mAuthors = $ePub->Authors();
|
||||||
$this->mLanguage = $epub->Language();
|
$this->mLanguage = $ePub->Language();
|
||||||
$this->mDescription = $epub->Description();
|
$this->mDescription = $ePub->Description();
|
||||||
$this->mSubjects = $epub->Subjects();
|
$this->mSubjects = $ePub->Subjects();
|
||||||
$this->mCover = $epub->getCoverItem();
|
$cover = $ePub->Cover();
|
||||||
$this->mIsbn = $epub->ISBN();
|
$this->mCover = ($cover['found'] !== false) ? $cover['found'] : '';
|
||||||
$this->mRights = $epub->Copyright();
|
$this->mIsbn = $ePub->ISBN();
|
||||||
$this->mPublisher = $epub->Publisher();
|
$this->mRights = $ePub->Copyright();
|
||||||
|
$this->mPublisher = $ePub->Publisher();
|
||||||
|
$this->mSerie = $ePub->Serie();
|
||||||
|
$this->mSerieIndex = $ePub->SerieIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,10 +141,11 @@ class CalibreDbLoader
|
||||||
*/
|
*/
|
||||||
private function AddBook($inBookInfo)
|
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 = $this->mDb->prepare($sql);
|
||||||
$stmt->bindParam(':title', $inBookInfo->mTitle);
|
$stmt->bindParam(':title', $inBookInfo->mTitle);
|
||||||
$stmt->bindParam(':sort', $inBookInfo->mTitle);
|
$stmt->bindParam(':sort', $inBookInfo->mTitle);
|
||||||
|
$stmt->bindParam(':serieindex', $inBookInfo->mSerieIndex);
|
||||||
$stmt->bindParam(':uuid', $inBookInfo->mUuid);
|
$stmt->bindParam(':uuid', $inBookInfo->mUuid);
|
||||||
$stmt->bindParam(':path', $inBookInfo->mPath);
|
$stmt->bindParam(':path', $inBookInfo->mPath);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
|
@ -184,7 +185,52 @@ class CalibreDbLoader
|
||||||
$stmt->bindParam(':value', $inBookInfo->mUri);
|
$stmt->bindParam(':value', $inBookInfo->mUri);
|
||||||
$stmt->execute();
|
$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) {
|
foreach ($inBookInfo->mAuthors as $authorSort => $author) {
|
||||||
// Get the author id
|
// Get the author id
|
||||||
$sql = 'select id from authors where name=:author';
|
$sql = 'select id from authors where name=:author';
|
||||||
|
@ -221,6 +267,7 @@ class CalibreDbLoader
|
||||||
$error = sprintf('Cannot find author id for name: %s', $author);
|
$error = sprintf('Cannot find author id for name: %s', $author);
|
||||||
throw new Exception($error);
|
throw new Exception($error);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Add the book author link
|
// Add the book author link
|
||||||
$sql = 'insert into books_authors_link(book, author) values(:idBook, :idAuthor)';
|
$sql = 'insert into books_authors_link(book, author) values(:idBook, :idAuthor)';
|
||||||
$stmt = $this->mDb->prepare($sql);
|
$stmt = $this->mDb->prepare($sql);
|
||||||
|
@ -229,7 +276,6 @@ class CalibreDbLoader
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check database for debug
|
* Check database for debug
|
||||||
|
|
Loading…
Reference in a new issue