NOW()' ); return $result !== false ? (int) $result : 0; } public static function deleteById(int $id): bool { $result = DB::delete('delete from user_remember_tokens where id = ?', (string) $id); return $result !== false; } public static function deleteByUserId(int $userId): bool { $result = DB::delete('delete from user_remember_tokens where user_id = ?', (string) $userId); return $result !== false; } public static function listByUserId(int $userId, int $limit = 20): array { if ($userId <= 0) { return []; } if ($limit < 1) { $limit = 20; } elseif ($limit > 100) { $limit = 100; } $rows = DB::select( 'select id, user_id, selector, expires_at, expired_by_admin_at, last_used, created from user_remember_tokens where user_id = ? order by id desc limit ?', (string) $userId, (string) $limit ); return self::unwrapList($rows); } public static function countActive(): int { $count = DB::selectValue('select count(*) from user_remember_tokens where expires_at > NOW()'); return $count ? (int) $count : 0; } }