Completed
Push — master ( db7992...03e2a4 )
by Simon
02:23
created

PartialFormSubmission::getCMSFields()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 28
rs 8.8571
cc 1
eloc 17
nc 1
nop 0
1
<?php
2
3
namespace Firesphere\PartialUserforms\Models;
4
5
use SilverStripe\Forms\FieldList;
6
use SilverStripe\ORM\DataObject;
7
use SilverStripe\UserForms\Model\Submission\SubmittedForm;
8
use SilverStripe\Forms\GridField\GridField;
9
use SilverStripe\Forms\GridField\GridFieldConfig;
10
use SilverStripe\Forms\GridField\GridFieldDataColumns;
11
use SilverStripe\Forms\GridField\GridFieldExportButton;
12
use SilverStripe\Forms\GridField\GridFieldPrintButton;
13
14
/**
15
 * Class \Firesphere\PartialUserforms\Models\PartialFormSubmission
16
 *
17
 * @property boolean $IsSend
18
 * @property int $UserDefinedFormID
19
 * @method \SilverStripe\ORM\DataObject UserDefinedForm()
20
 * @method \SilverStripe\ORM\DataList|\Firesphere\PartialUserforms\Models\PartialFieldSubmission[] PartialFields()
21
 */
22
class PartialFormSubmission extends SubmittedForm
23
{
24
    private static $table_name = 'PartialFormSubmission';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $table_name 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...
25
26
    private static $db = [
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
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...
27
        'IsSend' => 'Boolean(false)'
28
    ];
29
30
    private static $has_one = [
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
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...
31
        'UserDefinedForm' => DataObject::class
32
    ];
33
34
    private static $has_many = [
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $has_many 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...
35
        'PartialFields' => PartialFieldSubmission::class
36
    ];
37
38
    public function getCMSFields()
39
    {
40
        /** @var FieldList $fields */
41
        $fields = parent::getCMSFields();
42
        $fields->removeByName(['Values', 'IsSend', 'PartialFields']);
43
44
        $values = GridField::create(
45
            'PartialFields',
46
            _t(static::class . '.PARTIALFIELDS', 'Partial fields'),
47
            $this->PartialFields()->sort('Created', 'ASC')
48
        );
49
50
        $exportColumns = array(
51
            'Title' => 'Title',
52
            'ExportValue' => 'Value'
53
        );
54
55
        $config = new GridFieldConfig();
56
        $config->addComponent(new GridFieldDataColumns());
57
        $config->addComponent(new GridFieldExportButton('after', $exportColumns));
58
        $config->addComponent(new GridFieldPrintButton());
59
60
        $values->setConfig($config);
61
62
        $fields->addFieldToTab('Root.Main', $values);
63
64
        return $fields;
65
    }
66
67
    public function getParent()
68
    {
69
        return $this->UserDefinedForm();
70
    }
71
72
    /**
73
     * @param Member
74
     *
75
     * @return boolean
76
     */
77
    public function canCreate($member = null, $context = [])
78
    {
79
        if ($this->UserDefinedForm()) {
80
            return $this->UserDefinedForm()->canCreate($member, $context);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->UserDefinedForm()...ate($member, $context); of type boolean|string adds the type string to the return on line 80 which is incompatible with the return type of the parent method SilverStripe\UserForms\M...ubmittedForm::canCreate of type boolean.
Loading history...
81
        }
82
83
        return parent::canCreate($member);
84
    }
85
86
    /**
87
     * @param Member
88
     *
89
     * @return boolean
90
     */
91
    public function canView($member = null)
92
    {
93
        if ($this->UserDefinedForm()) {
94
            return $this->UserDefinedForm()->canView($member);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->UserDefinedForm()->canView($member); of type boolean|string adds the type string to the return on line 94 which is incompatible with the return type of the parent method SilverStripe\UserForms\M...\SubmittedForm::canView of type boolean.
Loading history...
95
        }
96
97
        return parent::canView($member);
98
    }
99
100
    /**
101
     * @param Member
102
     *
103
     * @return boolean
104
     */
105
    public function canEdit($member = null)
106
    {
107
        if ($this->UserDefinedForm()) {
108
            return $this->UserDefinedForm()->canEdit($member);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->UserDefinedForm()->canEdit($member); of type boolean|string adds the type string to the return on line 108 which is incompatible with the return type of the parent method SilverStripe\UserForms\M...\SubmittedForm::canEdit of type boolean.
Loading history...
109
        }
110
111
        return parent::canEdit($member);
112
    }
113
114
    /**
115
     * @param Member
116
     *
117
     * @return boolean
118
     */
119
    public function canDelete($member = null)
120
    {
121
        if ($this->UserDefinedForm()) {
122
            return $this->UserDefinedForm()->canDelete($member);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->UserDefinedForm()->canDelete($member); of type boolean|string adds the type string to the return on line 122 which is incompatible with the return type of the parent method SilverStripe\UserForms\M...ubmittedForm::canDelete of type boolean.
Loading history...
123
        }
124
125
        return parent::canDelete($member);
126
    }
127
}
128