73 lines
2.0 KiB
PHP
73 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Repository;
|
|
|
|
use App\Entity\SphericalPhoto;
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
|
use Doctrine\ORM\Query\ResultSetMappingBuilder;
|
|
use Doctrine\Persistence\ManagerRegistry;
|
|
|
|
/**
|
|
* @extends ServiceEntityRepository<SphericalPhoto>
|
|
*/
|
|
class SphericalPhotoRepository extends ServiceEntityRepository
|
|
{
|
|
public function __construct(ManagerRegistry $registry)
|
|
{
|
|
parent::__construct($registry, SphericalPhoto::class);
|
|
}
|
|
|
|
public function coordinates(int $id)
|
|
{
|
|
$conn = $this->getEntityManager()->getConnection();
|
|
|
|
$sql = '
|
|
SELECT
|
|
ST_X(ST_AsText(coordinate)) as lng,
|
|
ST_Y(ST_AsText(coordinate)) as lat
|
|
FROM
|
|
foto_sferica
|
|
WHERE id = :id
|
|
';
|
|
|
|
return $conn->executeQuery($sql, ['id' => $id])
|
|
->fetchAssociative();
|
|
}
|
|
/**
|
|
* @return SphericalPhoto[] Returns an array of SphericalPhoto objects
|
|
*/
|
|
public function findBySite(int $siteId): array
|
|
{
|
|
return $this->createQueryBuilder('s')
|
|
->andWhere('s.site = :siteId')
|
|
->setParameter('siteId', $siteId)
|
|
->orderBy('s.id', 'ASC')
|
|
->getQuery()
|
|
->getResult()
|
|
;
|
|
}
|
|
/**
|
|
* @return SphericalPhoto[] Returns an array of SphericalPhoto objects
|
|
*/
|
|
public function findBySiteGis(string $gisId): array
|
|
{
|
|
$rsm = new ResultSetMappingBuilder($this->getEntityManager());
|
|
$rsm->addRootEntityFromClassMetadata('App\Entity\SphericalPhoto', 'sf');
|
|
$query = $this->getEntityManager()->createNativeQuery(
|
|
'SELECT
|
|
sf.id,
|
|
filename
|
|
FROM foto_sferica sf
|
|
JOIN sito
|
|
ON sito.id = sf.sito
|
|
WHERE sito.gis_id = :gisId
|
|
',
|
|
$rsm
|
|
);
|
|
|
|
$query->setParameter('gisId', $gisId);
|
|
|
|
return $query->getResult();
|
|
}
|
|
}
|