From ca8b360936777f16df34fcdbd10fc3bdf4cdce40 Mon Sep 17 00:00:00 2001 From: Kacper Donat Date: Fri, 11 Jan 2019 22:38:36 +0100 Subject: [PATCH] add entities for schedule support --- src/Entity/TripEntity.php | 116 +++++++++++++++++++++++ src/Entity/TripStop.php | 103 ++++++++++++++++++++ src/Migrations/Version20190111212909.php | 35 +++++++ 3 files changed, 254 insertions(+) create mode 100644 src/Entity/TripEntity.php create mode 100644 src/Entity/TripStop.php create mode 100644 src/Migrations/Version20190111212909.php diff --git a/src/Entity/TripEntity.php b/src/Entity/TripEntity.php new file mode 100644 index 0000000..2a8247c --- /dev/null +++ b/src/Entity/TripEntity.php @@ -0,0 +1,116 @@ + + * + * @ORM\OneToMany(targetEntity=StopInTrack::class, fetch="EXTRA_LAZY", mappedBy="track", cascade={"persist"}) + * @ORM\OrderBy({"order": "ASC"}) + */ + private $stops; + + /** + * TripEntity constructor. + */ + public function __construct() + { + $this->setStops([]); + } + + public function getOperator(): OperatorEntity + { + return $this->operator; + } + + public function setOperator(OperatorEntity $operator): void + { + $this->operator = $operator; + } + + public function getTrack(): TrackEntity + { + return $this->track; + } + + public function setTrack(TrackEntity $track): void + { + $this->track = $track; + } + + public function getVariant(): ?string + { + return $this->variant; + } + + public function setVariant(?string $variant): void + { + $this->variant = $variant; + } + + public function getNote(): ?string + { + return $this->note; + } + + public function setNote(?string $note): void + { + $this->note = $note; + } + + public function getStops(): Collection + { + return $this->stops; + } + + public function setStops(iterable $stops): void + { + $this->stops = new ArrayCollection(is_array($stops) ? $stops : iterator_to_array($stops)); + } +} \ No newline at end of file diff --git a/src/Entity/TripStop.php b/src/Entity/TripStop.php new file mode 100644 index 0000000..c2799d8 --- /dev/null +++ b/src/Entity/TripStop.php @@ -0,0 +1,103 @@ +stop; + } + + public function setStop($stop): void + { + $this->stop = $stop; + } + + public function getTrip() + { + return $this->trip; + } + + public function setTrip($trip): void + { + $this->trip = $trip; + } + + public function getOrder(): int + { + return $this->order; + } + + public function setOrder(int $order): void + { + $this->order = $order; + } + + public function getArrival(): Carbon + { + return $this->arrival; + } + + public function setArrival(Carbon $arrival): void + { + $this->arrival = $arrival; + } + + public function getDeparture(): Carbon + { + return $this->departure; + } + + public function setDeparture(Carbon $departure): void + { + $this->departure = $departure; + } +} \ No newline at end of file diff --git a/src/Migrations/Version20190111212909.php b/src/Migrations/Version20190111212909.php new file mode 100644 index 0000000..03066a9 --- /dev/null +++ b/src/Migrations/Version20190111212909.php @@ -0,0 +1,35 @@ +abortIf($this->connection->getDatabasePlatform()->getName() !== 'sqlite', 'Migration can only be executed safely on \'sqlite\'.'); + + $this->addSql('CREATE TABLE trip_stop (stop_id VARCHAR(255) NOT NULL, trip_id VARCHAR(255) NOT NULL, sequence INTEGER NOT NULL, arrival DATETIME NOT NULL, departure DATETIME NOT NULL, PRIMARY KEY(stop_id, trip_id))'); + $this->addSql('CREATE INDEX IDX_926E85DD3902063D ON trip_stop (stop_id)'); + $this->addSql('CREATE INDEX IDX_926E85DDA5BC2E0E ON trip_stop (trip_id)'); + $this->addSql('CREATE TABLE trip (id VARCHAR(255) NOT NULL, operator_id VARCHAR(255) DEFAULT NULL, track_id VARCHAR(255) DEFAULT NULL, provider_id VARCHAR(255) DEFAULT NULL, variant VARCHAR(255) DEFAULT NULL, note VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE INDEX IDX_7656F53B584598A3 ON trip (operator_id)'); + $this->addSql('CREATE INDEX IDX_7656F53B5ED23C43 ON trip (track_id)'); + $this->addSql('CREATE INDEX IDX_7656F53BA53A8AA ON trip (provider_id)'); + } + + public function down(Schema $schema) : void + { + // this down() migration is auto-generated, please modify it to your needs + $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'sqlite', 'Migration can only be executed safely on \'sqlite\'.'); + + $this->addSql('DROP TABLE trip_stop'); + $this->addSql('DROP TABLE trip'); + } +}