UsersNumber.php 895 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /**
  3. * This file is part of the ForkBB <https://github.com/forkbb>.
  4. *
  5. * @copyright (c) Visman <mio.visman@yandex.ru, https://github.com/MioVisman>
  6. * @license The MIT License (MIT)
  7. */
  8. declare(strict_types=1);
  9. namespace ForkBB\Models\User;
  10. use ForkBB\Models\Action;
  11. use ForkBB\Models\Group\Group;
  12. class UsersNumber extends Action
  13. {
  14. /**
  15. * Подсчет количества пользователей в группе
  16. */
  17. public function usersNumber(Group $group): int
  18. {
  19. if (
  20. empty($group->g_id)
  21. || $group->g_id === FORK_GROUP_GUEST
  22. ) {
  23. return 0;
  24. }
  25. $vars = [
  26. ':gid' => $group->g_id,
  27. ];
  28. $query = 'SELECT COUNT(u.id)
  29. FROM ::users AS u
  30. WHERE u.group_id=?i:gid';
  31. return (int) $this->c->DB->query($query, $vars)->fetchColumn();
  32. }
  33. }