Completed
Push — master ( 6815df...d4e03c )
by Jason
05:43
created

AccordionBlock::singular_name()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
class AccordionBlock extends Block
4
{
5
    /**
6
     * @return string
7
     */
8 9
    public function singular_name()
9
    {
10 9
        return _t('AccordionBlock.SINGULARNAME', 'Accordion Block');
11
    }
12
13
    /**
14
     * @return string
15
     */
16
    public function plural_name()
17
    {
18
        return _t('AccordionBlock.PLURALNAME', 'Accordion Blocks');
19
    }
20
21
    /**
22
     * @var array
23
     */
24
    private static $db = array(
25
        'Content' => 'HTMLText',
26
        'SortOrder' => 'Int',
27
    );
28
29
    /**
30
     * @var array
31
     */
32
    private static $has_many = array(
33
        'Panels' => 'AccordionPanel',
34
    );
35
36
    /**
37
     * @return FieldList
38
     */
39 1 View Code Duplication
    public function getCMSFields()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
    {
41 1
        $fields = parent::getCMSFields();
42
43 1
        $fields->removeByName(array(
44 1
            'SortOrder',
45 1
            'Panels',
46 1
        ));
47
48 1
        $config = GridFieldConfig_RecordEditor::create();
49 1
        if (class_exists('GridFieldOrderableRows')) {
50 1
            $config->addComponent(new GridFieldOrderableRows());
51 1
        }
52 1
        $config->removeComponentsByType('GridFieldAddExistingAutocompleter');
53 1
        $config->removeComponentsByType('GridFieldDeleteAction');
54 1
        $config->addComponent(new GridFieldDeleteAction(false));
55
56 1
        if ($this->ID) {
57 1
            $fields->addFieldsToTab('Root.Panels', array(
58 1
                GridField::create('Panels', 'Accordion Panels', $this->Panels()->sort('Sort'), $config),
0 ignored issues
show
Documentation Bug introduced by
The method Panels does not exist on object<AccordionBlock>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
59 1
            ));
60 1
        }
61
62 1
        return $fields;
63
    }
64
65
    /**
66
     * @return DataList
67
     */
68 1
    public function getPanelList()
69
    {
70 1
        if ($this->Panels()->exists()) {
0 ignored issues
show
Documentation Bug introduced by
The method Panels does not exist on object<AccordionBlock>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
71 1
            return $this->Panels()->sort('Sort');
0 ignored issues
show
Documentation Bug introduced by
The method Panels does not exist on object<AccordionBlock>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
72
        }
73
        return $this->Panels();
0 ignored issues
show
Documentation Bug introduced by
The method Panels does not exist on object<AccordionBlock>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
74
    }
75
}
76
77
class AccordionBlock_Controller extends Block_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...
78
{
79
    /**
80
     * @var string
81
     */
82
    private static $accordion_class = 'accordion-block';
0 ignored issues
show
Unused Code introduced by
The property $accordion_class 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...
83
84
    /**
85
     *
86
     */
87
    public function init()
88
    {
89
        $class = $this->AccordionClass();
90
        Requirements::javascript(THIRDPARTY_DIR . '/jquery-ui/jquery-ui.js');
91
        Requirements::customScript('
92
            $(function() {
93
                $( ".' . $class . '" ).accordion({
94
                    header: ".accord-header",
95
                    collapsible: true, heightStyle: "content"
96
                });
97
            });
98
        ');
99
    }
100
101
    /**
102
     * @return array
103
     */
104
    public function AccordionClass()
105
    {
106
        return Config::inst()->get('AccordionBlock_Controller', 'accordion_class');
107
    }
108
}