Continue the refactoring

This commit is contained in:
Sébastien Lucas 2012-09-20 21:15:03 +02:00
parent 654eddebc6
commit 82d535d02c
2 changed files with 16 additions and 58 deletions

View file

@ -261,7 +261,7 @@ class PageAuthorDetail extends Page
$author = Author::getAuthorById ($this->idGet); $author = Author::getAuthorById ($this->idGet);
$this->idPage = $author->getEntryId (); $this->idPage = $author->getEntryId ();
$this->title = $author->name; $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); $tag = Tag::getTagById ($this->idGet);
$this->idPage = $tag->getEntryId (); $this->idPage = $tag->getEntryId ();
$this->title = $tag->name; $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); $serie = Serie::getSerieById ($this->idGet);
$this->title = $serie->name; $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 (); $this->idPage = $serie->getEntryId ();
} }
} }
@ -342,7 +342,7 @@ class PageQueryResult extends Page
public function InitializeContent () public function InitializeContent ()
{ {
$this->title = "Search result for query *" . $this->query . "*"; // TODO I18N $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);
} }
} }

View file

@ -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 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_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 $id;
public $title; public $title;
@ -259,51 +263,17 @@ class Book extends Base {
return $result; return $result;
} }
public static function getBooksByAuthor($authorId) { public static function getBooksByAuthor($authorId, $n) {
$result = parent::getDb ()->prepare('select ' . self::BOOK_COLUMNS . ' return self::getEntryArray (self::SQL_BOOKS_BY_AUTHOR, array ($authorId), $n);
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 getBooksBySeries($serieId) { public static function getBooksBySeries($serieId, $n) {
$result = parent::getDb ()->prepare('select ' . self::BOOK_COLUMNS . ' return self::getEntryArray (self::SQL_BOOKS_BY_SERIE, array ($serieId), $n);
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 getBooksByTag($tagId) { public static function getBooksByTag($tagId, $n) {
$result = parent::getDb ()->prepare('select ' . self::BOOK_COLUMNS . ' return self::getEntryArray (self::SQL_BOOKS_BY_TAG, array ($tagId), $n);
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 getBookById($bookId) { public static function getBookById($bookId) {
@ -334,20 +304,8 @@ where data.book = books.id and data.id = ?');
return NULL; return NULL;
} }
public static function getBooksByQuery($query) { public static function getBooksByQuery($query, $n) {
$result = parent::getDb ()->prepare("select " . self::BOOK_COLUMNS . " return self::getEntryArray (self::SQL_BOOKS_QUERY, array ("%" . $query . "%", "%" . $query . "%"), $n);
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 getAllBooks() { public static function getAllBooks() {