Skip to content

Commit ed049bf

Browse files
author
helpfulrobot
committed
Converted to PSR-2
1 parent 61c0a50 commit ed049bf

File tree

4 files changed

+332
-303
lines changed

4 files changed

+332
-303
lines changed

code/Faq.php

+85-79
Original file line numberDiff line numberDiff line change
@@ -4,85 +4,91 @@
44
*
55
* @package advancedfaq
66
*/
7-
class Faq extends DataObject {
7+
class Faq extends DataObject
8+
{
89

9-
private static $db = array(
10-
'Question' => 'Text',
11-
'Answer' => 'HTMLText',
12-
'SortOrder'=>'Int'
13-
);
14-
15-
public static $default_sort='SortOrder';
16-
17-
private static $has_one = array(
10+
private static $db = array(
11+
'Question' => 'Text',
12+
'Answer' => 'HTMLText',
13+
'SortOrder'=>'Int'
14+
);
15+
16+
public static $default_sort='SortOrder';
17+
18+
private static $has_one = array(
1819
'FaqPage' => 'FaqPage',
19-
'FaqSection' => 'FaqSection',
20+
'FaqSection' => 'FaqSection',
21+
);
22+
23+
private static $many_many = array(
24+
'FaqTags' => 'FaqTag'
25+
);
26+
27+
private static $extensions = array(
28+
"Versioned('Stage', 'Live')"
29+
);
30+
31+
private static $summary_fields = array(
32+
'Question', 'Answer'
33+
);
34+
35+
private static $searchable_fields = array(
36+
'Question', 'Answer'
2037
);
21-
22-
private static $many_many = array(
23-
'FaqTags' => 'FaqTag'
24-
);
25-
26-
private static $extensions = array(
27-
"Versioned('Stage', 'Live')"
28-
);
29-
30-
private static $summary_fields = array(
31-
'Question', 'Answer'
32-
);
33-
34-
private static $searchable_fields = array(
35-
'Question', 'Answer'
36-
);
37-
38-
/*
39-
* Modify the default fields shown to the user
40-
*/
41-
public function getCMSFields() {
42-
$fields = parent::getCMSFields();
43-
$fields->removeByName('FaqPageID');
44-
$fields->removeByName('FaqTags');
45-
$fields->removeByName('SortOrder');
46-
47-
$fields->addFieldToTab('Root.Main', new TextField('Question', 'Question'));
48-
$fields->addFieldToTab('Root.Main', new HtmlEditorField('Answer', 'Answer'));
49-
50-
// faq section - has_one relation
51-
$map = FaqSection::get()
52-
->sort('Title')
53-
->map('ID', 'Title');
54-
$field = new DropdownField('FaqSectionID', 'Faq section', $map);
55-
$field->setEmptyString('None');
56-
$fields->addFieldToTab('Root.Main', $field, 'Question');
57-
58-
// faq tags - has_many relation
59-
$tagMap = FaqTag::get()
60-
->sort('Title')
61-
->map('ID', 'Title')
62-
->toArray();
63-
$tagsField = new ListboxField('FaqTags', 'Faq tags');
64-
$tagsField->setMultiple(true)->setSource($tagMap);
65-
$fields->addFieldToTab( 'Root.Main', $tagsField, 'Question' );
66-
67-
return $fields;
68-
}
69-
70-
public function getTitle(){
71-
return $this->Question;
72-
}
73-
74-
/** allow all users for crud operations **/
75-
public function canView($member = null) {
76-
return true;
77-
}
78-
public function canEdit($member = null) {
79-
return true;
80-
}
81-
public function canDelete($member = null) {
82-
return true;
83-
}
84-
public function canCreate($member = null) {
85-
return true;
86-
}
87-
88-
}
38+
39+
/*
40+
* Modify the default fields shown to the user
41+
*/
42+
public function getCMSFields()
43+
{
44+
$fields = parent::getCMSFields();
45+
$fields->removeByName('FaqPageID');
46+
$fields->removeByName('FaqTags');
47+
$fields->removeByName('SortOrder');
48+
49+
$fields->addFieldToTab('Root.Main', new TextField('Question', 'Question'));
50+
$fields->addFieldToTab('Root.Main', new HtmlEditorField('Answer', 'Answer'));
51+
52+
// faq section - has_one relation
53+
$map = FaqSection::get()
54+
->sort('Title')
55+
->map('ID', 'Title');
56+
$field = new DropdownField('FaqSectionID', 'Faq section', $map);
57+
$field->setEmptyString('None');
58+
$fields->addFieldToTab('Root.Main', $field, 'Question');
59+
60+
// faq tags - has_many relation
61+
$tagMap = FaqTag::get()
62+
->sort('Title')
63+
->map('ID', 'Title')
64+
->toArray();
65+
$tagsField = new ListboxField('FaqTags', 'Faq tags');
66+
$tagsField->setMultiple(true)->setSource($tagMap);
67+
$fields->addFieldToTab('Root.Main', $tagsField, 'Question');
68+
69+
return $fields;
70+
}
71+
72+
public function getTitle()
73+
{
74+
return $this->Question;
75+
}
76+
77+
/** allow all users for crud operations **/
78+
public function canView($member = null)
79+
{
80+
return true;
81+
}
82+
public function canEdit($member = null)
83+
{
84+
return true;
85+
}
86+
public function canDelete($member = null)
87+
{
88+
return true;
89+
}
90+
public function canCreate($member = null)
91+
{
92+
return true;
93+
}
94+
}

0 commit comments

Comments
 (0)