]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Poll/actions/pollsettings.php
Merge branch 'nightly' of git.gnu.io:gnu/gnu-social into nightly
[quix0rs-gnu-social.git] / plugins / Poll / actions / pollsettings.php
1 <?php
2 /**
3  * Form to set your personal poll settings
4  *
5  * StatusNet, the distributed open-source microblogging tool
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Plugins
23  * @package   StatusNet
24  * @author    Brion Vibber <brion@status.net>
25  * @copyright 2012 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
31     exit(1);
32 }
33
34 class PollSettingsAction extends SettingsAction
35 {
36     /**
37      * Title of the page
38      *
39      * @return string Page title
40      */
41     function title()
42     {
43         // TRANS: Page title.
44         return _m('Poll settings');
45     }
46
47     /**
48      * Instructions for use
49      *
50      * @return string Instructions for use
51      */
52
53     function getInstructions()
54     {
55         // TRANS: Page instructions.
56         return _m('Set your poll preferences');
57     }
58
59     /**
60      * Show the form for Poll
61      *
62      * @return void
63      */
64     function showContent()
65     {
66         $user = common_current_user();
67
68         $prefs = User_poll_prefs::getKV('user_id', $user->id);
69
70         $form = new PollPrefsForm($this, $prefs);
71
72         $form->show();
73     }
74
75     /**
76      * Handler method
77      *
78      * @param array $argarray is ignored since it's now passed in in prepare()
79      *
80      * @return void
81      */
82
83     function handlePost()
84     {
85         $user = common_current_user();
86
87         $upp = User_poll_prefs::getKV('user_id', $user->id);
88         $orig = null;
89
90         if (!empty($upp)) {
91             $orig = clone($upp);
92         } else {
93             $upp = new User_poll_prefs();
94             $upp->user_id = $user->id;
95             $upp->created = common_sql_now();
96         }
97
98         $upp->hide_responses = $this->boolean('hide_responses');
99         $upp->modified       = common_sql_now();
100
101         if (!empty($orig)) {
102             $upp->update($orig);
103         } else {
104             $upp->insert();
105         }
106
107         // TRANS: Confirmation shown when user profile settings are saved.
108         $this->showForm(_('Settings saved.'), true);
109
110         return;
111     }
112 }
113
114 class PollPrefsForm extends Form
115 {
116     var $prefs;
117
118     function __construct($out, $prefs)
119     {
120         parent::__construct($out);
121         $this->prefs = $prefs;
122     }
123
124     /**
125      * Visible or invisible data elements
126      *
127      * Display the form fields that make up the data of the form.
128      * Sub-classes should overload this to show their data.
129      *
130      * @return void
131      */
132
133     function formData()
134     {
135         $this->elementStart('fieldset');
136         $this->elementStart('ul', 'form_data');
137         $this->elementStart('li');
138         $this->checkbox('hide_responses',
139                         _('Do not deliver poll responses to my home timeline'),
140                         (!empty($this->prefs) && $this->prefs->hide_responses));
141         $this->elementEnd('li');
142         $this->elementEnd('ul');
143         $this->elementEnd('fieldset');
144     }
145
146     /**
147      * Buttons for form actions
148      *
149      * Submit and cancel buttons (or whatever)
150      * Sub-classes should overload this to show their own buttons.
151      *
152      * @return void
153      */
154
155     function formActions()
156     {
157         $this->submit('submit', _('Save'));
158     }
159
160     /**
161      * ID of the form
162      *
163      * Should be unique on the page. Sub-classes should overload this
164      * to show their own IDs.
165      *
166      * @return int ID of the form
167      */
168
169     function id()
170     {
171         return 'form_poll_prefs';
172     }
173
174     /**
175      * Action of the form.
176      *
177      * URL to post to. Should be overloaded by subclasses to give
178      * somewhere to post to.
179      *
180      * @return string URL to post to
181      */
182
183     function action()
184     {
185         return common_local_url('pollsettings');
186     }
187
188     /**
189      * Class of the form. May include space-separated list of multiple classes.
190      *
191      * @return string the form's class
192      */
193
194     function formClass()
195     {
196         return 'form_settings';
197     }
198 }