Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba

Creating A F.A.Q. page, How do I group questions?


Go to End


4 Posts   1188 Views

Avatar
otherjohn

Community Member, 125 Posts

7 May 2010 at 4:18am

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')
		);
	}

 
}

Avatar
UncleCheese

Forum Moderator, 4102 Posts

7 May 2010 at 4:32am

You need a nested DOM..

Page -> has_many -> FAQGroups -> has_many ->FAQs.

<% control FAQGroups %>
$Title
<% control FAQs %>
$Question $Answer
<% end_control %>
<% end_control%>

Avatar
otherjohn

Community Member, 125 Posts

7 May 2010 at 4:36am

I guess my question is, How do I get in the ADMIN, the ability to attach questions to FAQGroups?
In the questions tab, it just has the ability to enter question and answer. What am I missing to pick what group its a part of?
John

Avatar
UncleCheese

Forum Moderator, 4102 Posts

7 May 2010 at 4:40am

In the edit form for your question group, put a DOM in there for adding FAQs..

Holder page..

new DataObjectManager($this,'QuestionGroups','QuestionGroup');

QuestionGroup

return new FieldSet(
new TextField('Title'),
new DataObjectManager($this,'FAQs','FAQ')
);