Completed
Push — master ( a05403...d3048a )
by Simon
02:08
created

ShortListPaginationExtension::prevPage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
/*
3
 * @file ShortListPaginationExtension.php
4
 *
5
 * Provides Pagination for shortlist controller
6
 */
7
class ShortListPaginationExtension extends DataExtension {
1 ignored issue
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8
	/**
9
     * Get a paginated list of the shortlist items.
10
     *
11
     * @return mixed the paginated list of items, or false if the list cannot be found.
12
     * */
13
    public function paginatedItems()
14
    {
15
        if (!$this->owner->getRequest()->param('URL') || !ShortList::isBrowser()) {
16
            return false;
17
        }
18
19
        $items = false;
20
        $list = DataObject::get_one('ShortList', $filter = array('URL' => $this->owner->getRequest()->param('URL')));
21
22
        if ($list) {
23
            $items = $list->ShortListItems();
24
        }
25
26
        $this->owner->list = new PaginatedList($items, $this->owner->getRequest());
27
        $this->owner->list->setPageLength(Config::inst()->get('ShortList', 'PaginationCount'));
28
        $this->owner->list->setPaginationGetVar('page');
29
30
        if ($this->owner->currentPage) {
31
            $this->owner->list->setCurrentPage($this->owner->currentPage);
32
        }
33
34
        return $this->owner->list;
35
    }
36
37
    public function nextPage()
38
    {
39
        if ($this->owner->list->CurrentPage() < $this->owner->list->TotalPages()) {
40
            return '?page=' . ($this->owner->list->CurrentPage() + 1);
41
        }
42
43
        return false;
44
    }
45
46
    public function prevPage()
47
    {
48
        if ($this->owner->list->CurrentPage() > 1) {
49
            return '?page=' . ($this->owner->list->CurrentPage() - 1);
50
        }
51
52
        return false;
53
    }
54
}
55