瀏覽代碼

2017-12-25

Visman 7 年之前
父節點
當前提交
31e0ae387d

+ 39 - 0
app/Models/Group/Delete.php

@@ -0,0 +1,39 @@
+<?php
+
+namespace ForkBB\Models\Group;
+
+use ForkBB\Models\Action;
+use ForkBB\Models\Group\Model as Group;
+use InvalidArgumentException;
+use RuntimeException;
+
+class Delete extends Action
+{
+    /**
+     * Удаляет тему(ы) 
+     *
+     * @param Group $group
+     * @param Group $new
+     *
+     * @throws InvalidArgumentException
+     * @throws RuntimeException
+     */
+    public function delete(Group $group, Group $new = null)
+    {
+        //????
+#       if (! $arg->parent instanceof Forum) {
+#           throw new RuntimeException('Parent unavailable');
+#       }
+
+        if (null !== $new) {
+            $this->c->users->promote($group, $new);
+        }
+
+        $vars = [
+            ':gid' => $group->g_id,
+        ];
+        $sql = 'DELETE FROM ::groups
+                WHERE g_id=?i:gid';
+        $this->c->DB->exec($sql, $vars);
+    }
+}

+ 1 - 1
app/Models/Group/Save.php

@@ -40,7 +40,7 @@ class Save extends Action
             return $group;
         }
         $vars[] = $group->g_id;
-        $this->c->DB->query('UPDATE ::groups SET ' . implode(', ', $set) . ' WHERE id=?i', $vars);
+        $this->c->DB->query('UPDATE ::groups SET ' . implode(', ', $set) . ' WHERE g_id=?i', $vars);
         $group->resModified();
 
         return $group;

+ 105 - 21
app/Models/Pages/Admin/Groups.php

@@ -154,18 +154,20 @@ class Groups extends Admin
             $marker          = 'AdminGroupsNew';
             $this->titles    = \ForkBB\__('Create new group');
             $this->titleForm = \ForkBB\__('Create new group');
+            $this->classForm = 'f-create-group-form';
         } else {
             $vars            = ['id' => $group->g_id];
             $marker          = 'AdminGroupsEdit';
             $this->titles    = \ForkBB\__('Edit group');
             $this->titleForm = \ForkBB\__('Edit group');
+            $this->classForm = 'f-edit-group-form';
         }
 
         if (isset($args['_data'])) {
             $group->replAttrs($args['_data']);
         }
 
-        $this->nameTpl = 'admin/group';
+        $this->nameTpl = 'admin/form';
         $this->form    = $this->viewForm($group, $marker, $vars);
 
         return $this;
@@ -298,10 +300,9 @@ class Groups extends Admin
         } else {
             $message = \ForkBB\__('Group edited redirect');
             $this->c->groups->update($group);
-            //????
-            if ($data['g_promote_next_group']) {
-                $vars = [':next' => $data['g_promote_next_group'], ':id' => $group->g_id, ':posts' => $data['g_promote_min_posts']];
-                $this->c->DB->exec('UPDATE ::users SET group_id=?i:next WHERE group_id=?i:id AND num_posts>=?i:posts', $vars);
+
+            if ($group->g_promote_min_posts) {
+                $this->c->users->promote($group);
             }
         }
 
@@ -606,6 +607,8 @@ class Groups extends Admin
             return $this->c->Message->message('Bad request');
         }
 
+        $count = $this->c->users->UsersNumber($group);
+
         $form = [
             'action' => $this->c->Router->link('AdminGroupsDelete', $args),
             'hidden' => [
@@ -618,26 +621,38 @@ class Groups extends Admin
                     'value'     => \ForkBB\__('Delete group'),
                     'accesskey' => 'd',
                 ],
+                'cancel'  => [
+                    'type'      => 'submit',
+                    'value'     => \ForkBB\__('Cancel'),
+                ],
             ],
         ];
 
