Completed
Push — master ( 5dcbd9...ad771e )
by Leo
03:21
created
code/Block.php 1 patch
Indentation   +201 added lines, -201 removed lines patch added patch discarded remove patch
@@ -1,183 +1,183 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 class Block extends DataObject {
3
-	protected static $db = array (
4
-		'SortOrder'			=>	'Int',
5
-		'Title'				=>	'Varchar(64)',
6
-		'TitleWrapper'		=>	'Enum("h2,h3,h4,h5,h6")',
7
-		'hideTitle'			=>	'Boolean',
8
-		'showBlockbyClass'	=>	'Boolean',
9
-		'Description'		=>	'Varchar(128)',
10
-		'MemberVisibility'	=>	'Varchar(255)',
11
-		'shownInClass'		=>	'Text',
12
-		'addMarginTop'		=>	'Boolean',
13
-		'addMarginBottom'	=>	'Boolean',
14
-		'addPaddingTop'		=>	'Boolean',
15
-		'addPaddingBottom'	=>	'Boolean'
16
-	);
3
+    protected static $db = array (
4
+        'SortOrder'			=>	'Int',
5
+        'Title'				=>	'Varchar(64)',
6
+        'TitleWrapper'		=>	'Enum("h2,h3,h4,h5,h6")',
7
+        'hideTitle'			=>	'Boolean',
8
+        'showBlockbyClass'	=>	'Boolean',
9
+        'Description'		=>	'Varchar(128)',
10
+        'MemberVisibility'	=>	'Varchar(255)',
11
+        'shownInClass'		=>	'Text',
12
+        'addMarginTop'		=>	'Boolean',
13
+        'addMarginBottom'	=>	'Boolean',
14
+        'addPaddingTop'		=>	'Boolean',
15
+        'addPaddingBottom'	=>	'Boolean'
16
+    );
17 17
 	
18
-	protected static $many_many = array (
19
-		'Pages'				=>	'Page'
20
-	);
18
+    protected static $many_many = array (
19
+        'Pages'				=>	'Page'
20
+    );
21 21
 	
22
-	protected static $default_sort = array(
23
-		'SortOrder'			=>	'ASC',
24
-		'ID'					=>	'DESC'
25
-	);
22
+    protected static $default_sort = array(
23
+        'SortOrder'			=>	'ASC',
24
+        'ID'					=>	'DESC'
25
+    );
26 26
 		
27
-	protected static $create_table_options = array(
28
-		'MySQLDatabase'		=> 'ENGINE=MyISAM'
27
+    protected static $create_table_options = array(
28
+        'MySQLDatabase'		=> 'ENGINE=MyISAM'
29 29
     );
30 30
 	
31
-	protected static $extensions = array (
32
-		'StandardPermissions'
33
-	);
31
+    protected static $extensions = array (
32
+        'StandardPermissions'
33
+    );
34 34
 	
35
-	protected static $summary_fields = array(
36
-		'BlockType',
37
-		'Title', 
38
-		'Description',
39
-		'shownOn',
40
-		'VisibleTo',
41
-		'Published'
42
-	);
35
+    protected static $summary_fields = array(
36
+        'BlockType',
37
+        'Title', 
38
+        'Description',
39
+        'shownOn',
40
+        'VisibleTo',
41
+        'Published'
42
+    );
43 43
 	
44
-	protected static $field_labels = array(
45
-		'BlockType'			=>	'Block type',
46
-		'shownOn'			=>	'is shown on',
47
-		'VisibleTo'			=>	'Visible to'
48
-	);
44
+    protected static $field_labels = array(
45
+        'BlockType'			=>	'Block type',
46
+        'shownOn'			=>	'is shown on',
47
+        'VisibleTo'			=>	'Visible to'
48
+    );
49 49
 	
50
-	public function VisibleTo() {
51
-		if (strlen(trim($this->MemberVisibility)) > 0) {
52
-			$lists = 'Group: ' . str_replace(',','<br />Group: ', $this->MemberVisibility);
53
-		}else{
54
-			$lists = '<em>&lt;All&gt;</em>';
55
-		}
50
+    public function VisibleTo() {
51
+        if (strlen(trim($this->MemberVisibility)) > 0) {
52
+            $lists = 'Group: ' . str_replace(',','<br />Group: ', $this->MemberVisibility);
53
+        }else{
54
+            $lists = '<em>&lt;All&gt;</em>';
55
+        }
56 56
 		
57
-		return new LiteralField('VisibleTo',$lists);
58
-	}
57
+        return new LiteralField('VisibleTo',$lists);
58
+    }
59 59
 	
60
-	public function BlockType() {
61
-		return $this->singular_name();
62
-	}
60
+    public function BlockType() {
61
+        return $this->singular_name();
62
+    }
63 63
 	
64
-	public function shownOn() {
65
-		if ($this->showBlockbyClass) {
66
-			if (strlen(trim($this->shownInClass)) > 0) {
67
-				$lists = 'Type: ' . str_replace(',','<br />Type: ', $this->shownInClass);
68
-			}else{
69
-				$lists = '<em>&lt;not assigned&gt;</em>';
70
-			}
71
-		}else{
72
-			if ($this->Pages()->count() > 0) {
73
-				$lists = 'Page: ' . implode('<br />Page: ', $this->Pages()->column('Title'));
74
-			}else{
75
-				$lists = '<em>&lt;not assigned&gt;</em>';
76
-			}
77
-		}
78
-		return new LiteralField('shownOn',$lists);
79
-	}
64
+    public function shownOn() {
65
+        if ($this->showBlockbyClass) {
66
+            if (strlen(trim($this->shownInClass)) > 0) {
67
+                $lists = 'Type: ' . str_replace(',','<br />Type: ', $this->shownInClass);
68
+            }else{
69
+                $lists = '<em>&lt;not assigned&gt;</em>';
70
+            }
71
+        }else{
72
+            if ($this->Pages()->count() > 0) {
73
+                $lists = 'Page: ' . implode('<br />Page: ', $this->Pages()->column('Title'));
74
+            }else{
75
+                $lists = '<em>&lt;not assigned&gt;</em>';
76
+            }
77
+        }
78
+        return new LiteralField('shownOn',$lists);
79
+    }
80 80
 	
81
-	public function getCMSFields() {
82
-		$fields = parent::getCMSFields();
83
-		$fields->removeFieldFromTab('Root', 'Pages');
84
-		$fields->removeFieldsFromTab('Root.Main', array(
85
-			'SortOrder',
86
-			'showBlockbyClass',
87
-			'shownInClass',
88
-			'MemberVisibility'
89
-		));
81
+    public function getCMSFields() {
82
+        $fields = parent::getCMSFields();
83
+        $fields->removeFieldFromTab('Root', 'Pages');
84
+        $fields->removeFieldsFromTab('Root.Main', array(
85
+            'SortOrder',
86
+            'showBlockbyClass',
87
+            'shownInClass',
88
+            'MemberVisibility'
89
+        ));
90 90
 		
91
-		$fields->addFieldToTab('Root.Main', LiteralField::create('Status', 'Published: ' . $this->Published()), 'Title');
91
+        $fields->addFieldToTab('Root.Main', LiteralField::create('Status', 'Published: ' . $this->Published()), 'Title');
92 92
 		
93
-		$memberGroups = Group::get();
94
-		$sourcemap = $memberGroups->map('Code', 'Title');
95
-		$source = array(
96
-			'anonymous'		=>	'Anonymous visitors'
97
-		);
98
-		foreach ($sourcemap as $mapping => $key) {
99
-			$source[$mapping] = $key;
100
-		}
93
+        $memberGroups = Group::get();
94
+        $sourcemap = $memberGroups->map('Code', 'Title');
95
+        $source = array(
96
+            'anonymous'		=>	'Anonymous visitors'
97
+        );
98
+        foreach ($sourcemap as $mapping => $key) {
99
+            $source[$mapping] = $key;
100
+        }
101 101
 		
102
-		$memberVisibility = new CheckboxSetField(
103
-			$name = "MemberVisibility",
104
-			$title = "Show block for specific groups",
105
-			$source
106
-		);
102
+        $memberVisibility = new CheckboxSetField(
103
+            $name = "MemberVisibility",
104
+            $title = "Show block for specific groups",
105
+            $source
106
+        );
107 107
 		
108
-		$memberVisibility->setDescription('Show this block only for the selected group(s). If you select no groups, the block will be visible to all members.');
108
+        $memberVisibility->setDescription('Show this block only for the selected group(s). If you select no groups, the block will be visible to all members.');
109 109
 		
110
-		$availabelClasses = $this->availableClasses();
111
-		$inClass = new CheckboxSetField(
112
-			$name = "shownInClass",
113
-			$title = "Show block for specific content types",
114
-			$availabelClasses
115
-		);
110
+        $availabelClasses = $this->availableClasses();
111
+        $inClass = new CheckboxSetField(
112
+            $name = "shownInClass",
113
+            $title = "Show block for specific content types",
114
+            $availabelClasses
115
+        );
116 116
 		
117
-		$filterSelector = OptionsetField::create(
118
-			'showBlockbyClass',
119
-			'Choose filter set',
120
-			array(
121
-				'0'			=>	'by page',
122
-				'1'			=>	'by page/data type'
123
-			)
124
-		)->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>');
117
+        $filterSelector = OptionsetField::create(
118
+            'showBlockbyClass',
119
+            'Choose filter set',
120
+            array(
121
+                '0'			=>	'by page',
122
+                '1'			=>	'by page/data type'
123
+            )
124
+        )->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>');
125 125
 		
126
-		$availablePages = Page::get()->exclude('ClassName', array(
127
-			'ErrorPage',
128
-			'RedirectorPage',
129
-			'VirtualPage'
130
-		));
131
-		$pageSelector = new CheckboxSetField(
132
-			$name = "Pages",
133
-			$title = "Show on Page(s)",
134
-			$availablePages->map('ID','Title')
135
-		);
126
+        $availablePages = Page::get()->exclude('ClassName', array(
127
+            'ErrorPage',
128
+            'RedirectorPage',
129
+            'VirtualPage'
130
+        ));
131
+        $pageSelector = new CheckboxSetField(
132
+            $name = "Pages",
133
+            $title = "Show on Page(s)",
134
+            $availablePages->map('ID','Title')
135
+        );
136 136
 		
137 137
 		
138
-		if ($this->canConfigPageAndType(Member::currentUser())) {
139
-			$fields->addFieldsToTab('Root.VisibilitySettings', array(
140
-				$filterSelector,
141
-				$pageSelector,
142
-				$inClass
143
-			));
144
-		}
138
+        if ($this->canConfigPageAndType(Member::currentUser())) {
139
+            $fields->addFieldsToTab('Root.VisibilitySettings', array(
140
+                $filterSelector,
141
+                $pageSelector,
142
+                $inClass
143
+            ));
144
+        }
145 145
 		
146
-		if ($this->canConfigMemberVisibility(Member::currentUser())) {
147
-			$fields->addFieldToTab('Root.VisibilitySettings', $memberVisibility);
148
-		}
146
+        if ($this->canConfigMemberVisibility(Member::currentUser())) {
147
+            $fields->addFieldToTab('Root.VisibilitySettings', $memberVisibility);
148
+        }
149 149
 		
150
-		if (!$fields->fieldByName('Options')) {
151
-			$fields->insertBefore($right = RightSidebar::create('Options'), 'Root');
152
-	    }
150
+        if (!$fields->fieldByName('Options')) {
151
+            $fields->insertBefore($right = RightSidebar::create('Options'), 'Root');
152
+        }
153 153
 	
154
-	    $fields->addFieldsToTab('Options', array(
155
-			CheckboxField::create('addMarginTop', 'add "margin-top" class to block wrapper'),
156
-			CheckboxField::create('addMarginBottom', 'add "margin-bottom" class to block wrapper')
157
-	    ));
154
+        $fields->addFieldsToTab('Options', array(
155
+            CheckboxField::create('addMarginTop', 'add "margin-top" class to block wrapper'),
156
+            CheckboxField::create('addMarginBottom', 'add "margin-bottom" class to block wrapper')
157
+        ));
158 158
 
159
-		return $fields;
160
-	}
159
+        return $fields;
160
+    }
161 161
 	
162
-	public function doPublish() {
163
-		$this->writeToStage('Live');
164
-	}
162
+    public function doPublish() {
163
+        $this->writeToStage('Live');
164
+    }
165 165
 	
166
-	public function onBeforeWrite() {
167
-		parent::onBeforeWrite();
168
-		if (empty($this->byPass)) {
169
-			$this->readmode = Versioned::get_reading_mode();
170
-			Versioned::set_reading_mode('Stage.Stage');
171
-		}
172
-	}
166
+    public function onBeforeWrite() {
167
+        parent::onBeforeWrite();
168
+        if (empty($this->byPass)) {
169
+            $this->readmode = Versioned::get_reading_mode();
170
+            Versioned::set_reading_mode('Stage.Stage');
171
+        }
172
+    }
173 173
 	
174
-	public function onAfterWrite() {
175
-		parent::onAfterWrite();
176
-		if (isset($this->readmode)) {
177
-			Versioned::set_reading_mode('Stage.' . $this->readmode);
178
-		}
174
+    public function onAfterWrite() {
175
+        parent::onAfterWrite();
176
+        if (isset($this->readmode)) {
177
+            Versioned::set_reading_mode('Stage.' . $this->readmode);
178
+        }
179 179
 		
180
-		/*if ($this->isPublished()) {
180
+        /*if ($this->isPublished()) {
181 181
 			$live = Versioned::get_by_stage('Block', 'Live')->byID($this->ID);
182 182
 			$stage = Versioned::get_by_stage('Block', 'Stage')->byID($this->ID);
183 183
 			if ($live->SortOrder != $stage->SortOrder) {
@@ -186,74 +186,74 @@  discard block
 block discarded – undo
186 186
 				$this->doPublish();
187 187
 			}
188 188
 		}*/
189
-	}
189
+    }
190 190
 	
191
-	public function availableClasses() {
192
-		$Classes = array_diff(
193
-			ClassInfo::subclassesFor('Page'),
194
-			ClassInfo::subclassesFor('RedirectorPage'),
195
-			ClassInfo::subclassesFor('VirtualPage')
196
-		);
197
-		return $Classes;
198
-	}
191
+    public function availableClasses() {
192
+        $Classes = array_diff(
193
+            ClassInfo::subclassesFor('Page'),
194
+            ClassInfo::subclassesFor('RedirectorPage'),
195
+            ClassInfo::subclassesFor('VirtualPage')
196
+        );
197
+        return $Classes;
198
+    }
199 199
 	
200
-	public function forTemplate() {
201
-		if ($this->canDisplayMemberCheck()) {
202
-			return $this->renderWith(array($this->getClassName(), 'BaseBlock'));
203
-		}
200
+    public function forTemplate() {
201
+        if ($this->canDisplayMemberCheck()) {
202
+            return $this->renderWith(array($this->getClassName(), 'BaseBlock'));
203
+        }
204 204
 		
205
-		return false;
206
-	}
205
+        return false;
206
+    }
207 207
 	
208
-	public function canDisplayMemberCheck() {
209
-		$rawVisibility = $this->MemberVisibility;
208
+    public function canDisplayMemberCheck() {
209
+        $rawVisibility = $this->MemberVisibility;
210 210
 		
211
-		if (empty($rawVisibility)) {
212
-			return true;
213
-		}
211
+        if (empty($rawVisibility)) {
212
+            return true;
213
+        }
214 214
 		
215
-		$visibility = explode(',', $rawVisibility);
216
-		$member = Member::currentUser();
215
+        $visibility = explode(',', $rawVisibility);
216
+        $member = Member::currentUser();
217 217
 		
218
-		if (!$member && in_array('anonymous', $visibility)) {
219
-			return true;
220
-		}
218
+        if (!$member && in_array('anonymous', $visibility)) {
219
+            return true;
220
+        }
221 221
 		
222
-		if ($member) {
223
-			$memberGroups = $member->Groups()->column('Code');
224
-			foreach ($memberGroups as $memberGroup) {
225
-				if (in_array($memberGroup, $visibility)) {
226
-					return true;
227
-				}
228
-			}
229
-		}
222
+        if ($member) {
223
+            $memberGroups = $member->Groups()->column('Code');
224
+            foreach ($memberGroups as $memberGroup) {
225
+                if (in_array($memberGroup, $visibility)) {
226
+                    return true;
227
+                }
228
+            }
229
+        }
230 230
 		
231
-		return false;
232
-	}
231
+        return false;
232
+    }
233 233
 	
234
-	public function frontendEditable() {
235
-		$member = Member::currentUser();
236
-		return $this->canEdit($member) && Config::inst()->get('Block', 'FrontendEditable');
237
-	}
234
+    public function frontendEditable() {
235
+        $member = Member::currentUser();
236
+        return $this->canEdit($member) && Config::inst()->get('Block', 'FrontendEditable');
237
+    }
238 238
 	
239
-	public function Type2Class() {
240
-		return strtolower(str_replace(' ', '-', $this->singular_name()));
241
-	}
239
+    public function Type2Class() {
240
+        return strtolower(str_replace(' ', '-', $this->singular_name()));
241
+    }
242 242
 	
243
-	/*public function doPublish() {
243
+    /*public function doPublish() {
244 244
 		$this->writeToStage('Live');
245 245
 	}*/
246 246
 	
247
-	public function Published() {
248
-		return $this->isPublished() ? 'Yes' : 'No';
249
-	}
247
+    public function Published() {
248
+        return $this->isPublished() ? 'Yes' : 'No';
249
+    }
250 250
 	
251
-	public function isPublished() {
252
-		if (!empty(Versioned::get_by_stage('Block', 'Live')->byID($this->ID))) {
253
-			return true;
254
-		}
251
+    public function isPublished() {
252
+        if (!empty(Versioned::get_by_stage('Block', 'Live')->byID($this->ID))) {
253
+            return true;
254
+        }
255 255
 		
256
-		return false;
257
-	}
256
+        return false;
257
+    }
258 258
 
259 259
 }
260 260
\ No newline at end of file
Please login to merge, or discard this patch.