oldschool settings adapted to FormAction

TODO: Rename this "Layout", "Display" or something, since it might
actually be interesting to have non-threaded views for some users.
This commit is contained in:
Mikael Nordfeldth 2015-07-17 01:18:28 +02:00
parent a6e299a2fc
commit 47ef917f62

View File

@ -28,11 +28,7 @@
* @link http://status.net/ * @link http://status.net/
*/ */
if (!defined('STATUSNET')) { if (!defined('GNUSOCIAL')) { exit(1); }
// This check helps protect against security problems;
// your code file can't be executed directly from the web.
exit(1);
}
/** /**
* Old-school settings * Old-school settings
@ -77,35 +73,23 @@ class OldschoolsettingsAction extends SettingsAction
* @return boolean true * @return boolean true
*/ */
function prepare($argarray) protected function doPreparation()
{ {
if (!common_config('oldschool', 'enabled')) { if (!common_config('oldschool', 'enabled')) {
throw new ClientException("Old-school settings not enabled."); throw new ClientException("Old-school settings not enabled.");
} }
parent::prepare($argarray);
return true;
} }
/** function doPost()
* Handler method
*
* @param array $argarray is ignored since it's now passed in in prepare()
*
* @return void
*/
function handlePost()
{ {
$user = common_current_user(); $osp = Old_school_prefs::getKV('user_id', $this->scoped->getID());
$osp = Old_school_prefs::getKV('user_id', $user->id);
$orig = null; $orig = null;
if (!empty($osp)) { if (!empty($osp)) {
$orig = clone($osp); $orig = clone($osp);
} else { } else {
$osp = new Old_school_prefs(); $osp = new Old_school_prefs();
$osp->user_id = $user->id; $osp->user_id = $this->scoped->getID();
$osp->created = common_sql_now(); $osp->created = common_sql_now();
} }
@ -113,34 +97,25 @@ class OldschoolsettingsAction extends SettingsAction
$osp->stream_nicknames = $this->boolean('stream_nicknames'); $osp->stream_nicknames = $this->boolean('stream_nicknames');
$osp->modified = common_sql_now(); $osp->modified = common_sql_now();
if (!empty($orig)) { if ($orig instanceof Old_school_prefs) {
$osp->update($orig); $osp->update($orig);
} else { } else {
$osp->insert(); $osp->insert();
} }
// TRANS: Confirmation shown when user profile settings are saved. // TRANS: Confirmation shown when user profile settings are saved.
$this->showForm(_('Settings saved.'), true); return _('Settings saved.');
return;
}
function showContent()
{
$user = common_current_user();
$form = new OldSchoolForm($this, $user);
$form->show();
} }
} }
class OldSchoolForm extends Form class OldSchoolSettingsForm extends Form
{ {
var $user; var $user;
function __construct($out, $user) function __construct(Action $out)
{ {
parent::__construct($out); parent::__construct($out);
$this->user = $user; $this->user = $out->getScoped()->getUser();
} }
/** /**