2020-06-01 21:13:02 +02:00
|
|
|
<?php namespace MapGuesser\Controller;
|
|
|
|
|
|
|
|
use MapGuesser\Database\Query\Select;
|
2020-06-09 00:56:00 +02:00
|
|
|
use MapGuesser\Interfaces\Authentication\IUser;
|
2020-06-07 23:37:01 +02:00
|
|
|
use MapGuesser\Interfaces\Authorization\ISecured;
|
2020-06-01 21:13:02 +02:00
|
|
|
use MapGuesser\Interfaces\Database\IResultSet;
|
2020-06-09 00:56:00 +02:00
|
|
|
use MapGuesser\Interfaces\Request\IRequest;
|
2020-06-01 21:13:02 +02:00
|
|
|
use MapGuesser\Interfaces\Response\IContent;
|
2020-06-02 01:16:59 +02:00
|
|
|
use MapGuesser\Repository\PlaceRepository;
|
2020-06-01 21:13:02 +02:00
|
|
|
use MapGuesser\Response\HtmlContent;
|
2020-06-02 21:44:01 +02:00
|
|
|
use MapGuesser\Response\JsonContent;
|
2020-06-01 21:13:02 +02:00
|
|
|
use MapGuesser\Util\Geo\Bounds;
|
|
|
|
|
2020-06-07 23:37:01 +02:00
|
|
|
class MapAdminController implements ISecured
|
2020-06-01 21:13:02 +02:00
|
|
|
{
|
2020-06-09 00:56:00 +02:00
|
|
|
private IRequest $request;
|
|
|
|
|
2020-06-02 01:16:59 +02:00
|
|
|
private PlaceRepository $placeRepository;
|
|
|
|
|
2020-06-09 00:56:00 +02:00
|
|
|
public function __construct(IRequest $request)
|
2020-06-02 01:16:59 +02:00
|
|
|
{
|
2020-06-09 00:56:00 +02:00
|
|
|
$this->request = $request;
|
2020-06-02 01:16:59 +02:00
|
|
|
$this->placeRepository = new PlaceRepository();
|
|
|
|
}
|
|
|
|
|
2020-06-07 23:37:01 +02:00
|
|
|
public function authorize(): bool
|
|
|
|
{
|
2020-06-09 00:56:00 +02:00
|
|
|
$user = $this->request->user();
|
2020-06-07 23:37:01 +02:00
|
|
|
|
2020-06-09 00:56:00 +02:00
|
|
|
return $user !== null && $user->hasPermission(IUser::PERMISSION_ADMIN);
|
2020-06-07 23:37:01 +02:00
|
|
|
}
|
|
|
|
|
2020-06-02 01:16:59 +02:00
|
|
|
public function getMaps(): IContent
|
|
|
|
{
|
2020-06-01 21:13:02 +02:00
|
|
|
//TODO
|
|
|
|
|
|
|
|
return new HtmlContent('admin/maps');
|
|
|
|
}
|
|
|
|
|
2020-06-09 00:56:00 +02:00
|
|
|
public function getMapEditor(): IContent
|
2020-06-02 01:16:59 +02:00
|
|
|
{
|
2020-06-09 00:56:00 +02:00
|
|
|
$mapId = (int) $this->request->query('mapId');
|
2020-06-01 21:13:02 +02:00
|
|
|
|
|
|
|
$bounds = $this->getMapBounds($mapId);
|
|
|
|
|
|
|
|
$places = $this->getPlaces($mapId);
|
|
|
|
|
|
|
|
$data = ['mapId' => $mapId, 'bounds' => $bounds->toArray(), 'places' => &$places];
|
|
|
|
return new HtmlContent('admin/map_editor', $data);
|
|
|
|
}
|
|
|
|
|
2020-06-09 00:56:00 +02:00
|
|
|
public function getPlace()
|
2020-06-02 01:16:59 +02:00
|
|
|
{
|
2020-06-09 00:56:00 +02:00
|
|
|
$placeId = (int) $this->request->query('placeId');
|
2020-06-02 21:44:01 +02:00
|
|
|
|
2020-06-02 01:16:59 +02:00
|
|
|
$placeData = $this->placeRepository->getById($placeId);
|
2020-06-02 21:44:01 +02:00
|
|
|
|
2020-06-02 01:16:59 +02:00
|
|
|
$data = ['panoId' => $placeData['panoId']];
|
2020-06-02 21:44:01 +02:00
|
|
|
return new JsonContent($data);
|
|
|
|
}
|
|
|
|
|
2020-06-01 21:13:02 +02:00
|
|
|
private function getMapBounds(int $mapId): Bounds
|
|
|
|
{
|
|
|
|
$select = new Select(\Container::$dbConnection, 'maps');
|
|
|
|
$select->columns(['bound_south_lat', 'bound_west_lng', 'bound_north_lat', 'bound_east_lng']);
|
|
|
|
$select->whereId($mapId);
|
|
|
|
|
|
|
|
$map = $select->execute()->fetch(IResultSet::FETCH_ASSOC);
|
|
|
|
|
|
|
|
$bounds = Bounds::createDirectly($map['bound_south_lat'], $map['bound_west_lng'], $map['bound_north_lat'], $map['bound_east_lng']);
|
|
|
|
|
|
|
|
return $bounds;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function &getPlaces(int $mapId): array
|
|
|
|
{
|
|
|
|
$select = new Select(\Container::$dbConnection, 'places');
|
2020-06-02 01:16:59 +02:00
|
|
|
$select->columns(['id', 'lat', 'lng', 'pano_id_cached', 'pano_id_cached_timestamp']);
|
2020-06-01 21:13:02 +02:00
|
|
|
$select->where('map_id', '=', $mapId);
|
|
|
|
$select->orderBy('lng');
|
|
|
|
|
2020-06-02 01:16:59 +02:00
|
|
|
$result = $select->execute();
|
|
|
|
|
|
|
|
$places = [];
|
|
|
|
|
|
|
|
while ($place = $result->fetch(IResultSet::FETCH_ASSOC)) {
|
2020-06-05 00:21:36 +02:00
|
|
|
//$panoId = ???
|
|
|
|
//$pov = ???
|
2020-06-02 01:16:59 +02:00
|
|
|
$noPano = $place['pano_id_cached_timestamp'] && $place['pano_id_cached'] === null;
|
|
|
|
|
2020-06-05 00:21:36 +02:00
|
|
|
$places[$place['id']] = [
|
|
|
|
'id' => $place['id'],
|
|
|
|
'lat' => $place['lat'],
|
|
|
|
'lng' => $place['lng'],
|
|
|
|
'panoId' => null,
|
|
|
|
'pov' => ['heading' => 0.0, 'pitch' => 0.0, 'zoom' => 0.0],
|
|
|
|
'noPano' => $noPano
|
|
|
|
];
|
2020-06-02 01:16:59 +02:00
|
|
|
}
|
2020-06-01 21:13:02 +02:00
|
|
|
|
|
|
|
return $places;
|
|
|
|
}
|
|
|
|
}
|