Completed
Push — 1.0 ( 78976d...0dd4e9 )
by Morven
01:43
created

PostageController::RelativeLink()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SilverCommerce\Postage\Tests\Control;
4
5
use SilverStripe\Dev\TestOnly;
6
use SilverStripe\Control\Director;
7
use SilverStripe\Forms\HiddenField;
8
use SilverStripe\Control\Controller;
9
use SilverCommerce\Postage\Forms\PostageForm;
10
use SilverCommerce\Postage\Tests\Model\ExtendableObject;
11
use SilverStripe\ORM\FieldType\DBHTMLText;
12
13
/**
14
 * Controller used for testing form submissions
15
 */
16
class PostageController extends Controller implements TestOnly
17
{
18
19
    private static $url_segment = 'postagetest';
20
21
    private static $allowed_actions = [
0 ignored issues
show
introduced by
The private property $allowed_actions is not used, and could be removed.
Loading history...
22
        'index',
23
        'complete',
24
        'PostageForm'
25
    ];
26
27
    public function getObject()
28
    {
29
        $session = $this->getRequest()->getSession();
30
        $id = $session->get("ObjectID");
31
        return ExtendableObject::get()->byID($id);
32
    }
33
34
    public function Link($action = null)
35
    {
36
        return Controller::join_links(
37
            $this->config()->url_segment,
38
            $action
39
        );
40
    }
41
42
    public function AbsoluteLink($action = null)
43
    {
44
        return Director::absoluteURL($this->Link($action));
45
    }
46
47
    public function RelativeLink($action = null)
48
    {
49
        return Controller::join_links(
50
            $this->Link($action)
51
        );
52
    }
53
54
    public function index()
55
    {
56
        $id = $this->getRequest()->param("ID");
57
        $object = ExtendableObject::get()->byID($id);
0 ignored issues
show
Bug introduced by
$id of type string is incompatible with the type integer expected by parameter $id of SilverStripe\ORM\DataList::byID(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

57
        $object = ExtendableObject::get()->byID(/** @scrutinizer ignore-type */ $id);
Loading history...
58
        $session = $this->getRequest()->getSession();
59
        $session->set("ObjectID", $object->ID);
60
61
        $html = '<p class="postage-key">';
62
        $html .= $object->getPostage()->getKey();
63
        $html .= '</p>';
64
        $content = DBHTMLText::create();
65
        $content->setValue($html);
66
67
        $this->customise([
68
            "Content" => $content
69
        ]);
70
71
        return $this->render();
72
    }
73
74
    public function complete()
75
    {
76
        $this->customise([
77
            "Content" => '<p class="message">form submitted</p>'
78
        ]);
79
80
        return $this->render();
81
    }
82
83
    public function PostageForm()
84
    {
85
        $object = $this->getObject();
86
87
        $form = PostageForm::create(
88
            $this,
0 ignored issues
show
Bug introduced by
$this of type SilverCommerce\Postage\T...ntrol\PostageController is incompatible with the type array expected by parameter $args of SilverStripe\View\ViewableData::create(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

88
            /** @scrutinizer ignore-type */ $this,
Loading history...
89
            "PostageForm",
0 ignored issues
show
Bug introduced by
'PostageForm' of type string is incompatible with the type array expected by parameter $args of SilverStripe\View\ViewableData::create(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

89
            /** @scrutinizer ignore-type */ "PostageForm",
Loading history...
90
            $object,
0 ignored issues
show
Bug introduced by
$object of type SilverStripe\ORM\DataObject is incompatible with the type array expected by parameter $args of SilverStripe\View\ViewableData::create(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

90
            /** @scrutinizer ignore-type */ $object,
Loading history...
91
            $object->SubTotal,
92
            $object->TotalWeight,
93
            $object->TotalItems,
94
            $object->DeliveryCountry,
95
            $object->DeliveryCounty
96
        );
97
98
        return $form;
99
    }
100
}
101