1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class GalleryPage_Controller extends Page_Controller |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
public function init() { |
6
|
|
|
parent::init(); |
7
|
|
|
} |
8
|
|
|
|
9
|
|
View Code Duplication |
public function PaginatedImages() |
|
|
|
|
10
|
|
|
{ |
11
|
|
|
$list = $this->SortedImages(); |
12
|
|
|
$limit = $this->ThumbnailsPerPage; |
13
|
|
|
|
14
|
|
|
$pages = PaginatedList::create($list, $this->getRequest()); |
15
|
|
|
$pages->setpageLength($limit); |
16
|
|
|
|
17
|
|
|
return $pages; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Generate an image based on the provided type |
22
|
|
|
* (either ) |
23
|
|
|
* |
24
|
|
|
* @param Image $image |
25
|
|
|
* @param string $thumbnail generate a smaller image (based on thumbnail settings) |
|
|
|
|
26
|
|
|
* @return void |
|
|
|
|
27
|
|
|
*/ |
28
|
|
|
protected function ScaledImage(Image $image, $thumbnail = false) |
29
|
|
|
{ |
30
|
|
|
$img = false; |
31
|
|
|
$background = $this->PaddedImageBackground; |
32
|
|
|
|
33
|
|
|
if ($thumbnail) { |
|
|
|
|
34
|
|
|
$resize_type = $this->ThumbnailResizeType; |
35
|
|
|
$width = $this->ThumbnailWidth; |
36
|
|
|
$height = $this->ThumbnailHeight; |
37
|
|
|
} else { |
38
|
|
|
$resize_type = $this->ImageResizeType; |
39
|
|
|
$width = $this->ImageWidth; |
40
|
|
|
$height = $this->ImageHeight; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
switch ($resize_type) { |
44
|
|
|
case 'crop': |
45
|
|
|
$img = $image->CroppedImage($width,$height); |
|
|
|
|
46
|
|
|
break; |
47
|
|
|
case 'pad': |
48
|
|
|
$img = $image->PaddedImage($width,$height,$background); |
|
|
|
|
49
|
|
|
break; |
50
|
|
|
case 'ratio': |
51
|
|
|
$img = $image->SetRatioSize($width,$height); |
|
|
|
|
52
|
|
|
break; |
53
|
|
|
case 'width': |
54
|
|
|
$img = $image->ScaleWidth($width); |
55
|
|
|
break; |
56
|
|
|
case 'height': |
57
|
|
|
$img = $image->ScaleHeight($height); |
58
|
|
|
break; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$this->extend("augmentImageResize", $image, $thumbnail, $img); |
62
|
|
|
|
63
|
|
|
return $img; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
protected function GalleryImage(Image $image) |
67
|
|
|
{ |
68
|
|
|
return $this->ScaledImage($image); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
protected function GalleryThumbnail(Image $image) |
72
|
|
|
{ |
73
|
|
|
return $this->ScaledImage($image, true); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Generate an image gallery from the Gallery template, if no images are |
78
|
|
|
* available, then return an empty string. |
79
|
|
|
* |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
|
|
public function Gallery() |
83
|
|
|
{ |
84
|
|
|
if ($this->Images()->exists()) { |
85
|
|
|
|
86
|
|
|
// Create a list of images with generated gallery image and thumbnail |
87
|
|
|
$images = ArrayList::create(); |
88
|
|
|
foreach ($this->PaginatedImages() as $image) { |
89
|
|
|
$image_data = $image->toMap(); |
90
|
|
|
$image_data["GalleryImage"] = $this->GalleryImage($image); |
91
|
|
|
$image_data["GalleryThumbnail"] = $this->GalleryThumbnail($image); |
92
|
|
|
$images->add(ArrayData::create($image_data)); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
$vars = array( |
96
|
|
|
'Images' => $images, |
97
|
|
|
'Width' => $this->ImageWidth, |
98
|
|
|
'Height' => $this->ImageHeight |
99
|
|
|
); |
100
|
|
|
|
101
|
|
|
return $this->renderWith('Gallery',$vars); |
102
|
|
|
} else { |
103
|
|
|
return ""; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
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.