فهرست منبع

Add function to recalculate the number of users posts to the Admin/Users page

Visman 5 سال پیش
والد
کامیت
4887ccbfce

+ 6 - 0
app/Controllers/Routing.php

@@ -415,6 +415,12 @@ class Routing
                     'AdminUsersNew:view',
                     'AdminUsersNew'
                 );
+                $r->add(
+                    $r::PST,
+                    '/admin/users/recalculate',
+                    'AdminUsers:recalculate',
+                    'AdminUsersRecalculate'
+                );
             }
 
             if ($this->c->userRules->banUsers) {

+ 67 - 3
app/Models/Pages/Admin/Users/View.php

@@ -126,7 +126,8 @@ class View extends Users
         }
 
         if ($this->user->isAdmin) {
-            $this->formNew = $this->formNew();
+            $this->formNew         = $this->formNew();
+            $this->formRecalculate = $this->formRecalculate();
         }
 
         return $this;
@@ -142,11 +143,16 @@ class View extends Users
         $form = [
             'action' => $this->c->Router->link('AdminUsers'),
             'hidden' => [],
-            'sets'   => [],
+            'sets'   => [
+                'new' => [
+                    'legend' => __('New user'),
+                    'fields' => [],
+                ]
+            ],
             'btns'   => [
                 'new' => [
                     'type'      => 'btn',
-                    'value'     => __('New user'),
+                    'value'     => __('Add'),
                     'link'      => $this->c->Router->link('AdminUsersNew'),
                     'accesskey' => 'n',
                 ],
@@ -420,4 +426,62 @@ class View extends Users
 
         return $form;
     }
+
+    /**
+     * Пересчитывает количество сообщений пользователей
+     *
+     * @param array $args
+     * @param string $method
+     *
+     * @return Page
+     */
+    public function recalculate(array $args, string $method): Page
+    {
+        $v = $this->c->Validator->reset()
+        ->addValidators([
+        ])->addRules([
+            'token' => 'token:AdminUsersRecalculate',
+        ])->addAliases([
+        ])->addArguments([
+        ])->addMessages([
+        ]);
+
+        if (! $v->validation($_POST)) {
+            return $this->c->Message->message('Bad token');
+        }
+
+        $this->c->users->updateCountPosts();
+
+        return $this->c->Redirect->page('AdminUsers')->message('Updated the number of users posts redirect');
+    }
+
+    /**
+     * Создает массив данных для формы пересчета количества сообщений
+     *
+     * @return array
+     */
+    protected function formRecalculate(): array
+    {
+        $form = [
+            'action' => $this->c->Router->link('AdminUsersRecalculate'),
+            'hidden' => [
+                'token' => $this->c->Csrf->create('AdminUsersRecalculate'),
+            ],
+            'sets'   => [
+                'recalculate' => [
+                    'legend' => __('Number of users posts'),
+                    'fields' => [],
+                ]
+            ],
+            'btns'   => [
+                'recalculate' => [
+                    'type'      => 'submit',
+                    'value'     => __('Recalculate'),
+                    'accesskey' => 'r',
+                ],
+            ],
+        ];
+
+        return $form;
+    }
 }

+ 12 - 0
app/lang/en/admin_users.po

@@ -371,3 +371,15 @@ msgstr "Add user"
 
 msgid "New user added redirect"
 msgstr "New user added. Redirecting …"
+
+msgid "Updated the number of users posts redirect"
+msgstr "Updated the number of users posts. Redirecting …"
+
+msgid "Recalculate"
+msgstr "Recalculate"
+
+msgid "Recalculate head"
+msgstr "Recalculation of the number of users posts"
+
+msgid "Number of users posts"
+msgstr "Number of users posts"

+ 12 - 0
app/lang/ru/admin_users.po

@@ -371,3 +371,15 @@ msgstr "Добавление пользователя"
 
 msgid "New user added redirect"
 msgstr "Новый пользователь добавлен. Переадресация …"
+
+msgid "Updated the number of users posts redirect"
+msgstr "Сообщения пользователей пересчитаны. Переадресация …"
+
+msgid "Recalculate"
+msgstr "Пересчитать"
+
+msgid "Recalculate head"
+msgstr "Пересчет количества сообщений пользователей"
+
+msgid "Number of users posts"
+msgstr "Количество сообщений пользователей"

+ 8 - 0
app/templates/admin/users.forkbb.php

@@ -23,3 +23,11 @@
         </div>
       </section>
 @endif
+@if ($form = $p->formRecalculate)
+      <section class="f-admin f-recalculate-form">
+        <h2>{!! __('Recalculate head') !!}</h2>
+        <div class="f-fdiv">
+    @include ('layouts/form')
+        </div>
+      </section>
+@endif

+ 1 - 1
app/templates/layouts/form.forkbb.php

@@ -17,7 +17,7 @@
         @foreach ($setVal['info'] as $key => $cur)
           <p class="f-finfo"> @if ($cur['html']){!! $cur['value'] !!} @else{{ $cur['value'] }} @endif</p>
         @endforeach
-    @elseif ($setVal['fields'])
+    @elseif (isset($setVal['fields']))
           <fieldset id="id-fs-{{ $setKey }}" @if ($setVal['class']) class="f-fs-{!! \implode(' f-fs-', (array) $setVal['class']) !!}" @endif>
         @if ($setVal['legend'])
             <legend>{!! $setVal['legend'] !!}</legend>