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( |
|
|
|
|
31
|
|
|
'Title' => 'Text', |
32
|
|
|
'SortOrder' => 'Int', |
33
|
|
|
); |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var array |
37
|
|
|
*/ |
38
|
|
|
private static $has_one = array( |
|
|
|
|
39
|
|
|
'Image' => Image::class, |
40
|
|
|
'Parent' => SiteTree::class, |
41
|
|
|
); |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var string |
45
|
|
|
*/ |
46
|
|
|
private static $default_sort = 'SortOrder'; |
|
|
|
|
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var array |
50
|
|
|
*/ |
51
|
|
|
private static $summary_fields = array( |
|
|
|
|
52
|
|
|
'Image.CMSThumbnail' => 'Image', |
53
|
|
|
'Title' => 'Caption', |
54
|
|
|
); |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var string |
58
|
|
|
*/ |
59
|
|
|
private static $table_name = 'ProductImage'; |
|
|
|
|
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 |
|
|
|
|
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 |
|
|
|
|
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 |
|
|
|
|
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
|
|
|
|