OrderHistoryController::index()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Dynamic\Foxy\Orders\Page;
4
5
use Dynamic\Foxy\Orders\Model\Order;
6
use SilverStripe\ORM\ArrayList;
7
use SilverStripe\ORM\DataList;
8
use SilverStripe\ORM\PaginatedList;
9
use SilverStripe\Security\Security;
10
11
class OrderHistoryController extends \PageController
12
{
13
    /**
14
     * @var array
15
     */
16
    private static $allowed_actions = [
0 ignored issues
show
introduced by
The private property $allowed_actions is not used, and could be removed.
Loading history...
17
        'index',
18
    ];
19
20
    /**
21
     * @var PaginatedList
22
     */
23
    private $order_paginated_list;
24
25
    /**
26
     * @return bool|\SilverStripe\Control\HTTPResponse
27
     */
28
    public function checkMember()
29
    {
30
        if (Security::getCurrentUser()) {
31
            return true;
32
        } else {
33
            return Security::permissionFailure($this, _t(
34
                'AccountPage.CANNOTCONFIRMLOGGEDIN',
35
                'Please login to view this page.'
36
            ));
37
        }
38
    }
39
40
    /**
41
     * @return array
42
     */
43
    public function index()
44
    {
45
        $this->checkMember();
46
47
        return [];
48
    }
49
50
    protected function setOrderPaginatedList()
51
    {
52
        if (Security::getCurrentUser()) {
53
            $request = $this->getRequest();
54
            $orders = $this->data()->getOrderList();
55
            $start = ($request->getVar('start')) ? (int)$request->getVar('start') : 0;
56
            $records = PaginatedList::create($orders, $request);
57
            $records->setPageStart($start);
58
            $records->setPageLength($this->data()->PerPage);
59
        } else {
60
            $records = ArrayList::create();
61
        }
62
63
        $this->extend('updateOrderPaginatedList', $records);
64
65
        $this->order_paginated_list = $records;
66
67
        return $this;
68
    }
69
70
    /**
71
     * @return PaginatedList
72
     */
73
    public function OrderPaginatedList()
74
    {
75
        if (!$this->order_paginated_list) {
76
            $this->setOrderPaginatedList();
77
        }
78
79
        return $this->order_paginated_list;
80
    }
81
}
82