forkbb/app/Models/Post/UserInfoFromIP.php
2018-08-28 20:15:18 +07:00

43 lines
1.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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;
}
}