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.

Form Questions /

Form to catch votes (poll like)


Go to End
Reply


12 Posts   1927 Views

Avatar
gvelasquez85

Community Member, 11 Posts

29 June 2011 at 3:57pm

Hello, I am trying to make a online image contest, but the users of the site have to vote for their favorite picture. I've created a page where the admin can upload the contestants and the people can see it in the front-end, but what I need to make is something like a poll but, per page, not in the entire site. My client says that mayber 3-4 polls can be taken at the same time.

Any ideas/suggestions/snippets for this???

Any help will be highly appreciated.

Thank You

Avatar
swaiba

Forum Moderator, 1799 Posts

29 June 2011 at 11:51pm

http://www.silverstripe.org/polls-module/

then this might help...http://www.silverstripe.org/all-other-modules/show/16851

Avatar
gvelasquez85

Community Member, 11 Posts

30 June 2011 at 2:19am

Nice, I was looking that module yesterday but I can't figure how I can pass parameters to the function (I can create the poll with the same title of the page) and the $Title variable will be the parameter to select the specific poll for the page. I was trying to do something like

class Page_Controller extends ContentController {
...
function MyPoll($Title) {
return new ShowPoll($this, $Title);
}
...
}

and, in the .ss I have to put $MyPoll($Title), but it doesn't seems to work, any suggestions??

Avatar
swaiba

Forum Moderator, 1799 Posts

30 June 2011 at 2:36am

When I get stuck with passing variable around I just use the session... bit hacky as it's like having global vaiables!

but Session::set('MyVar','something) and $myvar = Session::get('MyVar'); will get the job done

Avatar
gvelasquez85

Community Member, 11 Posts

30 June 2011 at 3:00am

mmm nice solution... I have to put

Session::set('MyVar',$Title) and $myvar = Session::get('MyVar')

and then

class Page_Controller extends ContentController {
...
function MyPoll() {
return new ShowPoll($this, Myvar);
}
...
}

and, in the .ss I have to put $MyPoll()

rigth?

Avatar
swaiba

Forum Moderator, 1799 Posts

30 June 2011 at 3:04am

hmmmm

I'd add a has_one Poll to the page so that in the cms the user can select the poll that is required on that page.
then in the init of the page I'd transfer the $this->PollID to the session
then in the poll display code I'd hack the bit that does a DataObject::get_one to get_by_id and use the value from the session

does that make sense?

Avatar
gvelasquez85

Community Member, 11 Posts

30 June 2011 at 3:53am

mmm makes sense... let me try it in a few hours and I'll let you know how is it going. BTW whe you say:

I'd add a has_one Poll to the page so that in the cms the user can select the poll that is required on that page.

Do you mean add a TextField or something where the user will enter the Poll ID? Is there any other to do it? Maybe generate a combo with all the active polls? (Too much complicated) or better I'll try with a TextField?

Avatar
swaiba

Forum Moderator, 1799 Posts

30 June 2011 at 4:03am

Edited: 30/06/2011 4:04am

I mean like this...

class MyPage extends Page {
...
   static $has_one = array(
      'Poll' => 'Poll'
   );
...   
   function getCMSFields(){
      $fields = parent::getCMSFields();
      $dosPoll = DataObject::get('Poll');
      $map = $dosPoll ? $dosPoll ->toDropdownMap('ID','PollTitle') : array();
      $fields->addFieldToTab('Root.Content.Main', new DropdownField('PollID', 'Select a poll',$map));
      return $fields;
   }
...   
}

Go to Top