1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class CustomerImage extends DataObject |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
private static $db = array( |
|
|
|
|
6
|
|
|
'Status' => "Enum('New,Approved,Declined,Example', 'New')", |
7
|
|
|
'FirstName' => 'Varchar', |
8
|
|
|
'Email' => 'Varchar(100)', |
9
|
|
|
'Surname' => 'Varchar', |
10
|
|
|
'Location' => 'Varchar(255)', |
11
|
|
|
'Feedback' => 'Text' |
12
|
|
|
); |
13
|
|
|
|
14
|
|
|
private static $has_one = array( |
|
|
|
|
15
|
|
|
'ProductPage' => 'ProductPage', |
16
|
|
|
'ProductVariation' => 'ProductVariation', |
17
|
|
|
'Image1' => 'Image', |
18
|
|
|
'Image2' => 'Image', |
19
|
|
|
'Image3' => 'Image', |
20
|
|
|
'Image4' => 'Image', |
21
|
|
|
'Image5' => 'Image', |
22
|
|
|
'FinalImage' => 'Image' |
23
|
|
|
); |
24
|
|
|
|
25
|
|
|
private static $default_sort = '"Created" DESC'; |
|
|
|
|
26
|
|
|
|
27
|
|
|
private static $singular_name = 'Customer Image'; |
|
|
|
|
28
|
|
|
|
29
|
|
|
private static $plural_name = 'Customer Images'; |
|
|
|
|
30
|
|
|
|
31
|
|
|
private static $casting = array( |
|
|
|
|
32
|
|
|
"Title" => "Varchar", |
33
|
|
|
'Thumbnail' => "HTMLText" |
34
|
|
|
); |
35
|
|
|
|
36
|
|
|
private static $summary_fields = array( |
|
|
|
|
37
|
|
|
"Thumbnail" => "Thumbnail", |
38
|
|
|
"Status" => "Status", |
39
|
|
|
"Location" => "Location" |
40
|
|
|
); |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* STANDARD SILVERSTRIPE STUFF |
45
|
|
|
* @todo: how to translate this? |
46
|
|
|
**/ |
47
|
|
|
private static $searchable_fields = array( |
|
|
|
|
48
|
|
|
'Status', |
49
|
|
|
'FirstName' => 'PartialMatchFilter', |
50
|
|
|
'Surname' => 'PartialMatchFilter', |
51
|
|
|
'Location' => 'PartialMatchFilter', |
52
|
|
|
'ProductPageID' |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
public function IsPortrait() |
56
|
|
|
{ |
57
|
|
|
if ($this->getWidth() < $this->getHeight()) { |
|
|
|
|
58
|
|
|
return true; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function canView($member = null) |
63
|
|
|
{ |
64
|
|
|
if ($this->Status == "Approved") { |
|
|
|
|
65
|
|
|
return true; |
66
|
|
|
} |
67
|
|
|
return $this->canDelete($member); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getCMSFields() |
71
|
|
|
{ |
72
|
|
|
$fields = parent::getCMSFields(); |
73
|
|
|
|
74
|
|
|
//variations drop down |
75
|
|
|
$variations = ProductVariation::get()->filter(array("ProductID" => $this->ProductPageID))->map("ID", "Title")->toArray(); |
|
|
|
|
76
|
|
|
$fields->addFieldToTab("Root.Main", new DropdownField('ProductVariationID', 'Model', $variations), "FinalImage"); |
77
|
|
|
|
78
|
|
|
//final image field ... |
79
|
|
|
$newImageField = new UploadField("FinalImage"); |
80
|
|
|
$newImageField->setFolderName("Customer-Photos"); |
81
|
|
|
$newImageField->setAllowedExtensions(array("png", "jpg", "gif")); |
82
|
|
|
$fields->addFieldToTab("Root.Main", $newImageField, "Status"); |
83
|
|
|
//loop through images |
84
|
|
|
for ($i = 1; $i < 6; $i++) { |
85
|
|
|
$field = "Image$i"."ID"; |
86
|
|
|
$method = "Image$i"; |
87
|
|
|
if ($this->$field && $image = $this->$method()) { |
88
|
|
|
$imageField = new UploadField($method); |
89
|
|
|
$imageField->setFolderName("Customer-Photos/Drafts"); |
90
|
|
|
$imageField->setAllowedExtensions(array("png", "jpg", "gif")); |
91
|
|
|
$fields->addFieldToTab("Root.DraftImages", $imageField); |
92
|
|
|
} else { |
93
|
|
|
$fields->removeByName($method); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
return $fields; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function getThumbnail() |
|
|
|
|
100
|
|
|
{ |
101
|
|
|
$image = $this->FinalImage(); |
|
|
|
|
102
|
|
|
if (!$image->exists()) { |
103
|
|
|
$image = $this->Image1(); |
|
|
|
|
104
|
|
|
} |
105
|
|
|
if ($image->exists()) { |
106
|
|
|
$icon = "<img src=\"".$image->Link()."\" style=\"border: 1px solid black; height: 150px; \" height=\"200\" />"; |
107
|
|
|
} else { |
108
|
|
|
$icon = "[NO IMAGE]"; |
109
|
|
|
} |
110
|
|
|
return DBField::create_field("HTMLText", $icon); |
|
|
|
|
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
|
115
|
|
|
|
116
|
|
|
class CustomerImage_ModelAdmin extends ModelAdmin |
|
|
|
|
117
|
|
|
{ |
118
|
|
|
private static $url_segment = 'customerimages'; |
|
|
|
|
119
|
|
|
|
120
|
|
|
private static $menu_title = 'Customer Images'; |
|
|
|
|
121
|
|
|
|
122
|
|
|
private static $managed_models = array('CustomerImage'); |
|
|
|
|
123
|
|
|
} |
124
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.