@@ -1,193 +1,193 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | class Block extends DataObject { |
4 | - protected static $db = array ( |
|
5 | - 'SortOrder' => 'Int', |
|
6 | - 'Title' => 'Varchar(64)', |
|
7 | - 'TitleWrapper' => 'Enum("h2,h3,h4,h5,h6")', |
|
8 | - 'hideTitle' => 'Boolean', |
|
9 | - 'showBlockbyClass' => 'Boolean', |
|
10 | - 'Description' => 'Varchar(128)', |
|
11 | - 'MemberVisibility' => 'Varchar(255)', |
|
12 | - 'shownInClass' => 'Text' |
|
13 | - ); |
|
4 | + protected static $db = array ( |
|
5 | + 'SortOrder' => 'Int', |
|
6 | + 'Title' => 'Varchar(64)', |
|
7 | + 'TitleWrapper' => 'Enum("h2,h3,h4,h5,h6")', |
|
8 | + 'hideTitle' => 'Boolean', |
|
9 | + 'showBlockbyClass' => 'Boolean', |
|
10 | + 'Description' => 'Varchar(128)', |
|
11 | + 'MemberVisibility' => 'Varchar(255)', |
|
12 | + 'shownInClass' => 'Text' |
|
13 | + ); |
|
14 | 14 | |
15 | - protected static $many_many = array ( |
|
16 | - 'Pages' => 'Page' |
|
17 | - ); |
|
15 | + protected static $many_many = array ( |
|
16 | + 'Pages' => 'Page' |
|
17 | + ); |
|
18 | 18 | |
19 | - protected static $create_table_options = array( |
|
20 | - 'MySQLDatabase' => 'ENGINE=MyISAM' |
|
19 | + protected static $create_table_options = array( |
|
20 | + 'MySQLDatabase' => 'ENGINE=MyISAM' |
|
21 | 21 | ); |
22 | 22 | |
23 | - protected static $extensions = array ( |
|
24 | - 'StandardPermissions' |
|
25 | - ); |
|
23 | + protected static $extensions = array ( |
|
24 | + 'StandardPermissions' |
|
25 | + ); |
|
26 | 26 | |
27 | - protected static $summary_fields = array( |
|
28 | - 'BlockType', |
|
29 | - 'Title', |
|
30 | - 'Description', |
|
31 | - 'shownOn', |
|
32 | - 'VisibleTo' |
|
33 | - ); |
|
27 | + protected static $summary_fields = array( |
|
28 | + 'BlockType', |
|
29 | + 'Title', |
|
30 | + 'Description', |
|
31 | + 'shownOn', |
|
32 | + 'VisibleTo' |
|
33 | + ); |
|
34 | 34 | |
35 | - protected static $field_labels = array( |
|
36 | - 'BlockType' => 'Block type', |
|
37 | - 'shownOn' => 'is shown on', |
|
38 | - 'VisibleTo' => 'Visible to' |
|
39 | - ); |
|
35 | + protected static $field_labels = array( |
|
36 | + 'BlockType' => 'Block type', |
|
37 | + 'shownOn' => 'is shown on', |
|
38 | + 'VisibleTo' => 'Visible to' |
|
39 | + ); |
|
40 | 40 | |
41 | - public function VisibleTo() { |
|
42 | - if (strlen(trim($this->MemberVisibility)) > 0) { |
|
43 | - $lists = 'Group: ' . str_replace(',','<br />Group: ', $this->MemberVisibility); |
|
44 | - }else{ |
|
45 | - $lists = '<em><All></em>'; |
|
46 | - } |
|
47 | - |
|
48 | - return new LiteralField('VisibleTo',$lists); |
|
49 | - } |
|
41 | + public function VisibleTo() { |
|
42 | + if (strlen(trim($this->MemberVisibility)) > 0) { |
|
43 | + $lists = 'Group: ' . str_replace(',','<br />Group: ', $this->MemberVisibility); |
|
44 | + }else{ |
|
45 | + $lists = '<em><All></em>'; |
|
46 | + } |
|
47 | + |
|
48 | + return new LiteralField('VisibleTo',$lists); |
|
49 | + } |
|
50 | 50 | |
51 | - public function BlockType() { |
|
52 | - return $this->singular_name(); |
|
53 | - } |
|
51 | + public function BlockType() { |
|
52 | + return $this->singular_name(); |
|
53 | + } |
|
54 | 54 | |
55 | - public function shownOn() { |
|
56 | - if ($this->showBlockbyClass) { |
|
57 | - if (strlen(trim($this->shownInClass)) > 0) { |
|
58 | - $lists = 'Type: ' . str_replace(',','<br />Type: ', $this->shownInClass); |
|
59 | - }else{ |
|
60 | - $lists = '<em><not assigned></em>'; |
|
61 | - } |
|
62 | - }else{ |
|
63 | - if ($this->Pages()->count() > 0) { |
|
64 | - $lists = 'Page: ' . implode('<br />Page: ', $this->Pages()->column('Title')); |
|
65 | - }else{ |
|
66 | - $lists = '<em><not assigned></em>'; |
|
67 | - } |
|
68 | - } |
|
69 | - return new LiteralField('shownOn',$lists); |
|
70 | - } |
|
55 | + public function shownOn() { |
|
56 | + if ($this->showBlockbyClass) { |
|
57 | + if (strlen(trim($this->shownInClass)) > 0) { |
|
58 | + $lists = 'Type: ' . str_replace(',','<br />Type: ', $this->shownInClass); |
|
59 | + }else{ |
|
60 | + $lists = '<em><not assigned></em>'; |
|
61 | + } |
|
62 | + }else{ |
|
63 | + if ($this->Pages()->count() > 0) { |
|
64 | + $lists = 'Page: ' . implode('<br />Page: ', $this->Pages()->column('Title')); |
|
65 | + }else{ |
|
66 | + $lists = '<em><not assigned></em>'; |
|
67 | + } |
|
68 | + } |
|
69 | + return new LiteralField('shownOn',$lists); |
|
70 | + } |
|
71 | 71 | |
72 | - public function getCMSFields() { |
|
73 | - $fields = parent::getCMSFields(); |
|
74 | - $fields->removeFieldFromTab('Root', 'Pages'); |
|
75 | - $fields->removeFieldsFromTab('Root.Main', array( |
|
76 | - 'SortOrder', |
|
77 | - 'showBlockbyClass', |
|
78 | - 'shownInClass', |
|
79 | - 'MemberVisibility' |
|
80 | - )); |
|
81 | - |
|
82 | - $memberGroups = Group::get(); |
|
83 | - $sourcemap = $memberGroups->map('Code', 'Title'); |
|
84 | - $source = array( |
|
85 | - 'anonymous' => 'Anonymous visitors' |
|
86 | - ); |
|
87 | - foreach ($sourcemap as $mapping => $key) { |
|
88 | - $source[$mapping] = $key; |
|
89 | - } |
|
90 | - |
|
91 | - $memberVisibility = new CheckboxSetField( |
|
92 | - $name = "MemberVisibility", |
|
93 | - $title = "Show block for specific groups", |
|
94 | - $source |
|
95 | - ); |
|
96 | - |
|
97 | - $memberVisibility->setDescription('Show this block only for the selected group(s). If you select no groups, the block will be visible to all members.'); |
|
98 | - |
|
99 | - $availabelClasses = $this->availableClasses(); |
|
100 | - $inClass = new CheckboxSetField( |
|
101 | - $name = "shownInClass", |
|
102 | - $title = "Show block for specific content types", |
|
103 | - $availabelClasses |
|
104 | - ); |
|
105 | - |
|
106 | - $filterSelector = OptionsetField::create( |
|
107 | - 'showBlockbyClass', |
|
108 | - 'Choose filter set', |
|
109 | - array( |
|
110 | - '0' => 'by page', |
|
111 | - '1' => 'by page/data type' |
|
112 | - ) |
|
113 | - )->setDescription('<p><br /><strong>by page</strong>: block will be displayed in the selected page(s)<br /><strong>by page/data type</strong>: block will be displayed on the pages created with the particular page/data type. e.g. is <strong>"InternalPage"</strong> is picked, the block will be displayed, and will ONLY be displayed on all <strong>Internal Pages</strong></p>'); |
|
114 | - |
|
115 | - $availablePages = Page::get()->exclude('ClassName', array( |
|
116 | - 'ErrorPage', |
|
117 | - 'RedirectorPage', |
|
118 | - 'VirtualPage' |
|
119 | - )); |
|
120 | - $pageSelector = new CheckboxSetField( |
|
121 | - $name = "Pages", |
|
122 | - $title = "Show on Page(s)", |
|
123 | - $availablePages->map('ID','Title') |
|
124 | - ); |
|
125 | - |
|
126 | - |
|
127 | - if ($this->canConfigPageAndType(Member::currentUser())) { |
|
128 | - $fields->addFieldsToTab('Root.VisibilitySettings', array( |
|
129 | - $filterSelector, |
|
130 | - $pageSelector, |
|
131 | - $inClass |
|
132 | - )); |
|
133 | - } |
|
134 | - |
|
135 | - if ($this->canConfigMemberVisibility(Member::currentUser())) { |
|
136 | - $fields->addFieldToTab('Root.VisibilitySettings', $memberVisibility); |
|
137 | - } |
|
72 | + public function getCMSFields() { |
|
73 | + $fields = parent::getCMSFields(); |
|
74 | + $fields->removeFieldFromTab('Root', 'Pages'); |
|
75 | + $fields->removeFieldsFromTab('Root.Main', array( |
|
76 | + 'SortOrder', |
|
77 | + 'showBlockbyClass', |
|
78 | + 'shownInClass', |
|
79 | + 'MemberVisibility' |
|
80 | + )); |
|
81 | + |
|
82 | + $memberGroups = Group::get(); |
|
83 | + $sourcemap = $memberGroups->map('Code', 'Title'); |
|
84 | + $source = array( |
|
85 | + 'anonymous' => 'Anonymous visitors' |
|
86 | + ); |
|
87 | + foreach ($sourcemap as $mapping => $key) { |
|
88 | + $source[$mapping] = $key; |
|
89 | + } |
|
90 | + |
|
91 | + $memberVisibility = new CheckboxSetField( |
|
92 | + $name = "MemberVisibility", |
|
93 | + $title = "Show block for specific groups", |
|
94 | + $source |
|
95 | + ); |
|
96 | + |
|
97 | + $memberVisibility->setDescription('Show this block only for the selected group(s). If you select no groups, the block will be visible to all members.'); |
|
98 | + |
|
99 | + $availabelClasses = $this->availableClasses(); |
|
100 | + $inClass = new CheckboxSetField( |
|
101 | + $name = "shownInClass", |
|
102 | + $title = "Show block for specific content types", |
|
103 | + $availabelClasses |
|
104 | + ); |
|
105 | + |
|
106 | + $filterSelector = OptionsetField::create( |
|
107 | + 'showBlockbyClass', |
|
108 | + 'Choose filter set', |
|
109 | + array( |
|
110 | + '0' => 'by page', |
|
111 | + '1' => 'by page/data type' |
|
112 | + ) |
|
113 | + )->setDescription('<p><br /><strong>by page</strong>: block will be displayed in the selected page(s)<br /><strong>by page/data type</strong>: block will be displayed on the pages created with the particular page/data type. e.g. is <strong>"InternalPage"</strong> is picked, the block will be displayed, and will ONLY be displayed on all <strong>Internal Pages</strong></p>'); |
|
114 | + |
|
115 | + $availablePages = Page::get()->exclude('ClassName', array( |
|
116 | + 'ErrorPage', |
|
117 | + 'RedirectorPage', |
|
118 | + 'VirtualPage' |
|
119 | + )); |
|
120 | + $pageSelector = new CheckboxSetField( |
|
121 | + $name = "Pages", |
|
122 | + $title = "Show on Page(s)", |
|
123 | + $availablePages->map('ID','Title') |
|
124 | + ); |
|
125 | + |
|
126 | + |
|
127 | + if ($this->canConfigPageAndType(Member::currentUser())) { |
|
128 | + $fields->addFieldsToTab('Root.VisibilitySettings', array( |
|
129 | + $filterSelector, |
|
130 | + $pageSelector, |
|
131 | + $inClass |
|
132 | + )); |
|
133 | + } |
|
134 | + |
|
135 | + if ($this->canConfigMemberVisibility(Member::currentUser())) { |
|
136 | + $fields->addFieldToTab('Root.VisibilitySettings', $memberVisibility); |
|
137 | + } |
|
138 | 138 | |
139 | - return $fields; |
|
140 | - } |
|
139 | + return $fields; |
|
140 | + } |
|
141 | 141 | |
142 | - public function availableClasses() { |
|
143 | - $Classes = array_diff( |
|
144 | - ClassInfo::subclassesFor('Page'), |
|
145 | - ClassInfo::subclassesFor('RedirectorPage'), |
|
146 | - ClassInfo::subclassesFor('VirtualPage') |
|
147 | - ); |
|
148 | - return $Classes; |
|
149 | - } |
|
142 | + public function availableClasses() { |
|
143 | + $Classes = array_diff( |
|
144 | + ClassInfo::subclassesFor('Page'), |
|
145 | + ClassInfo::subclassesFor('RedirectorPage'), |
|
146 | + ClassInfo::subclassesFor('VirtualPage') |
|
147 | + ); |
|
148 | + return $Classes; |
|
149 | + } |
|
150 | 150 | |
151 | - public function forTemplate() { |
|
152 | - if ($this->canDisplayMemberCheck()) { |
|
153 | - return $this->renderWith(array($this->getClassName(), 'BaseBlock')); |
|
154 | - } |
|
151 | + public function forTemplate() { |
|
152 | + if ($this->canDisplayMemberCheck()) { |
|
153 | + return $this->renderWith(array($this->getClassName(), 'BaseBlock')); |
|
154 | + } |
|
155 | 155 | |
156 | - return false; |
|
157 | - } |
|
156 | + return false; |
|
157 | + } |
|
158 | 158 | |
159 | - public function canDisplayMemberCheck() { |
|
160 | - $rawVisibility = $this->MemberVisibility; |
|
161 | - |
|
162 | - if (empty($rawVisibility)) { |
|
163 | - return true; |
|
164 | - } |
|
165 | - |
|
166 | - $visibility = explode(',', $rawVisibility); |
|
167 | - $member = Member::currentUser(); |
|
168 | - |
|
169 | - if (!$member && in_array('anonymous', $visibility)) { |
|
170 | - return true; |
|
171 | - } |
|
172 | - |
|
173 | - if ($member) { |
|
174 | - $memberGroups = $member->Groups()->column('Code'); |
|
175 | - foreach ($memberGroups as $memberGroup) { |
|
176 | - if (in_array($memberGroup, $visibility)) { |
|
177 | - return true; |
|
178 | - } |
|
179 | - } |
|
180 | - } |
|
181 | - |
|
182 | - return false; |
|
183 | - } |
|
159 | + public function canDisplayMemberCheck() { |
|
160 | + $rawVisibility = $this->MemberVisibility; |
|
161 | + |
|
162 | + if (empty($rawVisibility)) { |
|
163 | + return true; |
|
164 | + } |
|
165 | + |
|
166 | + $visibility = explode(',', $rawVisibility); |
|
167 | + $member = Member::currentUser(); |
|
168 | + |
|
169 | + if (!$member && in_array('anonymous', $visibility)) { |
|
170 | + return true; |
|
171 | + } |
|
172 | + |
|
173 | + if ($member) { |
|
174 | + $memberGroups = $member->Groups()->column('Code'); |
|
175 | + foreach ($memberGroups as $memberGroup) { |
|
176 | + if (in_array($memberGroup, $visibility)) { |
|
177 | + return true; |
|
178 | + } |
|
179 | + } |
|
180 | + } |
|
181 | + |
|
182 | + return false; |
|
183 | + } |
|
184 | 184 | |
185 | - public function frontendEditable() { |
|
186 | - $member = Member::currentUser(); |
|
187 | - return $this->canEdit($member); |
|
188 | - } |
|
185 | + public function frontendEditable() { |
|
186 | + $member = Member::currentUser(); |
|
187 | + return $this->canEdit($member); |
|
188 | + } |
|
189 | 189 | |
190 | - public function Type2Class() { |
|
191 | - return strtolower(str_replace(' ', '-', $this->singular_name())); |
|
192 | - } |
|
190 | + public function Type2Class() { |
|
191 | + return strtolower(str_replace(' ', '-', $this->singular_name())); |
|
192 | + } |
|
193 | 193 | } |
194 | 194 | \ No newline at end of file |