Userlist.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. namespace ForkBB\Models\Pages;
  3. use ForkBB\Models\Page;
  4. use ForkBB\Core\Validator;
  5. use ForkBB\Models\Forum\Model as Forum;
  6. use InvalidArgumentException;
  7. class Userlist extends Page
  8. {
  9. use CrumbTrait;
  10. /**
  11. * Список пользователей
  12. *
  13. * @param array $args
  14. * @param string $method
  15. *
  16. * @return Page
  17. */
  18. public function view(array $args, $method)
  19. {
  20. $this->c->Lang->load('userlist');
  21. $v = $this->c->Validator->reset()
  22. ->addRules([
  23. 'sort' => 'string|in:username,registered' . ($this->user->showPostCount ? ',num_posts' : ''),
  24. 'dir' => 'string|in:ASC,DESC',
  25. 'group' => 'integer|min:-1|max:9999999999|not_in:0,' . $this->c->GROUP_GUEST,
  26. 'name' => 'string:trim|min:1|max:25' . ($this->user->searchUsers ? '' : '|in:*'),
  27. ]);
  28. $error = true;
  29. if ($v->validation($args)) {
  30. $count = (int) (null === $v->sort)
  31. + (int) (null === $v->dir)
  32. + (int) (null === $v->group)
  33. + (int) (null === $v->name);
  34. if (0 === $count || 4 === $count) {
  35. $error = false;
  36. }
  37. }
  38. if ($error) {
  39. return $this->c->Message->message('Bad request');
  40. }
  41. $filters = [];
  42. if ($v->group < 1) {
  43. $filters['group_id'] = ['!=', 0];
  44. } else {
  45. $filters['group_id'] = ['=', $v->group];
  46. }
  47. if (null !== $v->name && '*' !== $v->name) {
  48. $filters['username'] = ['LIKE', $v->name];
  49. }
  50. $order = $v->sort ? [$v->sort => $v->dir] : [];
  51. $ids = $this->c->users->filter($filters, $order);
  52. $number = \count($ids);
  53. $page = isset($args['page']) ? (int) $args['page'] : 1;
  54. $pages = $number ? (int) \ceil($number / $this->c->config->o_disp_users) : 1;
  55. if ($page > $pages) {
  56. return $this->c->Message->message('Bad request');
  57. }
  58. if ($number) {
  59. $this->startNum = ($page - 1) * $this->c->config->o_disp_users;
  60. $ids = \array_slice($ids, $this->startNum, $this->c->config->o_disp_users);
  61. $this->userList = $this->c->users->load($ids);
  62. $links = [];
  63. $vars = ['page' => $page];
  64. if (4 === $count) {
  65. $vars['group'] = -1;
  66. $vars['name'] = '*';
  67. } else {
  68. $vars['group'] = $v->group;
  69. $vars['name'] = $v->name;
  70. }
  71. $this->active = 0;
  72. foreach (['username', 'num_posts', 'registered'] as $i => $sort) {
  73. $vars['sort'] = $sort;
  74. foreach (['ASC', 'DESC'] as $j => $dir) {
  75. $vars['dir'] = $dir;
  76. $links[$i * 2 + $j] = $this->c->Router->link('Userlist', $vars);
  77. if ($v->sort === $sort && $v->dir === $dir) {
  78. $this->active = $i * 2 + $j;
  79. }
  80. }
  81. }
  82. $this->links = $links;
  83. } else {
  84. $this->startNum = 0;
  85. $this->userList = null;
  86. // ни чего не найдено
  87. $this->links = [null, null, null, null, null, null];
  88. }
  89. $this->fIndex = 'userlist';
  90. $this->nameTpl = 'userlist';
  91. $this->onlinePos = 'userlist';
  92. $this->canonical = $this->c->Router->link('Userlist', ['page' => $page]); // ????
  93. $this->robots = 'noindex';
  94. // $this->form = $form;
  95. $this->crumbs = $this->crumbs([$this->c->Router->link('Userlist'), \ForkBB\__('User_list')]);
  96. $this->pagination = $this->c->Func->paginate($pages, $page, 'Userlist', $args);
  97. return $this;
  98. }
  99. }