PMConfig.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * This file is part of the ForkBB <https://github.com/forkbb>.
  4. *
  5. * @copyright (c) Visman <mio.visman@yandex.ru, https://github.com/MioVisman>
  6. * @license The MIT License (MIT)
  7. */
  8. declare(strict_types=1);
  9. namespace ForkBB\Models\Pages\PM;
  10. use ForkBB\Core\Validator;
  11. use ForkBB\Models\Page;
  12. use ForkBB\Models\Pages\PM\AbstractPM;
  13. use ForkBB\Models\PM\Cnst;
  14. use function \ForkBB\__;
  15. class PMConfig extends AbstractPM
  16. {
  17. /**
  18. * Конфигурирование ЛС
  19. */
  20. public function config(array $args, string $method): Page
  21. {
  22. if (
  23. isset($args['more1'])
  24. || isset($args['more2'])
  25. ) {
  26. return $this->c->Message->message('Bad request');
  27. }
  28. $this->args = $args;
  29. $this->c->Lang->load('validator');
  30. if ('POST' === $method) {
  31. $v = $this->c->Validator->reset()
  32. ->addRules([
  33. 'token' => 'token:PMAction',
  34. 'u_pm' => 'required|integer|in:0,1',
  35. 'u_pm_notify' => 'required|integer|in:0,1',
  36. 'save' => 'required|string',
  37. ])->addAliases([
  38. ])->addArguments([
  39. 'token' => $args,
  40. ]);
  41. if ($v->validation($_POST)) {
  42. $this->user->u_pm = $v->u_pm;
  43. $this->user->u_pm_notify = $v->u_pm_notify;
  44. $this->c->users->update($this->user);
  45. return $this->c->Redirect->page('PMAction', $args)->message('PM Config redirect');
  46. }
  47. $this->fIswev = $v->getErrors();
  48. }
  49. $this->nameTpl = 'pm/form';
  50. $this->onlineDetail = null;
  51. $this->pmIndex = Cnst::ACTION_CONFIG;
  52. $this->formTitle = 'PM Config title';
  53. $this->formClass = 'pmconfig';
  54. $this->form = $this->formConfig($args);
  55. $this->pmCrumbs[] = [$this->c->Router->link('PMAction', $args), 'PM Config'];
  56. return $this;
  57. }
  58. /**
  59. * Подготавливает массив данных для формы
  60. */
  61. protected function formConfig(array $args): array
  62. {
  63. $yn = [1 => __('Yes'), 0 => __('No')];
  64. return [
  65. 'action' => $this->c->Router->link('PMAction', $args),
  66. 'hidden' => [
  67. 'token' => $this->c->Csrf->create('PMAction', $args),
  68. ],
  69. 'sets' => [
  70. 'config' => [
  71. 'legend' => 'PM Config legend',
  72. 'fields' => [
  73. 'u_pm' => [
  74. 'type' => 'radio',
  75. 'value' => $this->user->u_pm,
  76. 'values' => $yn,
  77. 'caption' => 'Use PM label',
  78. 'help' => 'Use PM help',
  79. ],
  80. 'u_pm_notify' => [
  81. 'type' => 'radio',
  82. 'value' => $this->user->u_pm_notify,
  83. 'values' => $yn,
  84. 'caption' => 'Email notification label',
  85. 'help' => 'Email notification help',
  86. ],
  87. ],
  88. ],
  89. ],
  90. 'btns' => [
  91. 'save' => [
  92. 'type' => 'submit',
  93. 'value' => __('Save changes'),
  94. ],
  95. ],
  96. ];
  97. }
  98. }