Completed
Pull Request — master (#7)
by
unknown
63:17
created

ShareThisSiteConfigDE   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 83
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
B updateCMSFields() 0 58 3
A CanEditShareIcons() 0 13 3
1
<?php
2
3
namespace SunnySideUp\ShareThis;
4
5
use SilverStripe\Forms\FieldList;
6
use SunnySideUp\ShareThis\ShareThisDataObject;
7
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
8
use SilverStripe\Forms\GridField\GridField;
9
use SunnySideUp\ShareThis\SocialNetworkingLinksDataObject;
10
use SilverStripe\Forms\HiddenField;
11
use SilverStripe\Forms\CheckboxField;
12
use SilverStripe\Forms\LiteralField;
13
use SilverStripe\Forms\Tab;
14
use SilverStripe\Forms\TabSet;
15
use SilverStripe\ORM\DataExtension;
16
17
/**
18
 * @todo Check that permissions on the 2 tables in the CMS are the same than before
19
 * @todo Fix the CanEditShareIcons section in updateCMSFields
20
 */
21
class ShareThisSiteConfigDE extends DataExtension
22
{
23
    private static $db = array(
24
        'AlwaysIncludeShareThisLinks' => 'Boolean',
25
        'AlwaysIncludeSocialNetworkingLinks' => 'Boolean',
26
        'IncludeByDefaultShareThisLinks' => 'Boolean',
27
        'IncludeByDefaultSocialNetworkingLinks' => 'Boolean',
28
        'ShareThisAllInOne' => 'Boolean'
29
    );
30
31
    public function updateCMSFields(FieldList $fields)
32
    {
33
        $individualPageNoteWith = _t("ShareThis.INDIVIDUAL_PAGE_NOTE_WITH", " (with the ability to turn them off/on on individual pages) ");
34
        $individualPageNoteWithout  = _t("ShareThis.INDIVIDUAL_PAGE_NOTE_WITHOUT", " (without the ability to turn them off/on on individual pages) ");
35
        $shareThisExtra = '<h3 style="margin-top: 50px">Select Icons</h3>';
36
        /*		if($this->CanEditShareIcons()) {
37
                    $addedLinks = array();
38
                    $obj = singleton('ShareThisDataObject');
39
                    $addedLinksShort['edit'] = DataObjectOneFieldUpdateController::popup_link('ShareThisDataObject', 'IncludeThisIcon');
40
                    $addedLinksLong['edit'] = DataObjectOneFieldUpdateController::popup_link('ShareThisDataObject', 'IncludeThisIconInExtendedList');
41
                    $addedLinksShort['sort'] = $obj->dataObjectSorterPopupLink('IncludeThisIcon', 1);
42
                    $addedLinksLong['sort'] = $obj->dataObjectSorterPopupLink('IncludeThisIconInExtendedList', 1);
43
                    if(count($addedLinksShort)) {
44
                        $shareThisExtra .= '<p>main list: ' . implode(', ', $addedLinksShort) . '.</p>';
45
                    }
46
                    if(count($addedLinksLong)) {
47
                        $shareThisExtra .= '<p>long list: ' . implode(', ', $addedLinksLong) . '.</p>';
48
                    }
49
                }
50
        */
51
        $shareThisTableField = new GridField('Share this options', null, ShareThisDataObject::get(), GridFieldConfig_RecordEditor::create());
52
        //$shareThisTableField->setPermissions(array("edit", "add"));
53
        $socialNetworkExtra = '<h3 style="margin-top: 50px">Add / Edit / Delete Your Social Networking Home Pages (e.g. www.facebook.com/our-company-page)</h3>';
54
        $socialNetworkTableField = new GridField('Join Us', null, SocialNetworkingLinksDataObject::get(), GridFieldConfig_RecordEditor::create());
55
        //$socialNetworkTableField->setPermissions(array("edit", "add", "delete", "view"));
56
        if ($this->owner->AlwaysIncludeShareThisLinks) {
57
            $defaultShareThisCheckbox = new HiddenField('IncludeByDefaultShareThisLinks', true);
58
        } else {
59
            $defaultShareThisCheckbox = new CheckboxField('IncludeByDefaultShareThisLinks', 'Show links on every page by default '.$individualPageNoteWith);
60
        }
61
        if ($this->owner->AlwaysIncludeSocialNetworkingLinks) {
62
            $defaultSocialNetworkingCheckbox = new HiddenField('IncludeByDefaultSocialNetworkingLinks', true);
63
        } else {
64
            $defaultSocialNetworkingCheckbox = new CheckboxField('IncludeByDefaultSocialNetworkingLinks', 'Include on every page by default '.$individualPageNoteWith);
65
        }
66
        $fields->addFieldToTab(
67
            'Root.SocialMedia',
68
            new TabSet(
69
                'SocialNetworkingOptions',
70
                new Tab(
71
                    'ShareThis',
72
                    new CheckboxField('AlwaysIncludeShareThisLinks', 'Show links on every page '.$individualPageNoteWithout),
73
                    $defaultShareThisCheckbox,
74
                    new CheckboxField('ShareThisAllInOne', 'Add a \'share\' all-in-one button'),
75
                    new LiteralField('shareThisExtra', $shareThisExtra),
76
                    $shareThisTableField
77
                ),
78
                new Tab(
79
                    'JoinUs',
80
                    new CheckboxField('AlwaysIncludeSocialNetworkingLinks', 'Show links on every page '.$individualPageNoteWithout),
81
                    $defaultSocialNetworkingCheckbox,
82
                    new LiteralField('socialNetworkExtra', $socialNetworkExtra),
83
                    $socialNetworkTableField
84
                )
85
            )
86
        );
87
        return $fields;
88
    }
89
90
    public function CanEditShareIcons()
91
    {
92
        if (class_exists('DataObjectSorterDOD')) {
93
            $obj = singleton(ShareThisDataObject::class);
94
            if ($obj->hasExtension('DataObjectSorterDOD')) {
95
                return true;
96
            } else {
97
                USER_ERROR('You have installed DataObjectSorterDOD, but you have not extended ShareThisDataObject with DataObjectSorterDOD, see sharethis/_config.php for more information.', E_USER_NOTICE);
98
            }
99
        } else {
100
            USER_ERROR('You need to install the DataObjectSorter module (see sharethis/README or sharethis/_config.php for more information)', E_USER_NOTICE);
101
        }
102
    }
103
}
104