-        $form['sets'][] = [
-            'info' => [
-                'info1' => [
-                    'type'  => '', //????
-                    'value' => \ForkBB\__('Confirm delete warn'),
+        if ($count) {
+            $groups = [];
+            foreach ($this->groupsList as $key => $cur) {
+                if ($key === $this->c->GROUP_GUEST || $key === $group->g_id) {
+                    continue;
+                }
+                $groups[$key] = $cur[0];
+            }
+
+            $form['sets'][] = [
+                'fields' => [
+                    'movegroup' => [
+                        'type'      => 'select',
+                        'options'   => $groups,
+                        'value'     => $this->c->config->o_default_user_group,
+                        'title'     => \ForkBB\__('Move users label'),
+                        'info'      => \ForkBB\__('Move users info', $group->g_title, $count),
+                    ],
                 ],
-#                'info2' => [
-#                    'type'  => '', //????
-#                    'value' => \ForkBB\__('Confirm delete info', $group->g_title),
-#                    'html'  => true,
-#                ],
-            ],
-        ];
+            ];
+        }
+
         $form['sets'][] = [
             'fields' => [
                 'confirm' => [
-#                    'dl'      => 'full',
                     'title'   => \ForkBB\__('Confirm delete'),
                     'type'    => 'checkbox',
                     'label'   => \ForkBB\__('I want to delete this group', $group->g_title),
@@ -646,11 +661,80 @@ class Groups extends Admin
                 ],
             ],
         ];
+        $form['sets'][] = [
+            'info' => [
+                'info1' => [
+                    'type'  => '', //????
+                    'value' => \ForkBB\__('Confirm delete warn'),
+                ],
+            ],
+        ];
 
-        $this->nameTpl = 'admin/group_delete';
-        $this->titles  = \ForkBB\__('Group delete');
-        $this->form    = $form;
+        $this->nameTpl   = 'admin/form';
+        $this->titles    = \ForkBB\__('Group delete');
+        $this->titleForm = \ForkBB\__('Group delete');
+        $this->classForm = 'f-delete-group-form';
+        $this->form      = $form;
 
         return $this;
     }
+
+    /**
+     * Удаление группы
+     *
+     * @param array $args
+     * 
+     * @return Page
+     */
+    public function deletePost(array $args)
+    {
+        $group = $this->c->groups->get((int) $args['id']);
+
+        if (null === $group || ! $group->canDelete) {
+            return $this->c->Message->message('Bad request');
+        }
+
+        $count = $this->c->users->UsersNumber($group);
+        if ($count) {
+            $move   = 'required|integer|in:';
+            $groups = [];
+            foreach ($this->groupsList as $key => $cur) {
+                if ($key === $this->c->GROUP_GUEST || $key === $group->g_id) {
+                    continue;
+                }
+                $groups[$key] = $cur[0];
+            }
+            $move  .= implode(',', array_keys($groups));
+        } else {
+            $move   = 'absent';
+        }
+
+        $v = $this->c->Validator->setRules([
+            'token'     => 'token:AdminGroupsDelete',
+            'movegroup' => $move,
+            'confirm'   => 'integer',
+            'delete'    => 'string',
+            'cancel'    => 'string',
+        ])->setArguments([
+            'token' => $args,
+        ]);
+
+        if (! $v->validation($_POST) || null === $v->delete) {
+            return $this->c->Redirect->page('AdminGroups')->message(\ForkBB\__('Cancel redirect'));
+        } elseif ($v->confirm !== 1) {
+            return $this->c->Redirect->page('AdminGroups')->message(\ForkBB\__('No confirm redirect'));
+        }
+
+        $this->c->DB->beginTransaction();
+
+        if ($v->movegroup) {
+            $this->c->groups->delete($group, $this->c->groups->get($v->movegroup));
+        } else {
+            $this->c->groups->delete($group);
+        }
+
+        $this->c->DB->commit();
+
+        return $this->c->Redirect->page('AdminGroups')->message(\ForkBB\__('Group removed redirect'));
+    }
 }

+ 3 - 1
app/Models/Pages/Auth.php

@@ -47,6 +47,8 @@ class Auth extends Page
     {
         $this->c->Lang->load('auth');
 
+        $save = empty($args) || ! empty($args['_save']);
+
         if (! isset($args['_username'])) {
             $args['_username'] = '';
         }
@@ -66,7 +68,7 @@ class Auth extends Page
         $this->regLink    = $this->c->config->o_regs_allow == '1' ? $this->c->Router->link('Register') : null;
         $this->username   = $args['_username'];
         $this->redirect   = $args['_redirect'];
-        $this->save       = ! empty($args['_save']);
+        $this->save       = $save;
 
         return $this;
     }

+ 50 - 0
app/Models/User/Promote.php

