Hi all
I want to have administrators be able to enter faq questions and assign them to groups to achieve an output like this:
QuestionGroup1
Question 1
Answer 1
Question 2
Answer 2
QuestionGroup 2
Question 3
Answer 3
I am having a heck of a time getting this to work in the admin.
I created a "FAQPage" and added 2 tabs "Question Groups" and "Questions"
Questions doesn't allow me to assign the question to a question group.
Can someone give me some insight to this?
-John
Here is my code
class FAQPage extends Page
{
static $has_many = array (
'QuestionGroups' => 'QuestionGroup'
);
public function getCMSFields()
{
$f = parent::getCMSFields();
$f->addFieldToTab("Root.Content.QuestionGroup", new DataObjectManager(
$this,
'QuestionBunchs',
'QuestionBunch',
array('QuestionGroup'=>'QuestionGroup'),
'getCMSFields_forPopup'
));
$f->addFieldToTab("Root.Content.Questions", new DataObjectManager(
$this,
'FaqQuestions',
'FaqQuestion',
array('Question'=>'Question','Answer'=>'Answer'),
'getCMSFields_forPopup'
));
$f->renameField("Root.Content.Questions", "Question Groups");
return $f;
}
}
class FaqQuestion extends DataObject {
static $db = array(
'Question' => 'Text',
'Answer' => 'HTMLText'
);
static $has_one = array (
'QuestionBunch' => 'QuestionBunch'
);
public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('Question'),
new TextareaField('Answer')
);
}
}
class QuestionBunch extends DataObject {
static $db = array(
'QuestionGroup' => 'Text',
'Order' => 'Int'
);
static $has_many = array (
'FaqQuestions' => 'FaqQuestion'
);
public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('QuestionGroup')
);
}
}