]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Poll/newpollform.php
Localisation updates from http://translatewiki.net.
[quix0rs-gnu-social.git] / plugins / Poll / newpollform.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2011, StatusNet, Inc.
5  *
6  * Form for adding a new poll
7  *
8  * PHP version 5
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Affero General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Affero General Public License for more details.
19  *
20  * You should have received a copy of the GNU Affero General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  * @category  PollPlugin
24  * @package   StatusNet
25  * @author    Brion Vibber <brion@status.net>
26  * @copyright 2011 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28  * @link      http://status.net/
29  */
30
31 if (!defined('STATUSNET')) {
32     // This check helps protect against security problems;
33     // your code file can't be executed directly from the web.
34     exit(1);
35 }
36
37 /**
38  * Form to add a new poll thingy
39  *
40  * @category  PollPlugin
41  * @package   StatusNet
42  * @author    Brion Vibber <brion@status.net>
43  * @copyright 2011 StatusNet, Inc.
44  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
45  * @link      http://status.net/
46  */
47 class NewpollForm extends Form
48 {
49     protected $question = null;
50     protected $options = array();
51
52     /**
53      * Construct a new poll form
54      *
55      * @param HTMLOutputter $out         output channel
56      *
57      * @return void
58      */
59     function __construct($out=null, $question=null, $options=null)
60     {
61         parent::__construct($out);
62     }
63
64     /**
65      * ID of the form
66      *
67      * @return int ID of the form
68      */
69     function id()
70     {
71         return 'newpoll-form';
72     }
73
74     /**
75      * class of the form
76      *
77      * @return string class of the form
78      */
79     function formClass()
80     {
81         return 'form_settings ajax-notice';
82     }
83
84     /**
85      * Action of the form
86      *
87      * @return string URL of the action
88      */
89     function action()
90     {
91         return common_local_url('newpoll');
92     }
93
94     /**
95      * Data elements of the form
96      *
97      * @return void
98      */
99     function formData()
100     {
101         $this->out->elementStart('fieldset', array('id' => 'newpoll-data'));
102         $this->out->elementStart('ul', 'form_data');
103
104         $this->li();
105         $this->out->input('question',
106                           // TRANS: Field label on the page to create a poll.
107                           _m('Question'),
108                           $this->question,
109                           // TRANS: Field title on the page to create a poll.
110                           _m('What question are people answering?'));
111         $this->unli();
112
113         $max = 5;
114         if (count($this->options) + 1 > $max) {
115             $max = count($this->options) + 2;
116         }
117         for ($i = 0; $i < $max; $i++) {
118             // @fixme make extensible
119             if (isset($this->options[$i])) {
120                 $default = $this->options[$i];
121             } else {
122                 $default = '';
123             }
124             $this->li();
125             $this->out->input('poll-option' . ($i + 1),
126                               // TRANS: Field label for an answer option on the page to create a poll.
127                               // TRANS: %d is the option number.
128                               sprintf(_m('Option %d'), $i + 1),
129                               $default,
130                               null,
131                               'option' . ($i + 1));
132             $this->unli();
133         }
134
135         $this->out->elementEnd('ul');
136
137         $toWidget = new ToSelector($this->out,
138                                    common_current_user(),
139                                    null);
140         $toWidget->show();
141
142         $this->out->elementEnd('fieldset');
143     }
144
145     /**
146      * Action elements
147      *
148      * @return void
149      */
150     function formActions()
151     {
152         // TRANS: Button text for saving a new poll.
153         $this->out->submit('poll-submit', _m('BUTTON', 'Save'), 'submit', 'submit');
154     }
155 }