@@ -0,0 +1,50 @@
+<?php
+
+namespace ForkBB\Models\User;
+
+use ForkBB\Models\Action;
+use ForkBB\Models\User\Model as User;
+use ForkBB\Models\Group\Model as Group;
+use RuntimeException;
+
+class Promote extends Action
+{
+    /**
+     * Обновляет данные пользователя
+     *
+     * @param mixed ...$args
+     * 
+     * @throws RuntimeException
+     * 
+     * @return int
+     */
+    public function promote(...$args)
+    {
+        $count = count($args);
+
+        // перемещение всех пользователей из группы 0 в группу 1
+        if (2 == $count && $args[0] instanceof Group && $args[1] instanceof Group) {
+            $vars = [
+                ':old' => $args[0]->g_id,
+                ':new' => $args[1]->g_id,
+            ];
+            $sql = 'UPDATE ::users 
+                    SET group_id=?i:new 
+                    WHERE group_id=?i:old';
+            return $this->c->DB->exec($sql, $vars);
+        // продвижение всех пользователей в группе 0
+        } elseif (1 == $count && $args[0] instanceof Group) {
+            $vars = [
+                ':old'   => $args[0]->g_id,
+                ':new'   => $args[0]->g_promote_next_group,
+                ':count' => $args[0]->g_promote_min_posts,
+            ];
+            $sql = 'UPDATE ::users 
+                    SET group_id=?i:new 
+                    WHERE group_id=?i:old AND num_posts>=?i:count';
+            return $this->c->DB->exec($sql, $vars);
+        } else {
+            throw new InvalidArgumentException("Unexpected parameters type, Illegal number of parameters ({$count})");
+        }
+    }
+}

+ 30 - 0
app/Models/User/UsersNumber.php

@@ -0,0 +1,30 @@
+<?php
+
+namespace ForkBB\Models\User;
+
+use ForkBB\Models\Action;
+use ForkBB\Models\Group\Model as Group;
+
+class UsersNumber extends Action
+{
+    /**
+     * Подсчет количества пользователей в группе
+     * 
+     * @param Group $group
+     * 
+     * @return int
+     */
+    public function UsersNumber(Group $group)
+    {
+        if (empty($group->g_id) || $group->g_id === $this->c->GROUP_GUEST) {
+            return 0;
+        }
+
+        $vars = [
+            ':gid' => $group->g_id,
+        ];
+        $sql = 'SELECT COUNT(id) FROM ::users WHERE group_id=?i:gid';
+
+        return $this->c->DB->query($sql, $vars)->fetchColumn();
+    }
+}

+ 1 - 1
app/lang/English/admin_groups.po

@@ -88,7 +88,7 @@ msgid "Move users subhead"
 msgstr "Move users currently in group"
 
 msgid "Move users info"
-msgstr "The group <strong>%s</strong> currently has <strong>%s</strong> members. Please select a group to which these members will be assigned upon deletion."
+msgstr "The group <b>%1$s</b> currently has <b>%2$s</b> members. Please select a group to which these members will be assigned upon deletion."
 
 msgid "Move users label"
 msgstr "Move users to"

+ 1 - 1
app/lang/Russian/admin_groups.po

@@ -88,7 +88,7 @@ msgid "Move users subhead"
 msgstr "Перемещение пользователей группы"
 
 msgid "Move users info"
-msgstr "В группе <strong>%s</strong> сейчас состоит <strong>%s</strong> участник(ов). Пожалуйста выберите группу, в которую следует перенести этих пользователей."
+msgstr "В группе <b>%1$s</b> сейчас состоит <b>%2$s</b> участник(ов). Пожалуйста, выберите группу, в которую следует перенести этих пользователей."
 
 msgid "Move users label"
 msgstr "Перенести в"

+ 1 - 1
app/templates/admin/group.tpl → app/templates/admin/form.tpl

@@ -1,5 +1,5 @@
 @extends ('layouts/admin')
-      <section class="f-admin">
+      <section class="f-admin @if ($p->classForm) {!! $p->classForm !!} @endif">
         <h2>{!! $p->titleForm !!}</h2>
         <div class="f-fdiv">
 @if ($form = $p->form)

+ 0 - 9
app/templates/admin/group_delete.tpl

@@ -1,9 +0,0 @@
-@extends ('layouts/admin')
-      <section class="f-admin">
-        <h2>{!! __('Group delete') !!}</h2>
-        <div class="f-fdiv">
-@if ($form = $p->form)
-  @include ('layouts/form')
-@endif
-        </div>
-      </section>

+ 8 - 2
public/style/ForkBB/style.css

@@ -473,7 +473,8 @@ select {
 }
 
 .f-fdiv .f-child2 > input {
-  margin: 0 0.625rem 0 0;
+/*  margin: 0 0.625rem 0 0; */
+  margin-right: 0.625rem;
 }
 
 .f-fdiv .f-btns {
@@ -1521,11 +1522,16 @@ li + li .f-btn {
   border: 0;
 }
 
-.f-post-form .f-btn {
+.f-post-form .f-btn,
+.f-delete-group-form .f-btn {
   width: auto;
   display: inline;
 }
 
+.f-delete-group-form .f-btns {
+  text-align: center;
+}
+
 #id-message {
   height: 11rem;
 }