Completed
Push — master ( 6044c4...808032 )
by Nicolaas
02:13
created

ContactListPage::i18n_singular_name()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
4
class ContactListPage extends Page
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...
5
{
6
    private static $icon = 'contact_list/images/treeicons/ContactListPage';
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...
7
8
    /**
9
     * @var String Description of the class functionality, typically shown to a user
10
     * when selecting which page type to create. Translated through {@link provideI18nEntities()}.
11
     */
12
    private static $description = "Shows a list of contacts";
0 ignored issues
show
Unused Code introduced by
The property $description 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...
13
14
    /**
15
     * standard SS variable
16
     * @Var String
17
     */
18
    private static $singular_name = 'Contact List Page';
0 ignored issues
show
Unused Code introduced by
The property $singular_name 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...
19
20
    public function i18n_singular_name()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
21
    {
22
        return $this->Config()->get('singular_name');
23
    }
24
25
    /**
26
     * standard SS variable
27
     * @Var String
28
     */
29
    private static $plural_name = 'Contact List Pages';
0 ignored issues
show
Unused Code introduced by
The property $plural_name 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...
30
31
    public function i18n_plural_name()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
32
    {
33
        return $this->Config()->get('plural_name');
34
    }
35
36
    public function canCreate($member = null)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
37
    {
38
        if (ContactListPage::get()->count() == 0) {
39
            return parent::canCreate($member);
40
        }
41
        return false;
42
    }
43
44
    private static $contacts_list_cache_key = null;
45
46
    public function ContactsListCacheKey()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
47
    {
48
        if (!self::$contacts_list_cache_key) {
49
            self::$contacts_list_cache_key = "CL_".Contact::get()->max('LastEdited') . "_" . Contact::get()->count();
50
        }
51
        return self::$contacts_list_cache_key;
52
    }
53
54
    /**
55
     * CMS Fields
56
     * @return FieldList
57
     */
58
    public function getCMSFields()
59
    {
60
        $fields = parent::getCMSFields();
61
        $fields->addFieldsToTab(
62
            'Root.Contacts',
63
            GridField::create(
64
                'Contacts',
65
                'Contacts',
66
                Contact::get(),
67
                GridFieldConfig_RecordEditor::create()
68
            )
69
        );
70
        return $fields;
71
    }
72
73
}
74
75
class ContactListPage_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...
76
{
77
    public function init()
78
    {
79
        parent::init();
80
        TableFilterSortAPI::include_requirements();
81
    }
82
83
    public function Contacts()
84
    {
85
        return Contact::get()->filter(array('IsVisible' => 1));
86
    }
87
}
88