123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- /**
- * This file is part of the ForkBB <https://github.com/forkbb>.
- *
- * @copyright (c) Visman <mio.visman@yandex.ru, https://github.com/MioVisman>
- * @license The MIT License (MIT)
- */
- declare(strict_types=1);
- namespace ForkBB\Models\Pages\PM;
- use ForkBB\Core\Validator;
- use ForkBB\Models\Page;
- use ForkBB\Models\Pages\PM\AbstractPM;
- use ForkBB\Models\PM\Cnst;
- use function \ForkBB\__;
- class PMConfig extends AbstractPM
- {
- /**
- * Конфигурирование ЛС
- */
- public function config(array $args, string $method): Page
- {
- if (
- isset($args['more1'])
- || isset($args['more2'])
- ) {
- return $this->c->Message->message('Bad request');
- }
- $this->args = $args;
- $this->c->Lang->load('validator');
- if ('POST' === $method) {
- $v = $this->c->Validator->reset()
- ->addRules([
- 'token' => 'token:PMAction',
- 'u_pm' => 'required|integer|in:0,1',
- 'u_pm_notify' => 'required|integer|in:0,1',
- 'save' => 'required|string',
- ])->addAliases([
- ])->addArguments([
- 'token' => $args,
- ]);
- if ($v->validation($_POST)) {
- $this->user->u_pm = $v->u_pm;
- $this->user->u_pm_notify = $v->u_pm_notify;
- $this->c->users->update($this->user);
- return $this->c->Redirect->page('PMAction', $args)->message('PM Config redirect');
- }
- $this->fIswev = $v->getErrors();
- }
- $this->nameTpl = 'pm/form';
- $this->onlineDetail = null;
- $this->pmIndex = Cnst::ACTION_CONFIG;
- $this->formTitle = 'PM Config title';
- $this->formClass = 'pmconfig';
- $this->form = $this->formConfig($args);
- $this->pmCrumbs[] = [$this->c->Router->link('PMAction', $args), 'PM Config'];
- return $this;
- }
- /**
- * Подготавливает массив данных для формы
- */
- protected function formConfig(array $args): array
- {
- $yn = [1 => __('Yes'), 0 => __('No')];
- return [
- 'action' => $this->c->Router->link('PMAction', $args),
- 'hidden' => [
- 'token' => $this->c->Csrf->create('PMAction', $args),
- ],
- 'sets' => [
- 'config' => [
- 'legend' => 'PM Config legend',
- 'fields' => [
- 'u_pm' => [
- 'type' => 'radio',
- 'value' => $this->user->u_pm,
- 'values' => $yn,
- 'caption' => 'Use PM label',
- 'help' => 'Use PM help',
- ],
- 'u_pm_notify' => [
- 'type' => 'radio',
- 'value' => $this->user->u_pm_notify,
- 'values' => $yn,
- 'caption' => 'Email notification label',
- 'help' => 'Email notification help',
- ],
- ],
- ],
- ],
- 'btns' => [
- 'save' => [
- 'type' => 'submit',
- 'value' => __('Save changes'),
- ],
- ],
- ];
- }
- }
|