29 December, 2009

Extending the Security Module of SilverStripe

Okay back to web development after my post yesterday.

Now I was in need to code up a section which is about user registration. Now this is quite easy with SilverStripe's User Page Module. But this module didn't help me out while implementing the site. I needed some other extended features such as,
  • Accept subscription payments
  • Set subscription amounts
  • Enable discounts / promos
  • Different user types
  • Different permissions
Now these things have been quite a bit of a headache for me in the beginning as I couldn't find a proper way of implementing this. After reading some of the core CMS codes (the security admin) I found my lucky niche to get it done.

Now this is what I mainly planned out. I am decorating the Group class to hold up subscriptions, promos, and most importantly the user permissions. By following this method I could quite smoothly. All I had to do when the registering process is that add the user to the correct group, and my client is really happy as he is able to do all the things inside one page, the Security Admin.

The codes are there so I am hoping to release them soon. Till then hope this post will be quite a buzz.

28 December, 2009

My views over General Sarath Fonseka

I am not a blogger who blogs about politics from the start of my blogging, yet as what I have been reading, seeing on the internet + television I thought I have to simply write something about what I feel.

So now a days Sri Lanka, is going to choose a new president for a period of 6 years, from 2010.
There are two main candidates, current president Mahinda Rajapaksha, and Former Army Commander General Sarath Fonseka. I thought of writing this post as I lost my confidence in General SF, with regard to what he talk.

He is raising a few things which makes a criminal in front of me. Let me list them out.

1. Former President CBK, and Defense Minister Ratwatte is much more better than President Mahinda, and Gotabhaya.
2. His statement which he made to the sunday Leader.
3. Again his statement at Ratnapura.
4. His promise to increase government workers salaries in 10, 000 Rupees.
5. His talk with Kingsly at Sirasa TV.

Okay let me go through these points,

1, my opinion about the first one is that it is true in CBK's time SL Army got lots of new weapons compared to the current president's time. Yet did they win the war! No it was a failure as a whole, as I know (what I have seen on news) in the first few years army achieved so many victories, operations like JayaSikuru, Riwirasa brought great damage to the LTTE. Yet they couldn't finish the war simply. And there was quite a huge buzz around the country saying that some of the military plans have been sold to the LTTE, etc, etc. And the Sri Lanka government sold a lot of money laundering institutions / organizations which were fully owned by the government (Air Lanka, Sri Lanka Insurance Corporation, etc.). And I don't think anyone would say president CBK's time is a good one, everyone needed some change and that's why Ranil became the prime minister though he didn't have a good name at all.
If we compare the current situation, during the past four years SL government occupied SL insurance corporation, Sri Lankan air lines, and most importantly the nation won the battle against the most brutal terrorist organization LTTE.
I am not singing praises for president Mahinda or Gotabhaya, lets say they didn't do anything at all. But my question for General is that how the hell CBK and Ratwatte can be better than Gota or Mahinda? I have an answer which I believe is true, General sing praises for CBK and Ratwatte as CBK is using the voice of her to help General. This is totally unacceptable.

