Issues (236)

src/Model/OrderDetail.php (12 issues)

1
<?php
2
3
namespace Dynamic\FoxyStripe\Model;
4
5
use Dynamic\FoxyStripe\Page\ProductPage;
6
use SilverStripe\Forms\FieldList;
7
use SilverStripe\Forms\GridField\GridField;
8
use SilverStripe\Forms\GridField\GridFieldConfig_RecordViewer;
9
use SilverStripe\ORM\DataObject;
10
use SilverStripe\Security\Permission;
11
12
/**
13
 * Class OrderDetail
14
 * @package Dynamic\FoxyStripe\Model
15
 *
16
 * @property \SilverStripe\ORM\FieldType\DBInt Quantity
17
 * @property \SilverStripe\ORM\FieldType\DBCurrency Price
18
 * @property \SilverStripe\ORM\FieldType\DBVarchar ProductName
19
 * @property \SilverStripe\ORM\FieldType\DBVarchar ProductCode
20
 * @property \SilverStripe\ORM\FieldType\DBText ProductImage
21
 * @property \SilverStripe\ORM\FieldType\DBVarchar ProductCategory
22
 *
23
 * @property int ProductID
24
 * @method ProductPage Product()
25
 * @property int OrderID
26
 * @method Order Order()
27
 *
28
 * @method \SilverStripe\ORM\HasManyList OrderOptions()
29
 * @method \SilverStripe\ORM\ManyManyList OptionItems()
30
 */
31
class OrderDetail extends DataObject
32
{
33
    /**
34
     * @var string
35
     */
36
    private static $singular_name = 'Order Detail';
0 ignored issues
show
The private property $singular_name is not used, and could be removed.
Loading history...
37
38
    /**
39
     * @var string
40
     */
41
    private static $plural_name = 'Order Details';
0 ignored issues
show
The private property $plural_name is not used, and could be removed.
Loading history...
42
43
    /**
44
     * @var string
45
     */
46
    private static $description = '';
0 ignored issues
show
The private property $description is not used, and could be removed.
Loading history...
47
48
    /**
49
     * @var array
50
     */
51
    private static $db = array(
0 ignored issues
show
The private property $db is not used, and could be removed.
Loading history...
52
        'Quantity' => 'Int',
53
        'Price' => 'Currency',
54
        'ProductName' => 'Varchar(255)',
55
        'ProductCode' => 'Varchar(100)',
56
        'ProductImage' => 'Text',
57
        'ProductCategory' => 'Varchar(100)',
58
    );
59
60
    /**
61
     * @var array
62
     */
63
    private static $has_one = array(
0 ignored issues
show
The private property $has_one is not used, and could be removed.
Loading history...
64
        'Product' => ProductPage::class,
65
        'Order' => Order::class,
66
    );
67
68
    /**
69
     * @var array
70
     */
71
    private static $has_many = array(
0 ignored issues
show
The private property $has_many is not used, and could be removed.
Loading history...
72
        'OrderOptions' => OrderOption::class,
73
    );
74
75
    /**
76
     * @var array
77
     */
78
    private static $many_many = [
0 ignored issues
show
The private property $many_many is not used, and could be removed.
Loading history...
79
        'OptionItems' => OptionItem::class,
80
    ];
81
82
    /**
83
     * @var array
84
     */
85
    private static $summary_fields = array(
0 ignored issues
show
The private property $summary_fields is not used, and could be removed.
Loading history...
86
        'Product.Title',
87
        'Quantity',
88
        'Price.Nice',
89
    );
90
91
    /**
92
     * @var string
93
     */
94
    private static $table_name = 'OrderDetail';
0 ignored issues
show
The private property $table_name is not used, and could be removed.
Loading history...
95
96
    /**
97
     * @return FieldList
98
     */
99 1
    public function getCMSFields()
100
    {
101 1
        $fields = parent::getCMSFields();
102
103 1
        if ($this->ID) {
104 1
            $fields->addFieldsToTab('Root.Options', array(
105 1
                GridField::create(
106 1
                    'Options',
107 1
                    'Product Options',
108 1
                    $this->OrderOptions(),
109 1
                    GridFieldConfig_RecordViewer::create()
110
                ),
111
            ));
112
        }
113
114 1
        return $fields;
115
    }
116
117
    /**
118
     * @param bool $member
119
     *
120
     * @return bool|int
121
     */
122 10
    public function canView($member = null)
123
    {
124 10
        return Permission::check('Product_ORDERS', 'any', $member);
0 ignored issues
show
It seems like $member can also be of type boolean; however, parameter $member of SilverStripe\Security\Permission::check() does only seem to accept SilverStripe\Security\Member|integer, maybe add an additional type check? ( Ignorable by Annotation )

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

124
        return Permission::check('Product_ORDERS', 'any', /** @scrutinizer ignore-type */ $member);
Loading history...
125
    }
126
127
    /**
128
     * @param null $member
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $member is correct as it would always require null to be passed?
Loading history...
129
     *
130
     * @return bool
131
     */
132 1
    public function canEdit($member = null)
133
    {
134 1
        return false;
135
    }
136
137
    /**
138
     * @param null $member
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $member is correct as it would always require null to be passed?
Loading history...
139
     * @param array $context
140
     *
141
     * @return bool
142
     */
143 1
    public function canCreate($member = null, $context = [])
144
    {
145 1
        return false;
146
        //return Permission::check('Product_ORDERS');
147
    }
148
149 1
    public function canDelete($member = null)
150
    {
151 1
        return Permission::check('Product_ORDERS', 'any', $member);
152
    }
153
}
154