public function getPotentialOpponents() { $userID = $this->id; $level = $this->level; $agencySize = $this->agency_size; // get up to 10 people to list on the attack list $attackListSize = 10; $maxAgencySize = $agencySize + 5; $minAgencySize = max(array(1, $agencySize - 5)); // temporary solution for level range $minLevel = $level - 5; $maxLevel = $level + 5; $query = "SELECT * FROM users WHERE level <= ? AND level >= ? AND agency_size <= ? AND agency_size >= ? AND id != ?"; $objAllPotOpps = ConnectionFactory::SelectRowsAsClasses($query, array($maxLevel, $minLevel, $maxAgencySize, $minAgencySize, $userID), __CLASS__); if (!$objAllPotOpps || count($objAllPotOpps) < $attackListSize) { // TODO: execute further queries with higher level or agency size ranges if too few users //the next lines is temp solution if there is 1<x<attacklistsize opponents if ($objAllPotOpps) { return $objAllPotOpps; } else { return array(); } } // get random indices $randomIntegers = getRandomIntegers($attackListSize, count($objAllPotOpps)); $opponents = array(); foreach ($randomIntegers as $key => $value) { array_push($opponents, $objAllPotOpps[$key]); } return $opponents; }
public function getPotentialOpponents() { $userID = $this->id; $level = $this->level; $agencySize = $this->agency_size; $minHealth = 25; // get up to 10 people to list on the attack list $attackListSize = 15; $maxAgencySize = $agencySize + 5; $minAgencySize = max(array(1, $agencySize - 5)); // temporary solution for level range $minLevel = $level - 5 . '<br />'; $maxLevel = $level + 5 . '<br />'; /* $query = "SELECT * FROM users,agencies WHERE (users.level <= ? AND users.level >= ? OR users.agency_size <= ? AND users.agency_size >= ?) AND (users.health > $minHealth AND users.level>3) AND (users.id != agencies.user_one_id AND users.id != agencies.user_two_id AND agencies.accepted =1) AND users.id != ? GROUP BY users.id ORDER BY RAND() LIMIT $attackListSize";*/ /*$query = "SELECT * FROM users,agencies WHERE (users.level <= ? AND users.level >= ? OR users.agency_size <= ? AND users.agency_size >= ?) AND (users.health > $minHealth AND users.level>3) AND (users.id NOT IN (SELECT agencies.user_one_id FROM agencies WHERE agencies.user_two_id = $userID AND agencies.accepted =1)) AND (users.id NOT IN (SELECT agencies.user_two_id FROM agencies WHERE agencies.user_one_id = $userID AND agencies.accepted =1)) AND users.id != $userID GROUP BY users.id ORDER BY users.id LIMIT $attackListSize";*/ $query = "SELECT * FROM users WHERE (users.level <= ? AND users.level >= ?) AND users.id != {$userID} GROUP BY users.id ORDER BY users.id LIMIT {$attackListSize}"; $objAllPotOpps = ConnectionFactory::SelectRowsAsClasses($query, array($maxLevel, $minLevel), __CLASS__); if (!$objAllPotOpps || count($objAllPotOpps) < $attackListSize) { // TODO: execute further queries with higher level or agency size ranges if too few users //the next lines is temp solution if there is 1<x<attacklistsize opponents if ($objAllPotOpps) { return $objAllPotOpps; } else { return array(); } } // get random indices $randomIntegers = getRandomIntegers($attackListSize, count($objAllPotOpps)); $opponents = array(); foreach ($randomIntegers as $key => $value) { array_push($opponents, $objAllPotOpps[$key]); } return $opponents; }