Continue the refactoring
This commit is contained in:
parent
654eddebc6
commit
82d535d02c
8
base.php
8
base.php
|
@ -261,7 +261,7 @@ class PageAuthorDetail extends Page
|
|||
$author = Author::getAuthorById ($this->idGet);
|
||||
$this->idPage = $author->getEntryId ();
|
||||
$this->title = $author->name;
|
||||
$this->entryArray = Book::getBooksByAuthor ($this->idGet);
|
||||
list ($this->entryArray, $this->totalNumber) = Book::getBooksByAuthor ($this->idGet, $this->n);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -282,7 +282,7 @@ class PageTagDetail extends Page
|
|||
$tag = Tag::getTagById ($this->idGet);
|
||||
$this->idPage = $tag->getEntryId ();
|
||||
$this->title = $tag->name;
|
||||
$this->entryArray = Book::getBooksByTag ($this->idGet);
|
||||
list ($this->entryArray, $this->totalNumber) = Book::getBooksByTag ($this->idGet, $this->n);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -302,7 +302,7 @@ class PageSerieDetail extends Page
|
|||
{
|
||||
$serie = Serie::getSerieById ($this->idGet);
|
||||
$this->title = $serie->name;
|
||||
$this->entryArray = Book::getBooksBySeries ($this->idGet);
|
||||
list ($this->entryArray, $this->totalNumber) = Book::getBooksBySeries ($this->idGet, $this->n);
|
||||
$this->idPage = $serie->getEntryId ();
|
||||
}
|
||||
}
|
||||
|
@ -342,7 +342,7 @@ class PageQueryResult extends Page
|
|||
public function InitializeContent ()
|
||||
{
|
||||
$this->title = "Search result for query *" . $this->query . "*"; // TODO I18N
|
||||
$this->entryArray = Book::getBooksByQuery ($this->query);
|
||||
list ($this->entryArray, $this->totalNumber) = Book::getBooksByQuery ($this->query, $this->n);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
66
book.php
66
book.php
|
@ -19,6 +19,10 @@ class Book extends Base {
|
|||
const BOOK_COLUMNS = "books.id as id, books.title as title, text as comment, path, timestamp, pubdate, series_index, uuid, has_cover";
|
||||
|
||||
const SQL_BOOKS_BY_FIRST_LETTER = "select {0} from books left outer join comments on book = books.id where upper (books.sort) like ?";
|
||||
const SQL_BOOKS_BY_AUTHOR = "select {0} from books_authors_link, books left outer join comments on comments.book = books.id where books_authors_link.book = books.id and author = ? order by pubdate";
|
||||
const SQL_BOOKS_BY_SERIE = "select {0} from books_series_link, books left outer join comments on comments.book = books.id where books_series_link.book = books.id and series = ? order by series_index";
|
||||
const SQL_BOOKS_BY_TAG = "select {0} from books_tags_link, books left outer join comments on comments.book = books.id where books_tags_link.book = books.id and tag = ? order by sort";
|
||||
const SQL_BOOKS_QUERY = "select {0} from books left outer join comments on book = books.id where exists (select null from authors, books_authors_link where book = books.id and author = authors.id and authors.name like ?) or title like ?";
|
||||
|
||||
public $id;
|
||||
public $title;
|
||||
|
@ -259,51 +263,17 @@ class Book extends Base {
|
|||
return $result;
|
||||
}
|
||||
|
||||
public static function getBooksByAuthor($authorId) {
|
||||
$result = parent::getDb ()->prepare('select ' . self::BOOK_COLUMNS . '
|
||||
from books_authors_link, books left outer join comments on comments.book = books.id
|
||||
where books_authors_link.book = books.id
|
||||
and author = ?
|
||||
order by pubdate');
|
||||
$entryArray = array();
|
||||
$result->execute (array ($authorId));
|
||||
while ($post = $result->fetchObject ())
|
||||
{
|
||||
$book = new Book ($post);
|
||||
array_push ($entryArray, $book->getEntry ());
|
||||
}
|
||||
return $entryArray;
|
||||
public static function getBooksByAuthor($authorId, $n) {
|
||||
return self::getEntryArray (self::SQL_BOOKS_BY_AUTHOR, array ($authorId), $n);
|
||||
}
|
||||
|
||||
|
||||
public static function getBooksBySeries($serieId) {
|
||||
$result = parent::getDb ()->prepare('select ' . self::BOOK_COLUMNS . '
|
||||
from books_series_link, books left outer join comments on comments.book = books.id
|
||||
where books_series_link.book = books.id and series = ?
|
||||
order by series_index');
|
||||
$entryArray = array();
|
||||
$result->execute (array ($serieId));
|
||||
while ($post = $result->fetchObject ())
|
||||
{
|
||||
$book = new Book ($post);
|
||||
array_push ($entryArray, $book->getEntry ());
|
||||
}
|
||||
return $entryArray;
|
||||
public static function getBooksBySeries($serieId, $n) {
|
||||
return self::getEntryArray (self::SQL_BOOKS_BY_SERIE, array ($serieId), $n);
|
||||
}
|
||||
|
||||
public static function getBooksByTag($tagId) {
|
||||
$result = parent::getDb ()->prepare('select ' . self::BOOK_COLUMNS . '
|
||||
from books_tags_link, books left outer join comments on comments.book = books.id
|
||||
where books_tags_link.book = books.id and tag = ?
|
||||
order by sort');
|
||||
$entryArray = array();
|
||||
$result->execute (array ($tagId));
|
||||
while ($post = $result->fetchObject ())
|
||||
{
|
||||
$book = new Book ($post);
|
||||
array_push ($entryArray, $book->getEntry ());
|
||||
}
|
||||
return $entryArray;
|
||||
public static function getBooksByTag($tagId, $n) {
|
||||
return self::getEntryArray (self::SQL_BOOKS_BY_TAG, array ($tagId), $n);
|
||||
}
|
||||
|
||||
public static function getBookById($bookId) {
|
||||
|
@ -334,20 +304,8 @@ where data.book = books.id and data.id = ?');
|
|||
return NULL;
|
||||
}
|
||||
|
||||
public static function getBooksByQuery($query) {
|
||||
$result = parent::getDb ()->prepare("select " . self::BOOK_COLUMNS . "
|
||||
from books left outer join comments on book = books.id
|
||||
where exists (select null from authors, books_authors_link where book = books.id and author = authors.id and authors.name like ?)
|
||||
or title like ?");
|
||||
$entryArray = array();
|
||||
$queryLike = "%" . $query . "%";
|
||||
$result->execute (array ($queryLike, $queryLike));
|
||||
while ($post = $result->fetchObject ())
|
||||
{
|
||||
$book = new Book ($post);
|
||||
array_push ($entryArray, $book->getEntry ());
|
||||
}
|
||||
return $entryArray;
|
||||
public static function getBooksByQuery($query, $n) {
|
||||
return self::getEntryArray (self::SQL_BOOKS_QUERY, array ("%" . $query . "%", "%" . $query . "%"), $n);
|
||||
}
|
||||
|
||||
public static function getAllBooks() {
|
||||
|
|
Loading…
Reference in a new issue