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