mirror of
https://github.com/Rogiel/predb
synced 2025-12-06 07:32:47 +00:00
Implements pagination
This commit is contained in:
@@ -37,6 +37,8 @@ use PreDB\PreDB;
|
|||||||
|
|
||||||
// This example does a simple search for an pre release
|
// This example does a simple search for an pre release
|
||||||
$db = new PreDB();
|
$db = new PreDB();
|
||||||
print_r($db->search("Microsoft Windows"));
|
|
||||||
|
$result = $db->search("Microsoft Windows");
|
||||||
|
var_dump($result);
|
||||||
|
|
||||||
?>
|
?>
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, Rogiel Sulzbach <rogiel@rogiel.com>
|
* Copyright (c) 2014, Rogiel Sulzbach <rogiel@rogiel.com>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
@@ -28,7 +29,6 @@
|
|||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace PreDB\Adapter;
|
namespace PreDB\Adapter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,11 +43,16 @@ interface Adapter {
|
|||||||
* Implements the underlying search method
|
* 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
|
* Implements the underlying latest method
|
||||||
|
*
|
||||||
|
* @param int $page
|
||||||
|
* the page to load
|
||||||
*/
|
*/
|
||||||
function latest();
|
function latest($page = 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,10 +32,8 @@
|
|||||||
namespace PreDB\Adapter;
|
namespace PreDB\Adapter;
|
||||||
|
|
||||||
use PreDB\Release;
|
use PreDB\Release;
|
||||||
|
|
||||||
use DOMDocument;
|
use DOMDocument;
|
||||||
use DOMXPath;
|
use DOMXPath;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use DateTimeZone;
|
use DateTimeZone;
|
||||||
|
|
||||||
@@ -48,13 +46,13 @@ use DateTimeZone;
|
|||||||
*/
|
*/
|
||||||
class OrlyDB implements Adapter {
|
class OrlyDB implements Adapter {
|
||||||
|
|
||||||
public function latest() {
|
public function latest($page = 1) {
|
||||||
$html = file_get_contents("http://orlydb.com/1");
|
$html = file_get_contents("http://orlydb.com/" . $page);
|
||||||
return $this->parseList($html);
|
return $this->parseList($html);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function search($release) {
|
public function search($release, $page = 1) {
|
||||||
$html = file_get_contents("http://orlydb.com/?q=" . urlencode($release));
|
$html = file_get_contents("http://orlydb.com/{$page}?q=" . urlencode($release));
|
||||||
return $this->parseList($html);
|
return $this->parseList($html);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, Rogiel Sulzbach <rogiel@rogiel.com>
|
* Copyright (c) 2014, Rogiel Sulzbach <rogiel@rogiel.com>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
@@ -28,7 +29,6 @@
|
|||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace PreDB;
|
namespace PreDB;
|
||||||
|
|
||||||
use PreDB\Adapter\Adapter;
|
use PreDB\Adapter\Adapter;
|
||||||
@@ -48,7 +48,7 @@ class PreDB {
|
|||||||
* @param Adapter $adapter
|
* @param Adapter $adapter
|
||||||
* the adapter to use. If none is provided an default is used.
|
* 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) {
|
if ($adapter == null) {
|
||||||
$adapter = new \PreDB\Adapter\OrlyDB();
|
$adapter = new \PreDB\Adapter\OrlyDB();
|
||||||
}
|
}
|
||||||
@@ -58,14 +58,16 @@ class PreDB {
|
|||||||
/**
|
/**
|
||||||
* Searches the pre database for certain releases
|
* Searches the pre database for certain releases
|
||||||
*
|
*
|
||||||
* @param
|
* @param string|SearchHelper $query
|
||||||
* string, SearchHelper $query the query
|
* the query
|
||||||
|
* @param int $page
|
||||||
|
* the page to return
|
||||||
*/
|
*/
|
||||||
public function search($query) {
|
public function search($query, $page = 1) {
|
||||||
if ($query instanceof SearchHelper) {
|
if ($query instanceof SearchHelper) {
|
||||||
$query = $query->getSearchQuery();
|
$query = $query->getSearchQuery();
|
||||||
}
|
}
|
||||||
return $this->adapter->search($query);
|
return $this->adapter->search($query, $page);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -82,8 +84,11 @@ class PreDB {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the latest pre entries from the database
|
* Retrieve the latest pre entries from the database
|
||||||
|
*
|
||||||
|
* @param int $page
|
||||||
|
* the page to load
|
||||||
*/
|
*/
|
||||||
public function latest() {
|
public function latest($page = 1) {
|
||||||
return $this->adapter->latest();
|
return $this->adapter->latest($page);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user