1
0
mirror of https://github.com/Rogiel/predb synced 2025-12-05 23:22:48 +00:00

Implements pagination

This commit is contained in:
2014-11-23 15:48:37 -02:00
parent 68cf6fc064
commit d8a338d345
4 changed files with 35 additions and 25 deletions

View File

@@ -1,4 +1,5 @@
<?php
/*
* Copyright (c) 2014, Rogiel Sulzbach <rogiel@rogiel.com>
* All rights reserved.
@@ -28,12 +29,11 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
namespace PreDB\Adapter;
/**
* The pre adapter interface
*
*
* @author <a href="http://www.rogiel.com/">Rogiel</a>
* @since 1.0
*/
@@ -41,13 +41,18 @@ interface Adapter {
/**
* Implements the underlying search method
*
* @param string $release
*
* @param string $release
* @param int $page
* the page to return
*/
function search($release);
function search($release, $page = 1);
/**
* Implements the underlying latest method
*
* @param int $page
* the page to load
*/
function latest();
function latest($page = 1);
}

View File

@@ -32,10 +32,8 @@
namespace PreDB\Adapter;
use PreDB\Release;
use DOMDocument;
use DOMXPath;
use DateTime;
use DateTimeZone;
@@ -48,13 +46,13 @@ use DateTimeZone;
*/
class OrlyDB implements Adapter {
public function latest() {
$html = file_get_contents("http://orlydb.com/1");
public function latest($page = 1) {
$html = file_get_contents("http://orlydb.com/" . $page);
return $this->parseList($html);
}
public function search($release) {
$html = file_get_contents("http://orlydb.com/?q=" . urlencode($release));
public function search($release, $page = 1) {
$html = file_get_contents("http://orlydb.com/{$page}?q=" . urlencode($release));
return $this->parseList($html);
}

View File

@@ -1,4 +1,5 @@
<?php
/*
* Copyright (c) 2014, Rogiel Sulzbach <rogiel@rogiel.com>
* All rights reserved.
@@ -28,7 +29,6 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
namespace PreDB;
use PreDB\Adapter\Adapter;
@@ -41,33 +41,35 @@ class PreDB {
* @var Adapter
*/
private $adapter;
/**
* Creates a new instance
*
* @param Adapter $adapter
* the adapter to use. If none is provided an default is used.
*/
public function __construct($adapter = null) {
public function __construct(Adapter $adapter = null) {
if ($adapter == null) {
$adapter = new \PreDB\Adapter\OrlyDB();
}
$this->adapter = $adapter;
}
/**
* Searches the pre database for certain releases
*
* @param
* string, SearchHelper $query the query
* @param string|SearchHelper $query
* the query
* @param int $page
* the page to return
*/
public function search($query) {
public function search($query, $page = 1) {
if ($query instanceof SearchHelper) {
$query = $query->getSearchQuery();
}
return $this->adapter->search($query);
return $this->adapter->search($query, $page);
}
/**
* Searches the pre database for an certain release
*
@@ -79,11 +81,14 @@ class PreDB {
$releases = $this->adapter->search($release);
return predb_find_suitable_release($release, $releases);
}
/**
* Retrieve the latest pre entries from the database
*
* @param int $page
* the page to load
*/
public function latest() {
return $this->adapter->latest();
public function latest($page = 1) {
return $this->adapter->latest($page);
}
}