ProductImage::canEdit()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Dynamic\FoxyStripe\Model;
4
5
use SilverStripe\AssetAdmin\Forms\UploadField;
6
use SilverStripe\Assets\Image;
7
use SilverStripe\CMS\Model\SiteTree;
8
use SilverStripe\Forms\FieldList;
9
use SilverStripe\Forms\TextField;
10
use SilverStripe\ORM\DataObject;
11
use SilverStripe\Security\Permission;
12
13
/**
14
 * Class ProductImage
15
 * @package Dynamic\FoxyStripe\Model
16
 *
17
 * @property \SilverStripe\ORM\FieldType\DBText Title
18
 * @property \SilverStripe\ORM\FieldType\DBInt SortOrder
19
 *
20
 * @property int ImageID
21
 * @method Image Image
22
 * @property int ParentID
23
 * @method SiteTree Parent
24
 */
25
class ProductImage extends DataObject
26
{
27
    /**
28
     * @var array
29
     */
30
    private static $db = array(
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
31
        'Title' => 'Text',
32
        'SortOrder' => 'Int',
33
    );
34
35
    /**
36
     * @var array
37
     */
38
    private static $has_one = array(
0 ignored issues
show
introduced by
The private property $has_one is not used, and could be removed.
Loading history...
39
        'Image' => Image::class,
40
        'Parent' => SiteTree::class,
41
    );
42
43
    /**
44
     * @var string
45
     */
46
    private static $default_sort = 'SortOrder';
0 ignored issues
show
introduced by
The private property $default_sort is not used, and could be removed.
Loading history...
47
48
    /**
49
     * @var array
50
     */
51
    private static $summary_fields = array(
0 ignored issues
show
introduced by
The private property $summary_fields is not used, and could be removed.
Loading history...
52
        'Image.CMSThumbnail' => 'Image',
53
        'Title' => 'Caption',
54
    );
55
56
    /**
57
     * @var string
58
     */
59
    private static $table_name = 'ProductImage';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
60
61
    /**
62
     * @return \SilverStripe\Forms\FieldList
63
     */
64
    public function getCMSFields()
65
    {
66
        $fields = FieldList::create(
67
            TextField::create('Title')
68
                ->setTitle(_t('ProductImage.Title', 'Product Image Title')),
69
            UploadField::create('Image')
70
                ->setTitle(_t('ProductCategory.Image', 'Product Image'))
71
                ->setFolderName('Uploads/Products')
72
                ->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'))
73
        );
74
75
        $this->extend('updateCMSFields', $fields);
76
77
        return $fields;
78
    }
79
80
    /**
81
     * @param bool $member
82
     *
83
     * @return bool
84
     */
85
    public function canView($member = null)
86
    {
87
        return true;
88
    }
89
90
    /**
91
     * @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...
92
     *
93
     * @return bool
94
     */
95
    public function canEdit($member = null)
96
    {
97
        return Permission::check('Product_CANCRUD');
98
    }
99
100
    /**
101
     * @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...
102
     *
103
     * @return bool|int
104
     */
105
    public function canDelete($member = null)
106
    {
107
        return Permission::check('Product_CANCRUD');
108
    }
109
110
    /**
111
     * @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...
112
     * @param array $context
113
     *
114
     * @return bool|int
115
     */
116
    public function canCreate($member = null, $context = [])
117
    {
118
        return Permission::check('Product_CANCRUD');
119
    }
120
}
121