Parcourir la source

* Fixed setting default values for topics and posts per page in user profile

Visman il y a 6 ans
Parent
commit
c39624d53a
3 fichiers modifiés avec 22 ajouts et 8 suppressions
  1. 20 6
      app/Models/Pages/Profile/Config.php
  2. 1 1
      app/lang/en/profile.po
  3. 1 1
      app/lang/ru/profile.po

+ 20 - 6
app/Models/Pages/Profile/Config.php

@@ -26,6 +26,7 @@ class Config extends Profile
         if ('POST' === $method) {
             $v = $this->c->Validator->reset()
                 ->addValidators([
+                    'to_zero' => [$this, 'vToZero'],
                 ])->addRules([
                     'token'        => 'token:EditUserBoardConfig',
                     'language'     => 'required|string:trim|in:' . \implode(',', $this->c->Func->getLangs()),
@@ -39,8 +40,8 @@ class Config extends Profile
                     'show_avatars' => 'required|integer|in:0,1',
                     'show_img'     => 'required|integer|in:0,1',
                     'show_img_sig' => 'required|integer|in:0,1',
-                    'disp_topics'  => 'integer|min:10|max:50',
-                    'disp_posts'   => 'integer|min:10|max:50',
+                    'disp_topics'  => 'integer|min:0|max:50|to_zero',
+                    'disp_posts'   => 'integer|min:0|max:50|to_zero',
                 ])->addAliases([
                     'language'     => 'Language',
                     'style'        => 'Style',
@@ -81,6 +82,19 @@ class Config extends Profile
         return $this;
     }
 
+    /**
+     * Преобразовывает число меньше 10 в 0
+     *
+     * @param Validator $v
+     * @param int $value
+     *
+     * @return string
+     */
+    public function vToZero(Validator $v, $value)
+    {
+        return $value < 10 ? 0 : $value;
+    }
+
     /**
      * Создает массив данных для формы
      *
@@ -247,17 +261,17 @@ class Config extends Profile
             'fields' => [
                 'disp_topics' => [
                     'type'    => 'number',
-                    'min'     => 10,
+                    'min'     => 0,
                     'max'     => 50,
-                    'value'   => $this->curUser->disp_topics,
+                    'value'   => $this->curUser->__disp_topics,
                     'caption' => \ForkBB\__('Topics per page label'),
                     'info'    => \ForkBB\__('For default'),
                 ],
                 'disp_posts' => [
                     'type'    => 'number',
-                    'min'     => 10,
+                    'min'     => 0,
                     'max'     => 50,
-                    'value'   => $this->curUser->disp_posts,
+                    'value'   => $this->curUser->__disp_posts,
                     'caption' => \ForkBB\__('Posts per page label'),
                     'info'    => \ForkBB\__('For default'),
                 ],

+ 1 - 1
app/lang/en/profile.po

@@ -499,7 +499,7 @@ msgid "Default"
 msgstr "Default"
 
 msgid "For default"
-msgstr "Clean this field for the default settings."
+msgstr "Zero this field for the default settings."
 
 msgid "Time format"
 msgstr "Time format"

+ 1 - 1
app/lang/ru/profile.po

@@ -499,7 +499,7 @@ msgid "Default"
 msgstr "По умолчанию"
 
 msgid "For default"
-msgstr "Очистите поле для использования значения по умолчанию."
+msgstr "Обнулите поле для использования значения по умолчанию."
 
 msgid "Time format"
 msgstr "Формат времени"