1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class MembersOnlyPage extends Page |
4
|
|
|
{ |
5
|
|
|
private static $add_action = 'Members Only Page'; |
|
|
|
|
6
|
|
|
|
7
|
|
|
private static $icon = 'mysite/images/treeicons/MembersOnlyPage'; |
|
|
|
|
8
|
|
|
|
9
|
|
|
private static $default_parent = 'MembersOnlyPage'; |
|
|
|
|
10
|
|
|
|
11
|
|
|
private static $allowed_children = array("MembersOnlyPage"); |
|
|
|
|
12
|
|
|
|
13
|
|
|
private static $group_code = "intranet-users"; |
14
|
|
|
public static function set_group_code($v) |
15
|
|
|
{ |
16
|
|
|
self::$group_code = $v; |
17
|
|
|
} |
18
|
|
|
public static function get_group_code() |
19
|
|
|
{ |
20
|
|
|
return self::$group_code; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
private static $group_name = "intranet users"; |
24
|
|
|
public static function set_group_name($v) |
25
|
|
|
{ |
26
|
|
|
self::$group_name = $v; |
27
|
|
|
} |
28
|
|
|
public static function get_group_name() |
29
|
|
|
{ |
30
|
|
|
return self::$group_name; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
private static $permission_code = "INTRANET_USERS"; |
34
|
|
|
public static function set_permission_code($v) |
35
|
|
|
{ |
36
|
|
|
self::$permission_code = $v; |
37
|
|
|
} |
38
|
|
|
public static function get_permission_code() |
39
|
|
|
{ |
40
|
|
|
return self::$permission_code; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
private static $defaults = array( |
|
|
|
|
44
|
|
|
"ProvideComments" => 1, |
45
|
|
|
"ShowInSearch" => 0 |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
public function getCMSFields() |
50
|
|
|
{ |
51
|
|
|
$fields = parent::getCMSFields(); |
52
|
|
|
return $fields; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function canView($member = null) |
56
|
|
|
{ |
57
|
|
|
if ($member = Member::currentUser()) { |
58
|
|
|
if ($member->inGroup("ADMIN") || Permission::checkMember($member, self::$permission_code)) { |
59
|
|
|
return true; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
return false; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getShowInMenus() |
66
|
|
|
{ |
67
|
|
|
return $this->canView(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function ShowInMenus() |
71
|
|
|
{ |
72
|
|
|
return $this->canView(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function getShowInSearch() |
76
|
|
|
{ |
77
|
|
|
return $this->canView(); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function ShowInSearch() |
81
|
|
|
{ |
82
|
|
|
return $this->canView(); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function requireDefaultRecords() |
86
|
|
|
{ |
87
|
|
|
parent::requireDefaultRecords(); |
88
|
|
|
$intranetGroup = Group::get()->filter(array("Code" => $this->Config()->get("group_code")))->first(); |
89
|
|
|
if ($intranetGroup && $intranetGroup->exists()) { |
|
|
|
|
90
|
|
|
//do nothing |
91
|
|
|
} else { |
92
|
|
|
$intranetGroup = new Group(); |
93
|
|
|
DB::alteration_message($this->Config()->get("group_name").' group created', "created"); |
94
|
|
|
} |
95
|
|
|
if ($intranetGroup) { |
96
|
|
|
$intranetGroup->Code = $this->Config()->get("group_code"); |
97
|
|
|
$intranetGroup->Title = $this->Config()->get("group_name"); |
98
|
|
|
$intranetGroup->write(); |
99
|
|
|
Permission::grant($intranetGroup->ID, $this->Config()->get("permission_code")); |
100
|
|
|
if (DB::query("
|
101
|
|
|
SELECT *
|
102
|
|
|
FROM Permission
|
103
|
|
|
WHERE \"GroupID\" = '".$intranetGroup->ID."'
|
104
|
|
|
AND \"Code\" LIKE '".$this->Config()->get("permission_code")."'")->numRecords() == 0 |
105
|
|
|
) { |
106
|
|
|
Permission::grant($intranetGroup->ID, $this->Config()->get("permission_code")); |
107
|
|
|
DB::alteration_message($this->Config()->get("group_name").' permissions granted', "created"); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
class MembersOnlyPage_Controller extends Page_Controller |
114
|
|
|
{ |
115
|
|
|
public function init() |
116
|
|
|
{ |
117
|
|
|
parent::init(); |
118
|
|
|
Requirements::themedCSS("MembersOnlyPage", "membersonlypages"); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.