2 & 3. Sunday leader reported some statement about Gotabhaya ordering the army (affective on the 58th division, Brig. Shawendra Silva - at that time) to kill the LTTE leaders whoever come to surrender with holding white flags or using some other means. Today I read an article on this website saying that the Editor of the Sunday Leader newspaper with the GOV are planning to issue a distorted version of a audio clip to prove General did such a statement. I am not going to talk about that incident. He is said no, he has been misquoted. OKAY we trust you. Now General go to Ratnapura and say a similar thing, he 100% proves that's his decision to reveal such a thing, though it is justifiable or not, but accepted by the nation. So I think he didn't betray Gota or Mahinda alone, but the wish or the whole nation.
As a true Sri Lankan if or if not Gota gave such an order to kill the LTTE leaders, I love what happened. If I could I will join the army to kill them. (I don't know what others think, but I think this is the love towards the country). If someone give an order like this I will not reveal it in any case. Lets see we keep secrets for our friends, family, etc. Do we reveal them if we are having some bad blood. This is very amateurish. Can't believe being a former General he could do this. And my question for General is that why do you reveal such things targeting a presidential election? this is not election campaigning, for me this is like revealing you have a brain filled up with SHIT.
Also, General you could go to courts and had time for that against Gotabhaya to seek justice about but why dont you do something like that to prove you didn't said such a thing.

4. This is for me a joke, Ranil was very popular for a statement which is about bracelets and gold chains. This sounds the same. Though he plans to limit the number of ministers to 35, and save some money which are used as commissions can he pay the whole lot of GOV workers 10,000 more.
Working for a BOI company which is in the IT industry I know that they come to Sri Lanka passing India as well, is because of the low cost. So General say that he is going to raise salaries of private sector employees too. I wish this wont happen, as our investors will go to somewhere else as they are going to miss their key benefits (General you have to know, Salaries are not what we take home, but EPF, ETF, Tax have to be included too). It is too simple to make such statements, yet the fact is that they expose that General doesn't have any sense of what he is talking about.

5. This is again I never want in my country. He has no plan which is to raise the country. He just blames presidents Mahina Chinthanaya, and he narrate statements made by someone else.
And he clearly said he is in this election as a candidate, because he is not treated well and he hates the way Gota and Mahinda work. This cannot be the starting point for such an intention. If he really need to serve the motherland he has to have such an ambition from the very first secod he was born, he said he was drived to take part as he is not treated well.
Lets think a little other way round. What will happen is the government presented him with a large plot of land, some better position, 600 troupe of army soldiers as his care takers, some women soldiers (i dont know for what), a house, vehicles, and hmmm what else, yes approved to close the roads when he travels, etc etc etc etc.
HE WILL NEVER BECOME A PRESIDENTIAL CANDIDATE. He says so.....

I got these intentions not being influenced by the current President nor by Gotabhaya. Yet I got them by listening to the things what have been happening in the past few days.

Anyway I wish you wont fill my blog with spam about General SF.

It has been quite a pain these days, the General Spamming :)

Think of this a little.

watch these for more

http://sarathfonseka.com/mediamain.html
http://dzoneonline.com/2009/12/25/exclusive-interview-with-sarath-fonseka/

22 December, 2009

Customizing the comments forms in SilverStripe

I came across some development stuff this week. I had to install a SilverStripe blog, yet the client needed some customizations for the Page Comments, also to change the form with which you can comment.

I always like to extend the core codes of SilverStripe but not to change them as it always helps when updating the CMS + the Framework.

Anyway this is what I did about the commenting, I had to extend the PageCommentInterface.php, I created a new child class of PageCommentInterface, called CustomPageCommentsInterface ( this is in ./mysite/code/CustomPageCommentsInterface.php ).

There I only had to override the method PostCommentForm.

This method creates a form, adds and Spam protection modules, MathSpamProtection, and the needed fields. Okay now I did one thing, I wanted to hide the Name and the URL fields of the comments. what I did is that I replaced them with hidden fields, and by the time it creates the form I assigned values to it by retrieving the logged in users details.

One more thing, for my requirement I didnt need any new fields to be introduced to comments, if you need any you can add them by a DataObjectDecorator, and create your field as you need.

Hope this information will be useful.

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.

23 years completed!

December 11th was my b'day, it was last Friday. So I just cut a cake at the office with my friends there. In the evening though I didnt expect Veranga a senior member of the Street Play troupe came to my place to pick me up for a party.
Damn! went to his place with my guitar and a drum. It was great and it was a real party. Singing till about 2 AM, and some booze was there too, he and his wife has arranged food too, and some friends of both came to the place.
Ultimately after having a late dinner one of his friends dropped me home, so thats how it went.
Its a good way to celebrate the b'day.