gnu-social/plugins/Poll/actions/pollsettings.php

92 lines
2.5 KiB
PHP
Raw Normal View History

<?php
/**
* Form to set your personal poll settings
*
* StatusNet, the distributed open-source microblogging tool
*
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Plugins
* @package StatusNet
* @author Brion Vibber <brion@status.net>
* @copyright 2012 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
2019-06-23 00:55:40 +01:00
if (!defined('GNUSOCIAL')) {
exit(1);
}
class PollSettingsAction extends SettingsAction
{
/**
* Title of the page
*
* @return string Page title
*/
2019-06-23 00:55:40 +01:00
public function title()
{
// TRANS: Page title.
return _m('Poll settings');
}
/**
* Instructions for use
*
* @return string Instructions for use
*/
2019-06-23 00:55:40 +01:00
public function getInstructions()
{
// TRANS: Page instructions.
return _m('Set your poll preferences');
}
2015-07-17 15:19:02 +01:00
protected function getForm()
{
2015-07-17 15:19:02 +01:00
$prefs = User_poll_prefs::getKV('user_id', $this->scoped->getID());
2019-06-23 00:55:40 +01:00
$form = new PollPrefsForm($this, $prefs ? $prefs : null);
2015-07-17 15:19:02 +01:00
return $form;
}
2015-07-17 15:19:02 +01:00
protected function doPost()
{
2015-07-17 15:19:02 +01:00
$upp = User_poll_prefs::getKV('user_id', $this->scoped->getID());
$orig = null;
2015-07-17 15:19:02 +01:00
if ($upp instanceof User_poll_prefs) {
$orig = clone($upp);
} else {
$upp = new User_poll_prefs();
2015-07-17 15:19:02 +01:00
$upp->user_id = $this->scoped->getID();
$upp->created = common_sql_now();
}
$upp->hide_responses = $this->boolean('hide_responses');
2019-06-23 00:55:40 +01:00
$upp->modified = common_sql_now();
2015-07-17 15:19:02 +01:00
if ($orig instanceof User_poll_prefs) {
$upp->update($orig);
} else {
$upp->insert();
}
// TRANS: Confirmation shown when user profile settings are saved.
2015-07-17 15:19:02 +01:00
return _('Settings saved.');
}
}