Completed
Pull Request — master (#10)
by Franco
02:06
created

requireDefaultRecords()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 18
nc 2
nop 0
1
<?php
2
/**
3
 * @property Text $ThanksMessage
4
 * @property Int  $CartEmailRecipientID
5
 *
6
 * @method Member CartEmailRecipient
7
 */
8
class DMSDocumentCartCheckoutPage extends Page
0 ignored issues
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...
9
{
10
    private static $db = array(
0 ignored issues
show
Unused Code introduced by
The property $db is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
11
        'ThanksMessage' => 'Text',
12
    );
13
14
    private static $has_one = array(
0 ignored issues
show
Unused Code introduced by
The property $has_one is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
15
        'CartEmailRecipient'     => 'Member'
16
    );
17
18
    private static $defaults = array(
0 ignored issues
show
Unused Code introduced by
The property $defaults is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
19
        'URLSegment'  => 'checkout',
20
        'ShowInMenus' => false,
21
    );
22
23
    public function getCMSFields()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
24
    {
25
        $fields = parent::getCMSFields();
26
        $members = Member::get('Member');
27
        $recipientDropDown = DropdownField::create(
28
            'CartEmailRecipientID',
29
            _t('DMSDocumentCartCheckoutPage.CART_RECIPIENT', 'Account to receive document print requests'),
30
            $members->Map()->toArray()
31
        )->setEmptyString(_t(
32
            'DMSDocumentCartCheckoutPage.CART_RECIPIENT_EMPTY_STRING',
33
            'Select a member'
34
        ));
35
        $fields->insertBefore('Content', $recipientDropDown);
36
37
        $fields->insertBefore(
38
            'Content',
39
            TextareaField::create(
40
                'ThanksMessage',
41
                _t('DMSDocumentCartCheckoutPage.THANK_YOU_MESSAGE', 'Thank you message')
42
            )
43
        );
44
45
        return $fields;
46
    }
47
    /**
48
     * Automatically create a CheckoutPage if one is not found
49
     * on the site at the time the database is built (dev/build).
50
     */
51
    function requireDefaultRecords()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
52
    {
53
        parent::requireDefaultRecords();
54
55
        if (!SiteTree::get_one($this->class)) {
56
            /** @var DMSDocumentCartCheckoutPage $page */
57
            $page = self::create();
58
            $page->Title = 'Request a printed copy';
59
            $page->MenuTitle = 'Document Cart Checkout';
60
            $page->Content = '';
61
            $page->URLSegment = 'checkout';
62
            $page->ShowInMenus = 0;
63
            $page->ThanksMessage = 'Thanks for your request.';
64
            $page->write();
65
            $page->publish('Stage', 'Live');
66
            $page->flushCache();
67
            DB::alteration_message(
68
                _t(
69
                    'DMSDocumentCartCheckoutPage.ALTERATION_MESSAGE',
70
                    'Document Cart Checkout page \'Request a printed copy\' created'
71
                ),
72
                'created'
73
            );
74
        }
75
    }
76
}
77