added pagination to claims explorer
This commit is contained in:
parent
4557e395fe
commit
f70f41c787
2 changed files with 38 additions and 3 deletions
|
@ -118,7 +118,26 @@ class MainController extends AppController {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$id) {
|
if (!$id) {
|
||||||
$claims = $this->Claims->find()->contain(['Stream', 'Publisher' => ['fields' => ['Name']]])->order(['Claims.Created' => 'DESC'])->limit(96)->toArray();
|
// paginate claims
|
||||||
|
$offset = 0;
|
||||||
|
$pageLimit = 96;
|
||||||
|
$page = intval($this->request->query('page'));
|
||||||
|
|
||||||
|
$conn = ConnectionManager::get('default');
|
||||||
|
$stmt = $conn->execute('SELECT COUNT(Id) AS Total FROM Claims');
|
||||||
|
$count = $stmt->fetch(\PDO::FETCH_OBJ);
|
||||||
|
$numClaims = $count->Total;
|
||||||
|
|
||||||
|
$numPages = ceil($numClaims / $pageLimit);
|
||||||
|
if ($page < 1) {
|
||||||
|
$page = 1;
|
||||||
|
}
|
||||||
|
if ($page > $numPages) {
|
||||||
|
$page = $numPages;
|
||||||
|
}
|
||||||
|
|
||||||
|
$offset = ($page - 1) * $pageLimit;
|
||||||
|
$claims = $this->Claims->find()->contain(['Stream', 'Publisher' => ['fields' => ['Name']]])->order(['Claims.Created' => 'DESC'])->offset($offset)->limit($pageLimit)->toArray();
|
||||||
for ($i = 0; $i < count($claims); $i++) {
|
for ($i = 0; $i < count($claims); $i++) {
|
||||||
if ($canConvert && $claims[$i]->Fee > 0 && $claims[$i]->FeeCurrency == 'USD') {
|
if ($canConvert && $claims[$i]->Fee > 0 && $claims[$i]->FeeCurrency == 'USD') {
|
||||||
$claims[$i]->Price = $claims[$i]->Fee / $priceInfo->price;
|
$claims[$i]->Price = $claims[$i]->Fee / $priceInfo->price;
|
||||||
|
@ -134,6 +153,11 @@ class MainController extends AppController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->set('pageLimit', $pageLimit);
|
||||||
|
$this->set('numPages', $numPages);
|
||||||
|
$this->set('numRecords', $numClaims);
|
||||||
|
$this->set('currentPage', $page);
|
||||||
$this->set('claims', $claims);
|
$this->set('claims', $claims);
|
||||||
} else {
|
} else {
|
||||||
$claim = $this->Claims->find()->contain(['Stream', 'Publisher' => ['fields' => ['ClaimId', 'Name']]])->where(['Claims.ClaimId' => $id])->first();
|
$claim = $this->Claims->find()->contain(['Stream', 'Publisher' => ['fields' => ['ClaimId', 'Name']]])->where(['Claims.ClaimId' => $id])->first();
|
||||||
|
|
|
@ -273,8 +273,17 @@ if (strlen(trim($desc)) == 0) {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="claims-grid">
|
<div class="claims-grid">
|
||||||
<?php $idx = 1; $a = ['purple', 'orange', 'blue', 'teal', 'green', 'yellow']; foreach ($claims as $claim):
|
<?php
|
||||||
$last_row = (count($claims) - $idx < 3);
|
|
||||||
|
$idx = 1;
|
||||||
|
$row = 1;
|
||||||
|
$rowCount = ceil(count($claims) / 3);
|
||||||
|
$a = ['purple', 'orange', 'blue', 'teal', 'green', 'yellow'];
|
||||||
|
foreach ($claims as $claim):
|
||||||
|
$last_row = ($row == $rowCount);
|
||||||
|
if ($idx % 3 == 0) {
|
||||||
|
$row++;
|
||||||
|
}
|
||||||
$autoThumbText = '';
|
$autoThumbText = '';
|
||||||
$link = $claim->Name;
|
$link = $claim->Name;
|
||||||
if (isset($claim->Publisher->Name)) {
|
if (isset($claim->Publisher->Name)) {
|
||||||
|
@ -373,4 +382,6 @@ if (strlen(trim($desc)) == 0) {
|
||||||
<div class="clear"></div>
|
<div class="clear"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<?php echo $this->element('pagination') ?>
|
||||||
|
|
||||||
<?php endif ?>
|
<?php endif ?>
|
Loading…
Reference in a new issue