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.

Archive

Our old forums are still available as a read-only archive.

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

ManyMany Complex Table Field -- Setting Default Checked Checkboxes


Reply

3 Posts   2915 Views

Avatar
Daminipo

23 July 2008 at 12:56am (Last edited: 23 July 2008 2:24am), Community Member, 14 Posts

Hello!

If got a problem with the ManyManyComplexTableField.
I'm trying to find out how to make certain Entries constantly checked.

I have a Pagetype "Faq" that is always Child of "ThemeHolder".
"Faq" represents an Question-Answer pair that was made.
"ThemeHolder" represents the Themes that the Faq entry can belong to.
In the ManyMany ComplexTableField theres a List of all "ThemeHolders" and you can correlate "Faq" with multiple "ThemeHolders".

Now I want that the "ThemeHolder" that is the parent to "Faq" is always checked and is not to change by the CMS user.
All the other ones can be checked or unchecked as normal but this one correlation has to be always there, otherwise it makes no sense.
Cause I want to make it possible that a Faq entry is able to correspond to many Themes, but the Theme it is Child of should always be checked and unable to get unchecked.

Is there anyone who might can help me with this Problem?
I would be very thankful!

Avatar
Daminipo

30 July 2008 at 4:03am (Last edited: 30 July 2008 4:05am), Community Member, 14 Posts

Well... finally I got the answer to my Problem. In any case someone is interessted what I've done let you know here:

class Faq extends Page
{
...
   static $many_many = array(
      'Themes' => 'ThemeHolder' //Relations name is "Themes"
   );
protected $myThemeArray = array();
   protected $myString = "";
...
//WHATCH OUT: The function onAfterWrite() is only useable when you use the Daily builds, it's not included in the Version 2.2.2
function onAfterWrite()
   {
      $myID = $this->ParentID;
      $this->getMyParents($myID);
      $myThemes = $this->Themes(); //be shure to use the Name here you gave your many_many relation before
      $myThemes->addMany($this->myThemeArray);
      
      parent::onAfterWrite();
   }
   
   function getMyParents($myID)
   {
      if( DataObject::get_by_id('SiteTree', $myID))
      {
         $myObj = DataObject::get_by_id('SiteTree', $myID);
         
         if( $myObj->ClassName != 'FaqHolder' )
         {
            $myThemeID = $myObj->ID;
            $this->myThemeArray[] = $myThemeID;
            foreach($this->myThemeArray as $PID)
            {
               $this->myString .= $PID;
            }
            $myParentID = $myObj->ParentID;

            $this->getMyParents($myParentID);
         }
      }
   }
...
}

As you hoefully have noticed is that the Function onAfterWrite() is beeing used. This is only availeble when you use the Daily builds. I don't know since when it isicluded, just use the newest one.
;-)

-->[url]http://dailybuilds.silverstripe.com/core-tarballs/[/url]

The problem was that with the function onBeforeWrite() you are unable to use $this->ID or $this->ParentID, because the actual entry hasn't been made yet, as you are Before the writing progress...

That way I have all my Themes Selected by default, even when someone deselects them, they will be there the next time he visits the Many_Many Table.

If anyone is interested in the FAQ Module I'm creating just let me know.
:-)

Cheers,
Daminipo

Avatar
Daminipo

20 August 2008 at 2:42am (Last edited: 20 August 2008 2:43am), Community Member, 14 Posts

Hi RNHurt!

Sorry that I took so long to answer your question!
Well, I think what you have in mind is something completely different than my FAQ.
I have actually build something very untypical, for that my FAQ looks more like an Forum.
You can make up themes and Subthemes and make your FAQ posts there.
The main idea was to make an FAQ that we in our development Team can make entries to specific themes, so if another one has the same issue he can look it up fast.
An FAQ like you see it on most of the Pages with a list of about 10 questions and beneath all the Question/Answer pairs, with the back to top links etc. isn't what I had to develop.

But if you have some more infos in what your problem is, I can try to help you.

For now I would suggest to make one Page that "holds" all the FAQ entries.
So you can easly list them on top and afterward make a clear Template for them.
For example:

MyFAQ
---Question1
---Question2
---Question3
---...etc

So that MyFAQ is the Parent.
Now you can use the MyFAQ.ss to <% control Children %> and firstly give out a list of Questions with the link to them.
and afterwards another control to give out the complete Question/Answer pair.
So you could work with anchors in your templates that makes it easy to jump around in the site.

Could I help you with this?

Best wishes,
Daminipo