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