]> 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('GNUSOCIAL')) { exit(1); }
31
32 class PollSettingsAction extends SettingsAction
33 {
34     /**
35      * Title of the page
36      *
37      * @return string Page title
38      */
39     function title()
40     {
41         // TRANS: Page title.
42         return _m('Poll settings');
43     }
44
45     /**
46      * Instructions for use
47      *
48      * @return string Instructions for use
49      */
50
51     function getInstructions()
52     {
53         // TRANS: Page instructions.
54         return _m('Set your poll preferences');
55     }
56
57     protected function getForm()
58     {
59         $prefs = User_poll_prefs::getKV('user_id', $this->scoped->getID());
60         $form = new PollPrefsForm($this, $prefs);
61         return $form;
62     }
63
64     protected function doPost()
65     {
66         $upp = User_poll_prefs::getKV('user_id', $this->scoped->getID());
67         $orig = null;
68
69         if ($upp instanceof User_poll_prefs) {
70             $orig = clone($upp);
71         } else {
72             $upp = new User_poll_prefs();
73             $upp->user_id = $this->scoped->getID();
74             $upp->created = common_sql_now();
75         }
76
77         $upp->hide_responses = $this->boolean('hide_responses');
78         $upp->modified       = common_sql_now();
79
80         if ($orig instanceof User_poll_prefs) {
81             $upp->update($orig);
82         } else {
83             $upp->insert();
84         }
85
86         // TRANS: Confirmation shown when user profile settings are saved.
87         return _('Settings saved.');
88     }
89 }