Skip to content

Commit

Permalink
Iterate through issue pages with pager-next to find total page count
Browse files Browse the repository at this point in the history
pager-last no longer exists on issue pages, so we need to scan every page to
find the end
  • Loading branch information
gapple committed Nov 24, 2013
1 parent 32a23f2 commit 3c90c66
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/DrupalReleaseDate/DrupalIssueCount.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,17 +227,20 @@ public function getCount(\Guzzle\Http\Message\RequestInterface $request, $viewCl

$document = $this->getXmlDocument($request->send());

// Check if pager exists on first page; get page count from link to last page.
// Check if pager exists on first page; get the next page until we're at
// the end to find the total number of pages.
$fullPages = 0;
$pagerLast = $document->xpath("//_xmlns:div[contains(concat(' ', @class, ' '), ' {$viewClass} ')]//_xmlns:li[contains(concat(' ', @class, ' '), ' pager-last ')]//_xmlns:a");
$pagerNext = $document->xpath("//_xmlns:div[contains(concat(' ', @class, ' '), ' {$viewClass} ')]//_xmlns:li[contains(concat(' ', @class, ' '), ' pager-next ')]//_xmlns:a");

if ($pagerLast) {
$pagerLastUrl = (string) $pagerLast[0]['href'];
preg_match('/page=(\\d+)/', $pagerLastUrl, $urlMatches);
while ($pagerNext) {
$pagerNextUrl = (string) $pagerNext[0]['href'];
preg_match('/page=(\\d+)/', $pagerNextUrl, $urlMatches);

$fullPages = (int) $urlMatches[1];
$fullPages = (int) $urlMatches[1]; // Pager starts at 0,
$request->getQuery()->set('page', $fullPages);
$document = $this->getXmlDocument($request->send());

$pagerNext = $document->xpath("//_xmlns:div[contains(concat(' ', @class, ' '), ' {$viewClass} ')]//_xmlns:li[contains(concat(' ', @class, ' '), ' pager-next ')]//_xmlns:a");
}

$issueRows = $document->xpath("//_xmlns:div[contains(concat(' ', @class, ' '), ' {$viewClass} ')]//_xmlns:table[contains(concat(' ', @class, ' '), ' views-table ')]/_xmlns:tbody/_xmlns:tr");
Expand Down

0 comments on commit 3c90c66

Please sign in to comment.