Completed
Push — 1 ( 574f35...b1e328 )
by Morven
01:29
created

GalleryPage_Controller::ScaledImage()   C

Complexity

Conditions 7
Paths 12

Size

Total Lines 37
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 37
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 29
nc 12
nop 2
1
<?php
2
3
class GalleryPage_Controller extends GalleryHub_Controller
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
    public function init() {
6
        parent::init();
7
    }
8
9
    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
    protected function GalleryImage(Image $image)
21
    {
22
        return $this->ScaledImage($image);
23
    }
24
25
    protected function GalleryThumbnail(Image $image)
26
    {
27
        return $this->ScaledImage($image, true);
28
    }
29
30
    /**
31
     * Generate an image gallery from the Gallery template, if no images are
32
     * available, then return an empty string.
33
     *
34
     * @return string
35
     */
36
    public function Gallery()
37
    {
38
        if ($this->Images()->exists()) {
39
40
            // Create a list of images with generated gallery image and thumbnail
41
            $images = ArrayList::create();
42
            foreach ($this->PaginatedImages() as $image) {
43
                $image_data = $image->toMap();
44
                $image_data["GalleryImage"] = $this->GalleryImage($image);
45
                $image_data["GalleryThumbnail"] = $this->GalleryThumbnail($image);
46
                $images->add(ArrayData::create($image_data));
47
            }
48
            
49
            $vars = array(
50
                'Images' => $images,
51
                'Width' => $this->ImageWidth,
52
                'Height' => $this->ImageHeight
53
            );
54
55
            return $this->renderWith('Gallery',$vars);
56
        } else {
57
            return "";
58
        }
59
    }
60
}
61