From 234924b041c87b0a1e2e1871e2714e9f4752773c Mon Sep 17 00:00:00 2001 From: Visman Date: Tue, 28 Aug 2018 20:15:18 +0700 Subject: [PATCH] * Admin -> Users --- app/Models/Pages/Admin/Users.php | 65 ++++++++++++++++++++- app/Models/Post/UserInfoFromIP.php | 43 ++++++++++++++ app/Models/User/Manager.php | 8 ++- app/templates/admin/users_result.forkbb.php | 35 +++++++++++ 4 files changed, 147 insertions(+), 4 deletions(-) create mode 100644 app/Models/Post/UserInfoFromIP.php diff --git a/app/Models/Pages/Admin/Users.php b/app/Models/Pages/Admin/Users.php index 0cb2a19f..9d7ccc64 100644 --- a/app/Models/Pages/Admin/Users.php +++ b/app/Models/Pages/Admin/Users.php @@ -31,6 +31,64 @@ class Users extends Admin return $onlyKeys ? \array_keys($groups) : $groups; } + /** + * Подготавливает данные для шаблона найденных по ip пользователей + * + * @param array $args + * @param string $method + * + * @return Page + */ + public function ip(array $args, $method) + { + $ip = \filter_var($args['ip'], \FILTER_VALIDATE_IP); + if (false === $ip) { + return $this->c->Message->message('Bad request'); + } + + $this->c->Lang->load('admin_users'); + + $fromPosts = $this->c->posts->userInfoFromIP($ip); + $ids = $this->c->users->filter([ + 'registration_ip' => ['=', $ip], + ]); + $ids = \array_flip($ids); + + foreach ($fromPosts as $val) { + if (isset($ids[$val])) { + unset($ids[$val]); + } + } + $ids = \array_merge($fromPosts, $ids); + $number = \count($ids); + + if (0 == $number) { + $this->fIswev = ['i', \ForkBB\__('No users found')]; + + return $this->view([], 'GET', ['ip' => $ip]); + } + + $page = isset($args['page']) ? (int) $args['page'] : 1; + $pages = (int) \ceil($number / $this->c->config->o_disp_users); + + if ($page > $pages) { + return $this->c->Message->message('Bad request'); + } + + $startNum = ($page - 1) * $this->c->config->o_disp_users; + $ids = \array_slice($ids, $startNum, $this->c->config->o_disp_users); + $userList = $this->c->users->load($ids); + + $this->nameTpl = 'admin/users_result'; + $this->aIndex = 'users'; + $this->mainSuffix = '-one-column'; + $this->aCrumbs[] = [$this->c->Router->link('AdminShowUsersWithIP', ['ip' => $ip]), \ForkBB\__('Results head')]; + $this->formResult = $this->formUsers($userList, $startNum); + $this->pagination = $this->c->Func->paginate($pages, $page, 'AdminShowUsersWithIP', ['ip' => $ip]); + + return $this; + } + /** * Подготавливает данные для шаблона найденных по фильтру пользователей * @@ -99,7 +157,7 @@ class Users extends Admin } $startNum = ($page - 1) * $this->c->config->o_disp_users; - $ids = \array_slice($ids, $this->startNum, $this->c->config->o_disp_users); + $ids = \array_slice($ids, $startNum, $this->c->config->o_disp_users); $userList = $this->c->users->load($ids); $this->nameTpl = 'admin/users_result'; @@ -107,6 +165,7 @@ class Users extends Admin $this->mainSuffix = '-one-column'; $this->aCrumbs[] = [$this->c->Router->link('AdminShowUsersWithFilter', ['filters' => $args['filters'], 'hash' => $args['hash']]), \ForkBB\__('Results head')]; $this->formResult = $this->formUsers($userList, $startNum); + $this->pagination = $this->c->Func->paginate($pages, $page, 'AdminShowUsersWithFilter', ['filters' => $args['filters'], 'hash' => $args['hash']]); return $this; } @@ -507,6 +566,10 @@ class Users extends Admin \array_unshift($users, $this->c->users->create(['id' => -1])); foreach ($users as $user) { + if (\is_string($user)) { + $user = $this->c->users->create(['id' => 1, 'username' => $user]); + } + $fields = []; $fields["l{$number}-wrap1"] = [ 'class' => 'main-result', diff --git a/app/Models/Post/UserInfoFromIP.php b/app/Models/Post/UserInfoFromIP.php new file mode 100644 index 00000000..37ed4b62 --- /dev/null +++ b/app/Models/Post/UserInfoFromIP.php @@ -0,0 +1,43 @@ + $ip, + ]; + $sql = 'SELECT p.poster_id, p.poster + FROM ::posts AS p + WHERE p.poster_ip=?s:ip + GROUP BY p.poster_id, p.poster + ORDER BY p.poster'; + + $stmt = $this->c->DB->query($sql, $vars); + $result = []; + $ids = []; + + while ($row = $stmt->fetch()) { + if ($row['poster_id'] === 1) { + $result[] = $row['poster']; + } elseif (empty($ids[$row['poster_id']])) { + $result[] = $row['poster_id']; + $ids[$row['poster_id']] = true; + } + } + + return $result; + } +} diff --git a/app/Models/User/Manager.php b/app/Models/User/Manager.php index 75fd0aa1..b3b07b29 100644 --- a/app/Models/User/Manager.php +++ b/app/Models/User/Manager.php @@ -32,10 +32,12 @@ class Manager extends ManagerModel { if (\is_array($value)) { $result = \array_flip($value); // ???? а если пользователь не найдется? - if ($field === 'id') { + if ('id' === $field) { $temp = []; foreach ($value as $id) { - if ($this->get($id) instanceof User) { + if (\is_string($id)) { // ???? для пользователей из админки + $result[$id] = $id; + } elseif ($this->get($id) instanceof User) { $result[$id] = $this->get($id); } else { $temp[] = $id; @@ -59,7 +61,7 @@ class Manager extends ManagerModel return $result; } else { - $user = $field === 'id' ? $this->get($value) : null; + $user = 'id' === $field ? $this->get($value) : null; if (! $user instanceof User) { $user = $this->Load->load($value, $field); diff --git a/app/templates/admin/users_result.forkbb.php b/app/templates/admin/users_result.forkbb.php index 27e30d97..abd06492 100644 --- a/app/templates/admin/users_result.forkbb.php +++ b/app/templates/admin/users_result.forkbb.php @@ -1,4 +1,32 @@ +@section ('pagination') + @if ($p->pagination) + + @endif +@endsection @extends ('layouts/admin') +@if ($p->pagination) + +@endif

{!! __('Results head') !!}

@@ -7,3 +35,10 @@ @endif
+@if ($p->pagination) + +@endif