function testChartURL()
 {
     $mobilePoll = $this->ObjFromFixture('Poll', 'mobile-poll');
     $pollForm = new PollForm(new Controller(), 'PollForm', $mobilePoll);
     $chart = $pollForm->getChart();
     $this->assertContains('iPhone (120)', $chart);
     $this->assertContains('Android (80)', $chart);
     $this->assertContains('Other (12)', $chart);
 }
 /**
  * If there is a poll available within range, take the last one and return that poll.
  * @return mixed:boolean|String False if none found. String of HTML if found.
  */
 public function PollForm()
 {
     $poll = Poll::get()->filter(array('Startdate:LessThan' => date('Y-m-d'), 'Enddate:GreaterThan' => date('Y-m-d')));
     if ($poll->count()) {
         return PollForm::create(Controller::curr(), 'PollForm', $poll->last());
     }
     return false;
 }
 function getCMSFields()
 {
     if ($this->ID != 0) {
         $totalCount = $this->getTotalVotes();
     } else {
         $totalCount = 0;
     }
     $fields = new FieldList($rootTab = new TabSet("Root", new Tab("Main", new TextField('Title', 'Poll title (maximum 50 characters)', null, 50), new OptionsetField('MultiChoice', 'Single answer (radio buttons)/multi-choice answer (tick boxes)', array(0 => 'Single answer', 1 => 'Multi-choice answer')), new OptionsetField('IsActive', 'Poll state', array(1 => 'Active', 0 => 'Inactive')), $embargo = new DatetimeField('Embargo', 'Embargo'), $expiry = new DatetimeField('Expiry', 'Expiry'), new HTMLEditorField('Description', 'Description'), $image = new UploadField('Image', 'Poll image'))));
     $embargo->getDateField()->setConfig('showcalendar', true);
     $embargo->getTimeField()->setConfig('showdropdown', true);
     $embargo->getDateField()->setConfig('dateformat', 'dd/MM/YYYY');
     $embargo->getTimeField()->setConfig('timeformat', 'h:m a');
     $expiry->getDateField()->setConfig('showcalendar', true);
     $expiry->getTimeField()->setConfig('showdropdown', true);
     $expiry->getDateField()->setConfig('dateformat', 'dd/MM/YYYY');
     $expiry->getTimeField()->setConfig('timeformat', 'h:m a');
     // Add the fields that depend on the poll being already saved and having an ID
     if ($this->ID != 0) {
         $config = GridFieldConfig::create();
         $config->addComponent(new GridFieldToolbarHeader());
         $config->addComponent(new GridFieldAddNewButton('toolbar-header-right'));
         $config->addComponent(new GridFieldDataColumns());
         $config->addComponent(new GridFieldEditButton());
         $config->addComponent(new GridFieldDeleteAction());
         $config->addComponent(new GridFieldDetailForm());
         $config->addComponent(new GridFieldSortableHeader());
         $pollChoicesTable = new GridField('Choices', 'Choices', $this->Choices(), $config);
         $fields->addFieldToTab('Root.Data', $pollChoicesTable);
         $fields->addFieldToTab('Root.Data', new ReadonlyField('Total', 'Total votes', $totalCount));
         // Display the results using the default poll chart
         $pollForm = new PollForm(new Controller(), 'PollForm', $this);
         $chartTab = new Tab("Result chart", new LiteralField('Chart', sprintf('<h1>%s</h1><p>%s</p>', $this->Title, $pollForm->getChart(), $this->Title)));
         $rootTab->push($chartTab);
     } else {
         $fields->addFieldToTab('Root.Choices', new ReadOnlyField('ChoicesPlaceholder', 'Choices', 'You will be able to add options once you have saved the poll for the first time.'));
     }
     $this->extend('updateCMSFields', $fields);
     return $fields;
 }