This commit is contained in:
parent
899817a853
commit
3f8311d708
@ -328,14 +328,13 @@ class Select
|
|||||||
|
|
||||||
private function generateJoins(): array
|
private function generateJoins(): array
|
||||||
{
|
{
|
||||||
$joins = $this->joins;
|
|
||||||
|
|
||||||
$joinQueries = [];
|
$joinQueries = [];
|
||||||
$params = [];
|
$params = [];
|
||||||
|
|
||||||
foreach($joins as $value) {
|
foreach($this->joins as $join) {
|
||||||
list($joinQueryFragment, $paramsFragment) = $this->generateTable($value[1], true);
|
list($joinQueryFragment, $paramsFragment) = $this->generateTable($join[1], true);
|
||||||
array_push($joinQueries, $value[0] . ' JOIN ' . $joinQueryFragment . ' ON ' . $this->generateColumn($value[2]) . ' ' . $value[3] . ' ' . $this->generateColumn($value[4]));
|
$joinQueries[] = $join[0] . ' JOIN ' . $joinQueryFragment . ' ON ' . $this->generateColumn($join[2]) . ' ' . $join[3] . ' ' . $this->generateColumn($join[4]);
|
||||||
$params = array_merge($params, $paramsFragment);
|
$params = array_merge($params, $paramsFragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,21 +35,26 @@ class PlaceRepository
|
|||||||
return $this->getRandomNForMapWithValidPano($mapId, $n);
|
return $this->getRandomNForMapWithValidPano($mapId, $n);
|
||||||
} else { // authorized user or multiplayer game with selection based on what the host played before
|
} else { // authorized user or multiplayer game with selection based on what the host played before
|
||||||
$unvisitedPlaces = $this->getRandomUnvisitedNForMapWithValidPano($mapId, $n, $userId);
|
$unvisitedPlaces = $this->getRandomUnvisitedNForMapWithValidPano($mapId, $n, $userId);
|
||||||
|
if (count($unvisitedPlaces) == $n) {
|
||||||
|
return $unvisitedPlaces;
|
||||||
|
}
|
||||||
|
|
||||||
$oldPlaces = $this->getRandomOldNForMapWithValidPano($mapId, $n - count($unvisitedPlaces), $userId);
|
$oldPlaces = $this->getRandomOldNForMapWithValidPano($mapId, $n - count($unvisitedPlaces), $userId);
|
||||||
|
|
||||||
return array_merge($unvisitedPlaces, $oldPlaces);
|
return array_merge($unvisitedPlaces, $oldPlaces);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: use Map instead of id
|
//TODO: use Map instead of id
|
||||||
public function getRandomNForMapWithValidPano(int $mapId, int $n, array $exclude = []): array
|
private function getRandomNForMapWithValidPano(int $mapId, int $n): array
|
||||||
{
|
{
|
||||||
$places = [];
|
$places = [];
|
||||||
|
|
||||||
$select = new Select(\Container::$dbConnection, 'places');
|
$select = new Select(\Container::$dbConnection, 'places');
|
||||||
$select->where('id', 'NOT IN', $exclude);
|
|
||||||
$select->where('map_id', '=', $mapId);
|
$select->where('map_id', '=', $mapId);
|
||||||
$numberOfPlaces = $select->count();
|
$numberOfPlaces = $select->count();
|
||||||
|
|
||||||
|
$exclude = [];
|
||||||
for ($i = 1; $i <= $n; ++$i) {
|
for ($i = 1; $i <= $n; ++$i) {
|
||||||
$place = $this->getRandomForMapWithValidPano($numberOfPlaces, $select, $exclude);
|
$place = $this->getRandomForMapWithValidPano($numberOfPlaces, $select, $exclude);
|
||||||
|
|
||||||
@ -60,7 +65,7 @@ class PlaceRepository
|
|||||||
return $places;
|
return $places;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getRandomForMapWithValidPano($numberOfPlaces, $select, array &$exclude, ?callable $pickRandomInt = null): ?Place
|
private function getRandomForMapWithValidPano(int $numberOfPlaces, Select $select, array &$exclude, ?callable $pickRandomInt = null): ?Place
|
||||||
{
|
{
|
||||||
do {
|
do {
|
||||||
$numberOfPlacesLeft = $numberOfPlaces - count($exclude);
|
$numberOfPlacesLeft = $numberOfPlaces - count($exclude);
|
||||||
@ -79,7 +84,7 @@ class PlaceRepository
|
|||||||
return $place;
|
return $place;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function selectRandomFromDbForMap($numberOfPlacesLeft, $select, array $exclude, ?callable $pickRandomInt): ?Place
|
private function selectRandomFromDbForMap(int $numberOfPlacesLeft, Select $select, array $exclude, ?callable $pickRandomInt): ?Place
|
||||||
{
|
{
|
||||||
if ($numberOfPlacesLeft <= 0)
|
if ($numberOfPlacesLeft <= 0)
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
Reference in New Issue
Block a user