Completed
Push — master ( 11a657...cb88da )
by Gordon
10:22
created

GalleryPage::getGalleryImages()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
class GalleryPage extends PageWithImage
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 static $has_many = array(
6
        'GalleryImages' => 'GalleryImage',
7
    );
8
9
    private static $db = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $db is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
10
        'GalleryDate' => 'Date',
11
    );
12
13
    private static $icon = 'ss3gallery/icons/photo.png';
0 ignored issues
show
Unused Code introduced by
The property $icon is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
14
15 1
    public function getCMSFields()
16
    {
17 1
        $fields = parent::getCMSFields();
18 1
        $gridFieldConfig = GridFieldConfig_RecordEditor::create();
19
        //$gridFieldConfig->addComponent(new GridFieldBulkEditingTools());
20 1
        $gridFieldConfig->addComponent($gbu = new GridFieldBulkUpload());
21 1
        $editableFields = array('Title', 'Caption', 'Aperture', 'ShutterSpeed', 'Image');
22 1
        $gridFieldConfig->addComponent($gbm = new GridFieldBulkManager($editableFields));
23 1
        $gridFieldConfig->addComponent(new GridFieldSortableRows('SortOrder'));
24 1
        $galleryimagesi18n = _t('GalleryImage.PLURALNAME', 'Gallery Images');
25
        //$gbu->setConfig('fileRelationName','Image');
26
27 1
        $gbu->setUfConfig('folderName', 'galleries/'.$this->ID);
28 1
        $gbm->setConfig('editableFields', $editableFields);
29
        // This is no longer available... $gbm->setConfig('fieldsNameBlacklist', array('Lat', 'Lon', 'ZoomLevel'));
30 1
        $gridfield = new GridField('GalleryImages', $galleryimagesi18n, $this->GalleryImages()->sort('"SortOrder"'), $gridFieldConfig);
31 1
        $fields->addFieldToTab('Root.'.$galleryimagesi18n, $gridfield);
32
33 1
        $fields->addFieldToTab('Root.Date', new DateField('GalleryDate'));
34
35 1
        return $fields;
36
    }
37
38 2
    public function Map()
0 ignored issues
show
Coding Style introduced by
Method name "GalleryPage::Map" is not in camel caps format
Loading history...
39
    {
40 2
        $photosWithLocation = $this->GalleryImages()->where('"Lat" != 0 AND "Lon" !=0');
41 2
        if ($photosWithLocation->count() == 0) {
42 1
            return '<!-- no image locations found -->'; // don't render a map
43
        }
44 1
        $map = $photosWithLocation->getRenderableMap();
45 1
        $map->setZoom(10);
46 1
        $map->setAdditionalCSSClasses('fullWidthMap');
47 1
        $map->setShowInlineMapDivStyle(true);
48 1
        $map->setClusterer(true);
49
50 1
        $map->setSize('100%', '400px');
51 1
        return $map;
52
    }
53
54
     public function getGalleryImages()
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 4 spaces, found 5
Loading history...
55
    {
0 ignored issues
show
Coding Style introduced by
Opening brace indented incorrectly; expected 5 spaces, found 4
Loading history...
56
        return $this->GalleryImages()->sort('SortOrder');
57
    }
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 4
Loading history...
Coding Style introduced by
Closing brace indented incorrectly; expected 5 spaces, found 4
Loading history...
58
59
}
60
61
62
63
class GalleryPage_Controller extends Page_Controller
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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...
Coding Style introduced by
This class is not in CamelCase format.

Classes in PHP are usually named in CamelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.

Thus the name database provider becomes DatabaseProvider.

Loading history...
64
{
65
    public static $allowed_actions = array();
66
67
    public function GetGalleryImages()
0 ignored issues
show
Coding Style introduced by
Method name "GalleryPage_Controller::GetGalleryImages" is not in camel caps format
Loading history...
68
    {
69
        return $this->GalleryImages()->sort('SortOrder');
70
    }
71
}
72