Hallo folks,
I have been extending the (daily trunk from yesterday) Poll Module a little bit.
I gave it a Field called PollaName (only PollTitle was available until now) which I want to use to select the Poll inside ShowPoll (instead of random).
Its working for now when adding the following function to the Page_Controller:
function MyPoll() {
$PollName = 'myfirstpoll';
return new ShowPoll($this, $PollName);
}
a next step will be to have a select Field on the Page Object to select a poll to be shown on this Page. This is no big Deal to Implement, but I don't want to hardcode this inside the Page class. Instead i prefere to use (haven't done this before) a Decorator.
I'm noit quite sure, I understand the Decorator Patterns right, but for my understanding, all I have to do is to is to write a Decorator class as foloowed:
class Pollable extends SiteTreeDecorator {
function extraStatics(){
return array('db' => array('ShowPoll' => 'Text'));
}
function updateCMSFields(&fields){
// add Dropdown List with Poll here
}
// add any function I want to use in Frontend
}
Than I can add DataObject::add_extension('Page', 'Pollable'); to the Polls _config.php an all Pages inheriting Page should be able to select a poll to be shown in the Frontend.
The function to Show the Poll will normaly be added to the Page_Controller. If I add this function to my Pollable Decorator, will it than be available in my Page_Controller to, or do I have to add an extension for the Controller too (and how do i do this)?