|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* A single page that can display many images as thumbnails. |
|
5
|
|
|
* |
|
6
|
|
|
* @package gallery |
|
7
|
|
|
*/ |
|
8
|
|
|
class GalleryPage extends GalleryHub |
|
|
|
|
|
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @var string |
|
12
|
|
|
*/ |
|
13
|
|
|
private static $description = 'Display a "gallery" of images'; |
|
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
private static $icon = "gallery/images/gallery.png"; |
|
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
private static $db = array( |
|
|
|
|
|
|
18
|
|
|
"ImageWidth" => "Int", |
|
19
|
|
|
"ImageHeight" => "Int", |
|
20
|
|
|
"ImageResizeType" => "Enum(array('crop','pad','ratio','width','height'), 'ratio')" |
|
21
|
|
|
); |
|
22
|
|
|
|
|
23
|
|
|
private static $defaults = array( |
|
|
|
|
|
|
24
|
|
|
"ImageWidth" => 950, |
|
25
|
|
|
"ImageHeight" => 500, |
|
26
|
|
|
"ShowSideBar" => 1 |
|
27
|
|
|
); |
|
28
|
|
|
|
|
29
|
|
|
private static $many_many = array( |
|
|
|
|
|
|
30
|
|
|
'Images' => 'Image' |
|
31
|
|
|
); |
|
32
|
|
|
|
|
33
|
|
|
private static $many_many_extraFields = array( |
|
|
|
|
|
|
34
|
|
|
'Images' => array('SortOrder' => 'Int') |
|
35
|
|
|
); |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Return sorted images |
|
39
|
|
|
* |
|
40
|
|
|
* @return ArrayList |
|
41
|
|
|
*/ |
|
42
|
|
|
public function SortedImages() |
|
43
|
|
|
{ |
|
44
|
|
|
return $this->Images()->Sort('SortOrder'); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function getCMSFields() |
|
|
|
|
|
|
48
|
|
|
{ |
|
49
|
|
|
$self =& $this; |
|
50
|
|
|
|
|
51
|
|
|
$this->beforeUpdateCMSFields(function ($fields) use ($self) { |
|
52
|
|
|
if (!$self->canEdit()) { |
|
53
|
|
|
return; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
$fields->removeByName('HideDescription'); |
|
57
|
|
|
|
|
58
|
|
|
$upload_folder = Controller::join_links( |
|
59
|
|
|
"gallery", |
|
60
|
|
|
$self->ID |
|
61
|
|
|
); |
|
62
|
|
|
|
|
63
|
|
|
$fields->addFieldToTab( |
|
64
|
|
|
"Root.Gallery", |
|
65
|
|
|
SortableUploadField::create( |
|
66
|
|
|
'Images', |
|
67
|
|
|
$this->fieldLabel('Images') |
|
68
|
|
|
)->setFolderName($upload_folder) |
|
69
|
|
|
); |
|
70
|
|
|
}); |
|
71
|
|
|
|
|
72
|
|
|
return parent::getCMSFields(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function getSettingsFields() { |
|
|
|
|
|
|
76
|
|
|
$fields = parent::getSettingsFields(); |
|
77
|
|
|
|
|
78
|
|
|
$fields->addFieldsToTab( |
|
79
|
|
|
'Root.Settings', |
|
80
|
|
|
array( |
|
81
|
|
|
NumericField::create("ImageWidth"), |
|
82
|
|
|
NumericField::create("ImageHeight"), |
|
83
|
|
|
DropdownField::create("ImageResizeType") |
|
84
|
|
|
->setSource($this->dbObject("ImageResizeType")->enumValues()) |
|
85
|
|
|
) |
|
86
|
|
|
); |
|
87
|
|
|
|
|
88
|
|
|
return $fields; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function onBeforeWrite() |
|
92
|
|
|
{ |
|
93
|
|
|
parent::onBeforeWrite(); |
|
94
|
|
|
|
|
95
|
|
|
// default settings (if not set) |
|
96
|
|
|
$defaults = $this->config()->defaults; |
|
97
|
|
|
$this->ImageWidth = ($this->ImageWidth) ? $this->ImageWidth : $defaults["ImageWidth"]; |
|
98
|
|
|
$this->ImageHeight = ($this->ImageHeight) ? $this->ImageHeight : $defaults["ImageHeight"]; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
} |
|
102
|
|
|
|
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.