Completed
Branch master (f11977)
by Leo
02:15
created
code/Block.php 1 patch
Indentation   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -1,168 +1,168 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 class Block extends DataObject {
4
-	protected static $db = array (
5
-		'SortOrder'			=>	'Int',
6
-		'Title'				=>	'Varchar(64)',
7
-		'hideTitle'			=>	'Boolean',
8
-		'showBlockbyClass'	=>	'Boolean',
9
-		'Description'		=>	'Varchar(128)',
10
-		'MemberVisibility'	=>	'Varchar(255)',
11
-		'shownInClass'		=>	'Text'
12
-	);
4
+    protected static $db = array (
5
+        'SortOrder'			=>	'Int',
6
+        'Title'				=>	'Varchar(64)',
7
+        'hideTitle'			=>	'Boolean',
8
+        'showBlockbyClass'	=>	'Boolean',
9
+        'Description'		=>	'Varchar(128)',
10
+        'MemberVisibility'	=>	'Varchar(255)',
11
+        'shownInClass'		=>	'Text'
12
+    );
13 13
 	
14
-	protected static $many_many = array (
15
-		'Pages'				=>	'Page'
16
-	);
14
+    protected static $many_many = array (
15
+        'Pages'				=>	'Page'
16
+    );
17 17
 		
18
-	protected static $create_table_options = array(
19
-		'MySQLDatabase'		=> 'ENGINE=MyISAM'
18
+    protected static $create_table_options = array(
19
+        'MySQLDatabase'		=> 'ENGINE=MyISAM'
20 20
     );
21 21
 	
22
-	protected static $extensions = array (
23
-		'StandardPermissions'
24
-	);
22
+    protected static $extensions = array (
23
+        'StandardPermissions'
24
+    );
25 25
 	
26
-	protected static $summary_fields = array(
27
-		'BlockType',
28
-		'Title', 
29
-		'Description',
30
-		'shownOn'
31
-	);
26
+    protected static $summary_fields = array(
27
+        'BlockType',
28
+        'Title', 
29
+        'Description',
30
+        'shownOn'
31
+    );
32 32
 	
33
-	protected static $field_labels = array(
34
-		'BlockType'			=>	'Block type',
35
-		'shownOn'			=>	'is shown on'
36
-	);
33
+    protected static $field_labels = array(
34
+        'BlockType'			=>	'Block type',
35
+        'shownOn'			=>	'is shown on'
36
+    );
37 37
 	
38
-	public function BlockType() {
39
-		return $this->singular_name();
40
-	}
38
+    public function BlockType() {
39
+        return $this->singular_name();
40
+    }
41 41
 	
42
-	public function shownOn() {
43
-		$lists = '';
44
-		if ($this->showBlockbyClass) {
45
-			if (strlen(trim($this->shownInClass)) > 0) {
46
-				$lists = 'Type: ' . str_replace(',','<br />Type: ', $this->shownInClass);
47
-			}else{
48
-				$lists = '<em>&lt;not assigned&gt;</em>';
49
-			}
50
-		}else{
51
-			$lists = 'Page: ' . implode('<br />Page: ', $this->Pages()->column('Title'));
52
-		}
53
-		return new LiteralField('shownOn',$lists);
54
-	}
42
+    public function shownOn() {
43
+        $lists = '';
44
+        if ($this->showBlockbyClass) {
45
+            if (strlen(trim($this->shownInClass)) > 0) {
46
+                $lists = 'Type: ' . str_replace(',','<br />Type: ', $this->shownInClass);
47
+            }else{
48
+                $lists = '<em>&lt;not assigned&gt;</em>';
49
+            }
50
+        }else{
51
+            $lists = 'Page: ' . implode('<br />Page: ', $this->Pages()->column('Title'));
52
+        }
53
+        return new LiteralField('shownOn',$lists);
54
+    }
55 55
 	
56 56
 	
57
-	public function getCMSFields() {
58
-		$fields = parent::getCMSFields();
59
-		$fields->removeFieldFromTab('Root', 'Pages');
60
-		$fields->removeFieldsFromTab('Root.Main', array(
61
-			'SortOrder',
62
-			'showBlockbyClass',
63
-			'shownInClass',
64
-			'MemberVisibility'
65
-		));
57
+    public function getCMSFields() {
58
+        $fields = parent::getCMSFields();
59
+        $fields->removeFieldFromTab('Root', 'Pages');
60
+        $fields->removeFieldsFromTab('Root.Main', array(
61
+            'SortOrder',
62
+            'showBlockbyClass',
63
+            'shownInClass',
64
+            'MemberVisibility'
65
+        ));
66 66
 		
67
-		$memberGroups = Group::get();
68
-		$sourcemap = $memberGroups->map('Code', 'Title');
69
-		$source = array(
70
-			'anonymous'		=>	'Anonymous visitors'
71
-		);
72
-		foreach ($sourcemap as $mapping => $key) {
73
-			$source[$mapping] = $key;
74
-		}
67
+        $memberGroups = Group::get();
68
+        $sourcemap = $memberGroups->map('Code', 'Title');
69
+        $source = array(
70
+            'anonymous'		=>	'Anonymous visitors'
71
+        );
72
+        foreach ($sourcemap as $mapping => $key) {
73
+            $source[$mapping] = $key;
74
+        }
75 75
 		
76
-		$memberVisibility = new CheckboxSetField(
77
-			$name = "MemberVisibility",
78
-			$title = "Show block for specific groups",
79
-			$source
80
-		);
76
+        $memberVisibility = new CheckboxSetField(
77
+            $name = "MemberVisibility",
78
+            $title = "Show block for specific groups",
79
+            $source
80
+        );
81 81
 		
82
-		$memberVisibility->setDescription('Show this block only for the selected group(s). If you select no groups, the block will be visible to all members.');
82
+        $memberVisibility->setDescription('Show this block only for the selected group(s). If you select no groups, the block will be visible to all members.');
83 83
 		
84
-		$availabelClasses = $this->availableClasses();
85
-		$inClass = new CheckboxSetField(
86
-			$name = "shownInClass",
87
-			$title = "Show block for specific content types",
88
-			$availabelClasses
89
-		);
84
+        $availabelClasses = $this->availableClasses();
85
+        $inClass = new CheckboxSetField(
86
+            $name = "shownInClass",
87
+            $title = "Show block for specific content types",
88
+            $availabelClasses
89
+        );
90 90
 		
91
-		$filterSelector = OptionsetField::create(
92
-			'showBlockbyClass',
93
-			'Choose filter set',
94
-			array(
95
-				'0'			=>	'by page',
96
-				'1'			=>	'by page/data type'
97
-			)
98
-		)->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>');
91
+        $filterSelector = OptionsetField::create(
92
+            'showBlockbyClass',
93
+            'Choose filter set',
94
+            array(
95
+                '0'			=>	'by page',
96
+                '1'			=>	'by page/data type'
97
+            )
98
+        )->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>');
99 99
 		
100
-		$availablePages = Page::get()->exclude('ClassName', array(
101
-			'ErrorPage',
102
-			'RedirectorPage',
103
-			'VirtualPage'
104
-		));
105
-		$pageSelector = new CheckboxSetField(
106
-			$name = "Pages",
107
-			$title = "Show on Page(s)",
108
-			$availablePages
109
-		);
100
+        $availablePages = Page::get()->exclude('ClassName', array(
101
+            'ErrorPage',
102
+            'RedirectorPage',
103
+            'VirtualPage'
104
+        ));
105
+        $pageSelector = new CheckboxSetField(
106
+            $name = "Pages",
107
+            $title = "Show on Page(s)",
108
+            $availablePages
109
+        );
110 110
 		
111
-		$fields->addFieldsToTab('Root.VisibilitySettings', array(
112
-			$filterSelector,
113
-			$pageSelector,
114
-			$inClass,
115
-			$memberVisibility
116
-		));
117
-		return $fields;
118
-	}
111
+        $fields->addFieldsToTab('Root.VisibilitySettings', array(
112
+            $filterSelector,
113
+            $pageSelector,
114
+            $inClass,
115
+            $memberVisibility
116
+        ));
117
+        return $fields;
118
+    }
119 119
 	
120
-	private function availableClasses() {
121
-		$Classes = array_diff(
122
-			ClassInfo::subclassesFor('Page'),
123
-			ClassInfo::subclassesFor('ErrorPage'),
124
-			ClassInfo::subclassesFor('RedirectorPage'),
125
-			ClassInfo::subclassesFor('VirtualPage')
126
-		);
127
-		return $Classes;
128
-	}
120
+    private function availableClasses() {
121
+        $Classes = array_diff(
122
+            ClassInfo::subclassesFor('Page'),
123
+            ClassInfo::subclassesFor('ErrorPage'),
124
+            ClassInfo::subclassesFor('RedirectorPage'),
125
+            ClassInfo::subclassesFor('VirtualPage')
126
+        );
127
+        return $Classes;
128
+    }
129 129
 	
130
-	public function forTemplate() {
131
-		if ($this->canDisplayMemberCheck()) {
132
-			return $this->renderWith(array($this->getClassName(), 'BaseBlock'));
133
-		}
130
+    public function forTemplate() {
131
+        if ($this->canDisplayMemberCheck()) {
132
+            return $this->renderWith(array($this->getClassName(), 'BaseBlock'));
133
+        }
134 134
 		
135
-		return false;
136
-	}
135
+        return false;
136
+    }
137 137
 	
138
-	private function canDisplayMemberCheck() {
139
-		$rawVisibility = $this->MemberVisibility;
138
+    private function canDisplayMemberCheck() {
139
+        $rawVisibility = $this->MemberVisibility;
140 140
 		
141
-		if (empty($rawVisibility)) {
142
-			return true;
143
-		}
141
+        if (empty($rawVisibility)) {
142
+            return true;
143
+        }
144 144
 		
145
-		$visibility = explode(',', $rawVisibility);
146
-		$member = Member::currentUser();
145
+        $visibility = explode(',', $rawVisibility);
146
+        $member = Member::currentUser();
147 147
 		
148
-		if (!$member && in_array('anonymous', $visibility)) {
149
-			return true;
150
-		}
148
+        if (!$member && in_array('anonymous', $visibility)) {
149
+            return true;
150
+        }
151 151
 		
152
-		if ($member) {
153
-			$memberGroups = $member->Groups()->column('Code');
154
-			foreach ($memberGroups as $memberGroup) {
155
-				if (in_array($memberGroup, $visibility)) {
156
-					return true;
157
-				}
158
-			}
159
-		}
152
+        if ($member) {
153
+            $memberGroups = $member->Groups()->column('Code');
154
+            foreach ($memberGroups as $memberGroup) {
155
+                if (in_array($memberGroup, $visibility)) {
156
+                    return true;
157
+                }
158
+            }
159
+        }
160 160
 		
161
-		return false;
162
-	}
161
+        return false;
162
+    }
163 163
 	
164
-	public function frontendEditable() {
165
-		$member = Member::currentUser();		
166
-		return $this->canEdit($member);
167
-	}
164
+    public function frontendEditable() {
165
+        $member = Member::currentUser();		
166
+        return $this->canEdit($member);
167
+    }
168 168
 }
169 169
\ No newline at end of file
Please login to merge, or discard this patch.
code/Extensions/PrintBlocks.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -1,27 +1,27 @@
 block discarded – undo
1 1
 <?php
2 2
 class PrintBlocks extends Extension {
3 3
 	
4
-	public function getAllBlocks() {
5
-		$blocks = new ArrayList();
6
-		$blocks->merge($this->getMyBlocks());
7
-		$blocks->merge($this->getDockedBlocks());
8
-		return $blocks;
9
-	}
4
+    public function getAllBlocks() {
5
+        $blocks = new ArrayList();
6
+        $blocks->merge($this->getMyBlocks());
7
+        $blocks->merge($this->getDockedBlocks());
8
+        return $blocks;
9
+    }
10 10
 		
11
-	public function getMyBlocks() {
12
-		return $this->owner->Blocks()->sort('SortOrder', 'ASC');
13
-	}
11
+    public function getMyBlocks() {
12
+        return $this->owner->Blocks()->sort('SortOrder', 'ASC');
13
+    }
14 14
 	
15
-	public function getDockedBlocks() {
16
-		$blocks = Block::get()->filter('showBlockbyClass', true);
17
-		$blocks_map = $blocks->map('ID', 'shownInClass');
18
-		foreach ($blocks_map as $blockID => $Classes) {
19
-			$Classes = explode(',', $Classes);
20
-			if (!in_array($this->owner->ClassName, $Classes)) {
21
-				$blocks = $blocks->exclude('ID', $blockID);
22
-			}
23
-		}
15
+    public function getDockedBlocks() {
16
+        $blocks = Block::get()->filter('showBlockbyClass', true);
17
+        $blocks_map = $blocks->map('ID', 'shownInClass');
18
+        foreach ($blocks_map as $blockID => $Classes) {
19
+            $Classes = explode(',', $Classes);
20
+            if (!in_array($this->owner->ClassName, $Classes)) {
21
+                $blocks = $blocks->exclude('ID', $blockID);
22
+            }
23
+        }
24 24
 		
25
-		return $blocks->sort('SortOrder', 'ASC');
26
-	}
25
+        return $blocks->sort('SortOrder', 'ASC');
26
+    }
27 27
 }
28 28
\ No newline at end of file
Please login to merge, or discard this patch.