Jump to:

7939 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Creating A F.A.Q. page, How do I group questions?

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 767 Views
  • otherjohn
    Avatar
    Community Member
    125 Posts

    Creating A F.A.Q. page, How do I group questions? Link to this post

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

    }

  • UncleCheese
    Avatar
    4085 Posts

    Re: Creating A F.A.Q. page, How do I group questions? Link to this post

    You need a nested DOM..

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

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

  • otherjohn
    Avatar
    Community Member
    125 Posts

    Re: Creating A F.A.Q. page, How do I group questions? Link to this post

    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

  • UncleCheese
    Avatar
    4085 Posts

    Re: Creating A F.A.Q. page, How do I group questions? Link to this post

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

    767 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.