forked from GNUsocial/gnu-social
[Poll] Refactoring and minor bug fixes
This commit is contained in:
@@ -52,11 +52,12 @@ class NewpollForm extends Form
|
||||
/**
|
||||
* Construct a new poll form
|
||||
*
|
||||
* @param HTMLOutputter $out output channel
|
||||
* @param HTMLOutputter $out output channel
|
||||
*
|
||||
* @return void
|
||||
* @param null $question
|
||||
* @param null $options
|
||||
*/
|
||||
function __construct($out=null, $question=null, $options=null)
|
||||
public function __construct(HTMLOutputter $out = null, $question = null, $options = null)
|
||||
{
|
||||
parent::__construct($out);
|
||||
}
|
||||
@@ -66,7 +67,7 @@ class NewpollForm extends Form
|
||||
*
|
||||
* @return int ID of the form
|
||||
*/
|
||||
function id()
|
||||
public function id()
|
||||
{
|
||||
return 'newpoll-form';
|
||||
}
|
||||
@@ -76,7 +77,7 @@ class NewpollForm extends Form
|
||||
*
|
||||
* @return string class of the form
|
||||
*/
|
||||
function formClass()
|
||||
public function formClass()
|
||||
{
|
||||
return 'form_settings ajax-notice';
|
||||
}
|
||||
@@ -86,7 +87,7 @@ class NewpollForm extends Form
|
||||
*
|
||||
* @return string URL of the action
|
||||
*/
|
||||
function action()
|
||||
public function action()
|
||||
{
|
||||
return common_local_url('newpoll');
|
||||
}
|
||||
@@ -96,20 +97,22 @@ class NewpollForm extends Form
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function formData()
|
||||
public function formData()
|
||||
{
|
||||
$this->out->elementStart('fieldset', array('id' => 'newpoll-data'));
|
||||
$this->out->elementStart('ul', 'form_data');
|
||||
|
||||
$this->li();
|
||||
$this->out->input('question',
|
||||
// TRANS: Field label on the page to create a poll.
|
||||
_m('Question'),
|
||||
$this->question,
|
||||
// TRANS: Field title on the page to create a poll.
|
||||
_m('What question are people answering?'),
|
||||
'question',
|
||||
true); // HTML5 "required" attribute
|
||||
$this->out->input(
|
||||
'question',
|
||||
// TRANS: Field label on the page to create a poll.
|
||||
_m('Question'),
|
||||
$this->question,
|
||||
// TRANS: Field title on the page to create a poll.
|
||||
_m('What question are people answering?'),
|
||||
'question',
|
||||
true
|
||||
); // HTML5 "required" attribute
|
||||
$this->unli();
|
||||
|
||||
$max = 5;
|
||||
@@ -124,22 +127,26 @@ class NewpollForm extends Form
|
||||
$default = '';
|
||||
}
|
||||
$this->li();
|
||||
$this->out->input('poll-option' . ($i + 1),
|
||||
// TRANS: Field label for an answer option on the page to create a poll.
|
||||
// TRANS: %d is the option number.
|
||||
sprintf(_m('Option %d'), $i + 1),
|
||||
$default,
|
||||
null,
|
||||
'option' . ($i + 1),
|
||||
$i<2); // HTML5 "required" attribute for 2 options
|
||||
$this->out->input(
|
||||
'poll-option' . ($i + 1),
|
||||
// TRANS: Field label for an answer option on the page to create a poll.
|
||||
// TRANS: %d is the option number.
|
||||
sprintf(_m('Option %d'), $i + 1),
|
||||
$default,
|
||||
null,
|
||||
'option' . ($i + 1),
|
||||
$i < 2
|
||||
); // HTML5 "required" attribute for 2 options
|
||||
$this->unli();
|
||||
}
|
||||
|
||||
$this->out->elementEnd('ul');
|
||||
|
||||
$toWidget = new ToSelector($this->out,
|
||||
common_current_user(),
|
||||
null);
|
||||
$toWidget = new ToSelector(
|
||||
$this->out,
|
||||
common_current_user(),
|
||||
null
|
||||
);
|
||||
$toWidget->show();
|
||||
|
||||
$this->out->elementEnd('fieldset');
|
||||
@@ -150,7 +157,7 @@ class NewpollForm extends Form
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function formActions()
|
||||
public function formActions()
|
||||
{
|
||||
// TRANS: Button text for saving a new poll.
|
||||
$this->out->submit('poll-submit', _m('BUTTON', 'Save'), 'submit', 'submit');
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
<?php
|
||||
|
||||
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||
if (!defined('GNUSOCIAL')) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
class PollPrefsForm extends Form
|
||||
{
|
||||
function __construct(Action $out, User_poll_prefs $prefs=null)
|
||||
public function __construct(Action $out, User_poll_prefs $prefs = null)
|
||||
{
|
||||
parent::__construct($out);
|
||||
$this->prefs = $prefs;
|
||||
@@ -19,14 +21,16 @@ class PollPrefsForm extends Form
|
||||
* @return void
|
||||
*/
|
||||
|
||||
function formData()
|
||||
public function formData()
|
||||
{
|
||||
$this->elementStart('fieldset');
|
||||
$this->elementStart('ul', 'form_data');
|
||||
$this->elementStart('li');
|
||||
$this->checkbox('hide_responses',
|
||||
_('Do not deliver poll responses to my home timeline'),
|
||||
($this->prefs instanceof User_poll_prefs && $this->prefs->hide_responses));
|
||||
$this->checkbox(
|
||||
'hide_responses',
|
||||
_('Do not deliver poll responses to my home timeline'),
|
||||
($this->prefs instanceof User_poll_prefs && $this->prefs->hide_responses)
|
||||
);
|
||||
$this->elementEnd('li');
|
||||
$this->elementEnd('ul');
|
||||
$this->elementEnd('fieldset');
|
||||
@@ -41,7 +45,7 @@ class PollPrefsForm extends Form
|
||||
* @return void
|
||||
*/
|
||||
|
||||
function formActions()
|
||||
public function formActions()
|
||||
{
|
||||
$this->submit('submit', _('Save'));
|
||||
}
|
||||
@@ -55,7 +59,7 @@ class PollPrefsForm extends Form
|
||||
* @return int ID of the form
|
||||
*/
|
||||
|
||||
function id()
|
||||
public function id()
|
||||
{
|
||||
return 'form_poll_prefs';
|
||||
}
|
||||
@@ -69,7 +73,7 @@ class PollPrefsForm extends Form
|
||||
* @return string URL to post to
|
||||
*/
|
||||
|
||||
function action()
|
||||
public function action()
|
||||
{
|
||||
return common_local_url('pollsettings');
|
||||
}
|
||||
@@ -80,7 +84,7 @@ class PollPrefsForm extends Form
|
||||
* @return string the form's class
|
||||
*/
|
||||
|
||||
function formClass()
|
||||
public function formClass()
|
||||
{
|
||||
return 'form_settings';
|
||||
}
|
||||
|
||||
@@ -52,11 +52,11 @@ class PollResponseForm extends Form
|
||||
* Construct a new poll form
|
||||
*
|
||||
* @param Poll $poll
|
||||
* @param HTMLOutputter $out output channel
|
||||
* @param HTMLOutputter $out output channel
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function __construct(Poll $poll, HTMLOutputter $out)
|
||||
public function __construct(Poll $poll, HTMLOutputter $out)
|
||||
{
|
||||
parent::__construct($out);
|
||||
$this->poll = $poll;
|
||||
@@ -67,7 +67,7 @@ class PollResponseForm extends Form
|
||||
*
|
||||
* @return int ID of the form
|
||||
*/
|
||||
function id()
|
||||
public function id()
|
||||
{
|
||||
return 'pollresponse-form';
|
||||
}
|
||||
@@ -77,7 +77,7 @@ class PollResponseForm extends Form
|
||||
*
|
||||
* @return string class of the form
|
||||
*/
|
||||
function formClass()
|
||||
public function formClass()
|
||||
{
|
||||
return 'form_settings ajax';
|
||||
}
|
||||
@@ -87,7 +87,7 @@ class PollResponseForm extends Form
|
||||
*
|
||||
* @return string URL of the action
|
||||
*/
|
||||
function action()
|
||||
public function action()
|
||||
{
|
||||
return common_local_url('respondpoll', array('id' => $this->poll->id));
|
||||
}
|
||||
@@ -97,18 +97,17 @@ class PollResponseForm extends Form
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function formData()
|
||||
public function formData()
|
||||
{
|
||||
$poll = $this->poll;
|
||||
$out = $this->out;
|
||||
$id = "poll-" . $poll->id;
|
||||
|
||||
$out->element('p', 'poll-question', $poll->question);
|
||||
$out->elementStart('ul', 'poll-options');
|
||||
foreach ($poll->getOptions() as $i => $opt) {
|
||||
$out->elementStart('li');
|
||||
$out->elementStart('label');
|
||||
$out->element('input', array('type' => 'radio', 'name' => 'pollselection', 'value' => $i + 1), '');
|
||||
$out->element('input', ['type' => 'radio', 'name' => 'pollselection', 'value' => $i + 1], '');
|
||||
$out->text(' ' . $opt);
|
||||
$out->elementEnd('label');
|
||||
$out->elementEnd('li');
|
||||
@@ -121,7 +120,7 @@ class PollResponseForm extends Form
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function formActions()
|
||||
public function formActions()
|
||||
{
|
||||
// TRANS: Button text for submitting a poll response.
|
||||
$this->out->submit('poll-response-submit', _m('BUTTON', 'Submit'), 'submit', 'submit');
|
||||
|
||||
@@ -52,11 +52,11 @@ class PollResultForm extends Form
|
||||
* Construct a new poll form
|
||||
*
|
||||
* @param Poll $poll
|
||||
* @param HTMLOutputter $out output channel
|
||||
* @param HTMLOutputter $out output channel
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function __construct(Poll $poll, HTMLOutputter $out)
|
||||
public function __construct(Poll $poll, HTMLOutputter $out)
|
||||
{
|
||||
parent::__construct($out);
|
||||
$this->poll = $poll;
|
||||
@@ -67,7 +67,7 @@ class PollResultForm extends Form
|
||||
*
|
||||
* @return int ID of the form
|
||||
*/
|
||||
function id()
|
||||
public function id()
|
||||
{
|
||||
return 'pollresult-form';
|
||||
}
|
||||
@@ -77,7 +77,7 @@ class PollResultForm extends Form
|
||||
*
|
||||
* @return string class of the form
|
||||
*/
|
||||
function formClass()
|
||||
public function formClass()
|
||||
{
|
||||
return 'form_settings ajax';
|
||||
}
|
||||
@@ -87,7 +87,7 @@ class PollResultForm extends Form
|
||||
*
|
||||
* @return string URL of the action
|
||||
*/
|
||||
function action()
|
||||
public function action()
|
||||
{
|
||||
return common_local_url('respondpoll', array('id' => $this->poll->id));
|
||||
}
|
||||
@@ -97,7 +97,7 @@ class PollResultForm extends Form
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function formData()
|
||||
public function formData()
|
||||
{
|
||||
$poll = $this->poll;
|
||||
$out = $this->out;
|
||||
@@ -121,9 +121,12 @@ class PollResultForm extends Form
|
||||
$out->elementEnd('td');
|
||||
|
||||
$out->elementStart('td');
|
||||
$out->element('span', array('class' => 'poll-block',
|
||||
'style' => "width: {$w}px"),
|
||||
"\xc2\xa0"); // nbsp
|
||||
$out->element(
|
||||
'span',
|
||||
array('class' => 'poll-block',
|
||||
'style' => "width: {$w}px"),
|
||||
"\xc2\xa0"
|
||||
); // nbsp
|
||||
$out->text($counts[$i]);
|
||||
$out->elementEnd('td');
|
||||
|
||||
@@ -137,7 +140,7 @@ class PollResultForm extends Form
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function formActions()
|
||||
public function formActions()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user