13 December, 2009

SiteWide publishing for SilverStripe new concept.

This is a new concept which I started working on and have done the stuff for some extent.

The goal is that on sites which have sub sites, we will need to run sections like news, customer testimonials, which probably common to all the subsites as well, yet there might be pages which are not needed to published on all the sub sites. Let me explain this more. Think of an organization which has many departments, and all these departments have their own news as well as common news. Now if we are to run a news section for this sort of a website we will have to duplicate content, which consumes time, and sometimes can cause errors. I am trying to address such a problem with this extension.

Surely you might think why do we need a new module for this as the SubSiteVirtualPage is there. Yes true you can make use of it. But the fact is that the SubSiteVirtualPage doesn't handle relationships among data objects (has_one / has_many / many_many). And the most hard question is how to have the same template and tags. Okay I think my approach can fix this up.

I am extending the SubsiteVirtualPage, and the module has two page types, one is SiteWidePage, the other one extends SiteWideHolder.

Now in the news module which we are trying to build we are going to extend the SiteWidePage as a NewsItem, and SiteWideHolder as NewsHolder, and we will be creating respective templates, NewsItem.ss and NewsHolder.ss. This solves the problem of having the same layout.

Now what the SiteWidePage does is that it has a new field called publishing, which has a check-box group with the names of the SubSites to publish. Once you select the sub domains and publish the page, it creates needed pages (SiteWidePage) on the subsites and take the content from the source. Okay we have it then, about the has_one relationships I am doing every time the source page is published it updates the pages which are taking its content. It is like cloning the database record. This solves the problem of the has_one relationships.

To make this much useful I am having a solution for the has_many (many to one) relationship as well. The below image illustrate the many -> one relationship.



Okay this is it, please be kind enough my graphics sucks :). Anyway note now that pages can have many images but a image can only have one page. Now as out login we have to add images to one page, and when we add an image it might be taken by the pages which get content from the source Page. OMG! we are ruining the logic of many -> one. To avoid this I am doing something like this. I extended the DataObject and created a new one called CloningDataObject now what this does is, once the page is published it creates clones and let the other pages to refer to those clones. This way I thought we can keep the many -> one relationship and proceed. As the SiteWidePage when the source dataobject is saved it writes all its content to its clones, on deletion it deletes all the clones as well.

One thing you have to note about the CloningDataobject is that it has a defined has_one relationship to the Page class. So if you are going to use this in your NewsItem page you dont need to extend the CloningDataObject and create a new relationship as it is there.

Now I still couldnt find a way to get on with the many -> many relationship, SilverStripe does it in a nice way, what I have in my mind is we can create more records in the respective database relationships tables. Yet I am trying to find a better solution.

I do think this can be a useful extension for the SilverStripe Open Source CMS, be glad if you can raise your thoughts about it.

7 comments:

Ardjan said...

Hi Nivanka,

Can I see your mashup code? I'm really stuck in this problem, so you would help me a lot with that!

Thanks in advance.

Ardjan

Nivanka said...

Ardjan,

Sure you can, I will post the link soon, and you can see. The code has some ToDo items to maintain the many_many relations. Yet it is usable. I will post the links soon.

Nivanka said...

Followed: Actually today I submitted it to SilverStripe. So I was planning to wait for their assessments. But I will release the code soon

Ardjan said...

Cool! Good work.
It's for a news section which should be published sidewide. I now get the job done by creating a subsites virtual page for every news article, but that's -obvious- quite unpracticle.
So, thanks in advance for your solution.

Nivanka said...

Hi I just uploaded the codes to one of the servers where I have access. take it from here.

Please be kind to raise your thoughts about the module as well. It would be great if we can develop some contacts over email.

Ardjan said...

"Please be kind to raise your thoughts about the module"
I sure will! I'm back in the office on Monday, so I'll take a look at it then.

Nivanka said...

nice one