Completed
Push — master ( f8f77e...d2a4ab )
by Jason
05:01
created

ProductImage   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
dl 0
loc 94
ccs 0
cts 18
cp 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A canView() 0 3 1
A canCreate() 0 3 1
A canEdit() 0 3 1
A canDelete() 0 3 1
A getCMSFields() 0 14 1
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
 *
15
 */
16
class ProductImage extends DataObject
17
{
18
    /**
19
     * @var array
20
     */
21
    private static $db = array(
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
22
        'Title' => 'Text',
23
        'SortOrder' => 'Int',
24
    );
25
26
    /**
27
     * @var array
28
     */
29
    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...
30
        'Image' => Image::class,
31
        'Parent' => SiteTree::class,
32
    );
33
34
    /**
35
     * @var string
36
     */
37
    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...
38
39
    /**
40
     * @var array
41
     */
42
    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...
43
        'Image.CMSThumbnail' => 'Image',
44
        'Title' => 'Caption',
45
    );
46
47
    /**
48
     * @var string
49
     */
50
    private static $table_name = 'FS_ProductImage';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
51
52
    /**
53
     * @return \SilverStripe\Forms\FieldList
54
     */
55
    public function getCMSFields()
56
    {
57
        $fields = FieldList::create(
58
            TextField::create('Title')
0 ignored issues
show
Bug introduced by
'Title' 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

58
            TextField::create(/** @scrutinizer ignore-type */ 'Title')
Loading history...
59
                ->setTitle(_t('ProductImage.Title', 'Product Image Title')),
60
            UploadField::create('Image')
61
                ->setTitle(_t('ProductCategory.Image', 'Product Image'))
62
                ->setFolderName('Uploads/Products')
63
                ->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'))
64
        );
65
66
        $this->extend('updateCMSFields', $fields);
67
68
        return $fields;
69
    }
70
71
    /**
72
     * @param bool $member
73
     *
74
     * @return bool
75
     */
76
    public function canView($member = false)
77
    {
78
        return true;
79
    }
80
81
    /**
82
     * @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...
83
     *
84
     * @return bool
85
     */
86
    public function canEdit($member = null)
87
    {
88
        return Permission::check('Product_CANCRUD');
89
    }
90
91
    /**
92
     * @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...
93
     *
94
     * @return bool|int
95
     */
96
    public function canDelete($member = null)
97
    {
98
        return Permission::check('Product_CANCRUD');
99
    }
100
101
    /**
102
     * @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...
103
     * @param array $context
104
     *
105
     * @return bool|int
106
     */
107
    public function canCreate($member = null, $context = [])
108
    {
109
        return Permission::check('Product_CANCRUD');
110
    }
111
}
112