mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Feature: Store location of each address contained in geographical units in a materialized view
This commit is contained in:
parent
ec9555ec84
commit
d3ba11f521
@ -15,6 +15,8 @@ use Chill\MainBundle\Doctrine\Model\Point;
|
|||||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
use Symfony\Component\Serializer\Annotation\Groups;
|
use Symfony\Component\Serializer\Annotation\Groups;
|
||||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||||
@ -97,6 +99,23 @@ class Address
|
|||||||
*/
|
*/
|
||||||
private $floor;
|
private $floor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of geographical units and addresses.
|
||||||
|
*
|
||||||
|
* This list is computed by a materialized view. It won't be populated until a refresh is done
|
||||||
|
* on the materialized view.
|
||||||
|
*
|
||||||
|
* @var Collection<int, GeographicalUnit>|GeographicalUnit[]
|
||||||
|
* @readonly
|
||||||
|
* @ORM\ManyToMany(targetEntity=GeographicalUnit::class)
|
||||||
|
* @ORM\JoinTable(
|
||||||
|
* name="view_chill_main_address_geographical_unit",
|
||||||
|
* joinColumns={@ORM\JoinColumn(name="address_id")},
|
||||||
|
* inverseJoinColumns={@ORM\JoinColumn(name="geographical_unit_id")}
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
private Collection $geographicalUnits;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
*
|
*
|
||||||
@ -104,8 +123,9 @@ class Address
|
|||||||
* @ORM\Column(name="id", type="integer")
|
* @ORM\Column(name="id", type="integer")
|
||||||
* @ORM\GeneratedValue(strategy="AUTO")
|
* @ORM\GeneratedValue(strategy="AUTO")
|
||||||
* @Groups({"write"})
|
* @Groups({"write"})
|
||||||
|
* @readonly
|
||||||
*/
|
*/
|
||||||
private $id;
|
private ?int $id = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* True if the address is a "no address", aka homeless person, ...
|
* True if the address is a "no address", aka homeless person, ...
|
||||||
@ -190,6 +210,7 @@ class Address
|
|||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->validFrom = new DateTime();
|
$this->validFrom = new DateTime();
|
||||||
|
$this->geographicalUnits = new ArrayCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function createFromAddress(Address $original): Address
|
public static function createFromAddress(Address $original): Address
|
||||||
@ -273,6 +294,14 @@ class Address
|
|||||||
return $this->floor;
|
return $this->floor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection<int, GeographicalUnit>|GeographicalUnit[]
|
||||||
|
*/
|
||||||
|
public function getGeographicalUnits(): Collection
|
||||||
|
{
|
||||||
|
return $this->geographicalUnits;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get id.
|
* Get id.
|
||||||
*
|
*
|
||||||
|
@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Chill is a software for social workers
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view
|
||||||
|
* the LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Chill\Migrations\Main;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
final class Version20221114105345 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('DROP MATERIALIZED VIEW view_chill_main_address_geographical_unit');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return 'Create materialized view to store GeographicalUnitAddress';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('CREATE MATERIALIZED VIEW view_chill_main_address_geographical_unit (address_id, geographical_unit_id) AS
|
||||||
|
SELECT
|
||||||
|
address.id AS address_id,
|
||||||
|
geographical_unit.id AS geographical_unit_id
|
||||||
|
FROM chill_main_address AS address
|
||||||
|
JOIN chill_main_geographical_unit AS geographical_unit ON ST_CONTAINS(geographical_unit.geom, address.point)
|
||||||
|
');
|
||||||
|
|
||||||
|
$this->addSql('CREATE INDEX IDX_BD42692CF5B7AF75 ON view_chill_main_address_geographical_unit (address_id)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_BD42692CDAA4DAB8 ON view_chill_main_address_geographical_unit (geographical_unit_id)');
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user