UserStat.php 921 B

1234567891011121314151617181920212223242526272829303132333435
  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\Post;
  10. use ForkBB\Models\Action;
  11. use ForkBB\Models\Post\Post;
  12. use PDO;
  13. class UserStat extends Action
  14. {
  15. /**
  16. * Возвращает массив данных использования ip для данного пользователя
  17. */
  18. public function userStat(int $id): array
  19. {
  20. $vars = [
  21. ':id' => $id,
  22. ];
  23. $query = 'SELECT p.poster_ip, MAX(p.posted) AS last_used, COUNT(p.id) AS used_times
  24. FROM ::posts AS p
  25. WHERE p.poster_id=?i:id
  26. GROUP BY p.poster_ip
  27. ORDER BY last_used DESC';
  28. return $this->c->DB->query($query, $vars)->fetchAll(PDO::FETCH_UNIQUE);
  29. }
  30. }