1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
class ContactListPage extends Page |
|
|
|
|
5
|
|
|
{ |
6
|
|
|
private static $icon = 'contact_list/images/treeicons/ContactListPage'; |
|
|
|
|
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"; |
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* standard SS variable |
16
|
|
|
* @Var String |
17
|
|
|
*/ |
18
|
|
|
private static $singular_name = 'Contact List Page'; |
|
|
|
|
19
|
|
|
|
20
|
|
|
public function i18n_singular_name() |
|
|
|
|
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'; |
|
|
|
|
30
|
|
|
|
31
|
|
|
public function i18n_plural_name() |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
return $this->Config()->get('plural_name'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function canCreate($member = null) |
|
|
|
|
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() |
|
|
|
|
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
|
|
|
class ContactListPage_Controller extends Page_Controller |
|
|
|
|
75
|
|
|
{ |
76
|
|
|
public function init() |
77
|
|
|
{ |
78
|
|
|
parent::init(); |
79
|
|
|
TableFilterSortAPI::include_requirements( |
80
|
|
|
$tableSelector = '.tfs-holder', |
81
|
|
|
$blockArray = array('TableFilterSort.theme'), |
82
|
|
|
$jqueryLocation = '', |
83
|
|
|
$includeInPage = true, |
84
|
|
|
$jsSettings = '{serverConnectionURL: ""}' |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function Contacts() |
89
|
|
|
{ |
90
|
|
|
return Contact::get()->filter(array('IsVisible' => 1)); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.