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( |
|
|
|
|
22
|
|
|
'Title' => 'Text', |
23
|
|
|
'SortOrder' => 'Int', |
24
|
|
|
); |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var array |
28
|
|
|
*/ |
29
|
|
|
private static $has_one = array( |
|
|
|
|
30
|
|
|
'Image' => Image::class, |
31
|
|
|
'Parent' => SiteTree::class, |
32
|
|
|
); |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
private static $default_sort = 'SortOrder'; |
|
|
|
|
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var array |
41
|
|
|
*/ |
42
|
|
|
private static $summary_fields = array( |
|
|
|
|
43
|
|
|
'Image.CMSThumbnail' => 'Image', |
44
|
|
|
'Title' => 'Caption', |
45
|
|
|
); |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
private static $table_name = 'FS_ProductImage'; |
|
|
|
|
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return \SilverStripe\Forms\FieldList |
54
|
|
|
*/ |
55
|
|
|
public function getCMSFields() |
56
|
|
|
{ |
57
|
|
|
$fields = FieldList::create( |
58
|
|
|
TextField::create('Title') |
|
|
|
|
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 |
|
|
|
|
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 |
|
|
|
|
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 |
|
|
|
|
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
|
|
|
|