mapguesser/src/Repository/MapRepository.php
Pőcze Bence c02e35580f
All checks were successful
mapguesser/pipeline/pr-develop This commit looks good
use sql field names with tables where join happens
2023-05-02 18:10:22 +02:00

31 lines
1020 B
PHP

<?php namespace MapGuesser\Repository;
use SokoWeb\Database\Query\Select;
use MapGuesser\PersistentData\Model\Challenge;
use MapGuesser\PersistentData\Model\Map;
use MapGuesser\PersistentData\Model\Place;
class MapRepository
{
public function getById(int $mapId): ?Map
{
return \Container::$persistentDataManager->selectFromDbById($mapId, Map::class);
}
public function getByPlace(Place $place): ?Map
{
return $this->getById($place->getMapId());
}
public function getByChallenge(Challenge $challenge): ?Map
{
$select = new Select(\Container::$dbConnection);
$select->innerJoin('places', ['maps', 'id'], '=', ['places', 'map_id']);
$select->innerJoin('place_in_challenge', ['places', 'id'], '=', ['place_in_challenge', 'place_id']);
$select->where(['place_in_challenge', 'challenge_id'], '=', $challenge->getId());
$select->limit(1);
return \Container::$persistentDataManager->selectFromDb($select, Map::class);
}
}