/** * Returns a paginate result of all players * * @param int $limit * @param null $names * * @return \Illuminate\Pagination\Paginator */ public function getAllPlayers($limit = 100, $names = null) { if ($limit === false || $limit > 100) { $limit = 100; } $query = Player::with('ban', 'infractionsGlobal', 'infractionsServer.server', 'reputation'); $names = new Collection(explode(',', $names)); $soldierNames = []; if (!empty($names)) { $query->where(function ($q) use(&$names, &$soldierNames) { $names->each(function ($name) use(&$q, &$soldierNames) { // Checks if string is an EAGUID if (preg_match('/^EA_([0-9A-Z]{32}+)$/', $name, $matches)) { $eaguid = sprintf('EA_%s', $matches[1]); $q->orWhere('EAGUID', '=', $eaguid); } elseif (preg_match('/^([a-f0-9]+)$/', $name, $matches)) { $pbguid = trim($matches[1]); $q->orWhere('PBGUID', '=', $pbguid); } elseif (preg_match("/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]?|[0-9])\$/", $name, $matches)) { $ip = trim($name); $q->orWhere('IP_Address', '=', $ip); } elseif (preg_match("/^\\*?([a-zA-Z0-9\\_\\-\\|]+)\$/", $name, $matches)) { if (substr($matches[0], 0, 1) === '*') { $name = sprintf('%%%s%%', $matches[1]); } else { $name = sprintf('%s%%', $matches[1]); } if (isset($matches[1]) && !empty($matches[1])) { $q->orWhere('SoldierName', 'LIKE', $name); $soldierNames[] = $name; } } }); }); if (!empty($soldierNames)) { $playerIds = Player::whereIn('PlayerID', function ($q) use(&$soldierNames) { $q->select('target_id')->from('adkats_records_main')->where(function ($q2) use(&$soldierNames) { foreach ($soldierNames as $name) { $q2->orWhere('record_message', 'LIKE', $name); } })->where('command_type', 48); })->lists('PlayerID'); if (!empty($playerIds)) { $query->orWhereIn('PlayerID', $playerIds); } } return $query->paginate($limit); } $query->orderBy('PlayerID', 'ASC'); return $query->simplePaginate($limit); }