pollsettings.php 2.5 KB

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