* Admin -> Users

This commit is contained in:
Visman 2018-08-28 20:15:18 +07:00
parent d1f0e4360f
commit 234924b041
4 changed files with 147 additions and 4 deletions

View file

@ -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',

View file

@ -0,0 +1,43 @@
<?php
namespace ForkBB\Models\Post;
use ForkBB\Models\Action;
use ForkBB\Models\Post\Model as Post;
class UserInfoFromIP extends Action
{
/**
* Возвращает массив данных с id пользователей (именами гостей)
*
* @param string $ip
*
* @return array
*/
public function userInfoFromIP($ip)
{
$vars = [
':ip' => $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;
}
}

View file

@ -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);

View file

@ -1,4 +1,32 @@
@section ('pagination')
@if ($p->pagination)
<nav class="f-pages">
@foreach ($p->pagination as $cur)
@if ($cur[2])
<a class="f-page active" href="{!! $cur[0] !!}">{{ $cur[1] }}</a>
@elseif ('info' === $cur[1])
<span class="f-pinfo">{!! $cur[0] !!}</span>
@elseif ('space' === $cur[1])
<span class="f-page f-pspacer">{!! __('Spacer') !!}</span>
@elseif ('prev' === $cur[1])
<a rel="prev" class="f-page f-pprev" href="{!! $cur[0] !!}">{!! __('Previous') !!}</a>
@elseif ('next' === $cur[1])
<a rel="next" class="f-page f-pnext" href="{!! $cur[0] !!}">{!! __('Next') !!}</a>
@else
<a class="f-page" href="{!! $cur[0] !!}">{{ $cur[1] }}</a>
@endif
@endforeach
</nav>
@endif
@endsection
@extends ('layouts/admin')
@if ($p->pagination)
<div class="f-nav-links">
<div class="f-nlinks-b">
@yield ('pagination')
</div>
</div>
@endif
<section class="f-admin f-search-user-form">
<h2>{!! __('Results head') !!}</h2>
<div class="f-fdiv">
@ -7,3 +35,10 @@
@endif
</div>
</section>
@if ($p->pagination)
<div class="f-nav-links">
<div class="f-nlinks">
@yield ('pagination')
</div>
</div>
@endif