mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Fixed array/object mismatch bug in PaginatedList
This commit is contained in:
parent
c942ca5be6
commit
f952ef747b
@ -167,7 +167,7 @@ class HTTP
|
||||
* @param string $separator Separator for http_build_query().
|
||||
* @return string
|
||||
*/
|
||||
public static function setGetVar($varname, $varvalue, $currentURL = null, $separator = '&')
|
||||
public static function setGetVar($varname, $varvalue, $currentURL = null, $separator = '&')
|
||||
{
|
||||
if (!isset($currentURL)) {
|
||||
$request = Controller::curr()->getRequest();
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace SilverStripe\ORM;
|
||||
|
||||
use SilverStripe\Control\HTTP;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\ORM\Queries\SQLSelect;
|
||||
use SilverStripe\View\ArrayData;
|
||||
use ArrayAccess;
|
||||
@ -259,7 +260,11 @@ class PaginatedList extends ListDecorator
|
||||
for ($i = $start; $i < $end; $i++) {
|
||||
$result->push(new ArrayData(array(
|
||||
'PageNum' => $i + 1,
|
||||
'Link' => HTTP::setGetVar($this->getPaginationGetVar(), $i * $this->getPageLength()),
|
||||
'Link' => HTTP::setGetVar(
|
||||
$this->getPaginationGetVar(),
|
||||
$i * $this->getPageLength(),
|
||||
($this->request instanceof HTTPRequest) ? $this->request->getURL(true) : null
|
||||
),
|
||||
'CurrentBool' => $this->CurrentPage() == ($i + 1)
|
||||
)));
|
||||
}
|
||||
@ -330,7 +335,11 @@ class PaginatedList extends ListDecorator
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $total; $i++) {
|
||||
$link = HTTP::setGetVar($this->getPaginationGetVar(), $i * $this->getPageLength());
|
||||
$link = HTTP::setGetVar(
|
||||
$this->getPaginationGetVar(),
|
||||
$i * $this->getPageLength(),
|
||||
($this->request instanceof HTTPRequest) ? $this->request->getURL(true) : null
|
||||
);
|
||||
$num = $i + 1;
|
||||
|
||||
$emptyRange = $num != 1 && $num != $total && (
|
||||
@ -439,8 +448,7 @@ class PaginatedList extends ListDecorator
|
||||
return HTTP::setGetVar(
|
||||
$this->getPaginationGetVar(),
|
||||
0,
|
||||
$this->request ? $this->request->getURL(true) : null,
|
||||
'&'
|
||||
($this->request instanceof HTTPRequest) ? $this->request->getURL(true) : null
|
||||
);
|
||||
}
|
||||
|
||||
@ -454,8 +462,7 @@ class PaginatedList extends ListDecorator
|
||||
return HTTP::setGetVar(
|
||||
$this->getPaginationGetVar(),
|
||||
($this->TotalPages() - 1) * $this->getPageLength(),
|
||||
$this->request ? $this->request->getURL(true) : null,
|
||||
'&'
|
||||
($this->request instanceof HTTPRequest) ? $this->request->getURL(true) : null
|
||||
);
|
||||
}
|
||||
|
||||
@ -471,8 +478,7 @@ class PaginatedList extends ListDecorator
|
||||
return HTTP::setGetVar(
|
||||
$this->getPaginationGetVar(),
|
||||
$this->getPageStart() + $this->getPageLength(),
|
||||
$this->request ? $this->request->getURL(true) : null,
|
||||
'&'
|
||||
($this->request instanceof HTTPRequest) ? $this->request->getURL(true) : null
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -489,8 +495,7 @@ class PaginatedList extends ListDecorator
|
||||
return HTTP::setGetVar(
|
||||
$this->getPaginationGetVar(),
|
||||
$this->getPageStart() - $this->getPageLength(),
|
||||
$this->request ? $this->request->getURL(true) : null,
|
||||
'&'
|
||||
($this->request instanceof HTTPRequest) ? $this->request->getURL(true) : null
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -506,7 +511,7 @@ class PaginatedList extends ListDecorator
|
||||
/**
|
||||
* Set the request object for this list
|
||||
*
|
||||
* @param HTTPRequest
|
||||
* @param HTTPRequest|ArrayAccess
|
||||
*/
|
||||
public function setRequest($request)
|
||||
{
|
||||
|
@ -154,13 +154,13 @@ class HTTPTest extends FunctionalTest
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'relative/url?baz=buz&foo=bar',
|
||||
'relative/url?baz=buz&foo=bar',
|
||||
HTTP::setGetVar('foo', 'bar', '/relative/url?baz=buz'),
|
||||
'Relative URL with existing query params, and new added key'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'http://test.com/?foo=new&buz=baz',
|
||||
'http://test.com/?foo=new&buz=baz',
|
||||
HTTP::setGetVar('foo', 'new', 'http://test.com/?foo=old&buz=baz'),
|
||||
'Absolute URL without path and multipe existing query params, overwriting an existing parameter'
|
||||
);
|
||||
@ -172,7 +172,7 @@ class HTTPTest extends FunctionalTest
|
||||
);
|
||||
// http_build_query() escapes angular brackets, they should be correctly urldecoded by the browser client
|
||||
$this->assertEquals(
|
||||
'http://test.com/?foo%5Btest%5D=one&foo%5Btest%5D=two',
|
||||
'http://test.com/?foo%5Btest%5D=one&foo%5Btest%5D=two',
|
||||
HTTP::setGetVar('foo[test]', 'two', 'http://test.com/?foo[test]=one'),
|
||||
'Absolute URL and PHP array query string notation'
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user