add entities for schedule support

This commit is contained in:
Kacper Donat 2019-01-11 22:38:36 +01:00
parent 305d1b57e2
commit ca8b360936
3 changed files with 254 additions and 0 deletions

116
src/Entity/TripEntity.php Normal file
View File

@ -0,0 +1,116 @@
<?php
namespace App\Entity;
use App\Model\Fillable;
use App\Model\FillTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table("trip")
*/
class TripEntity implements Entity, Fillable
{
use ReferableEntityTrait, ProviderReferenceTrait, FillTrait;
/**
* Operator of the trip
*
* @var OperatorEntity
* @ORM\ManyToOne(targetEntity=OperatorEntity::class)
*/
private $operator;
/**
* Track of the trip
*
* @var TrackEntity
* @ORM\ManyToOne(targetEntity=TrackEntity::class)
*/
private $track;
/**
* Variant of track, for example some alternative route
*
* @var ?string
* @ORM\Column("variant", nullable=true)
*/
private $variant;
/**
* Description of variant
*
* @var ?string
* @ORM\Column("note", nullable=true)
*/
private $note;
/**
* @var Collection<StopInTrack>
*
* @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));
}
}

103
src/Entity/TripStop.php Normal file
View File

@ -0,0 +1,103 @@
<?php
namespace App\Entity;
use App\Model\Fillable;
use App\Model\FillTrait;
use Carbon\Carbon;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table("trip_stop")
*/
class TripStop implements Fillable
{
use FillTrait;
/**
* @ORM\ManyToOne(targetEntity=StopEntity::class, fetch="EAGER")
* @ORM\Id
*/
private $stop;
/**
* @ORM\ManyToOne(targetEntity=TripEntity::class, fetch="EAGER")
* @ORM\Id
*/
private $trip;
/**
* Order in trip
* @var int
*
* @ORM\Column(name="sequence", type="integer")
*/
private $order;
/**
* Arrival time
* @var Carbon
*
* @ORM\Column(type="datetime", nullable=false)
*/
private $arrival;
/**
* Departure time
* @var Carbon
*
* @ORM\Column(type="datetime", nullable=false)
*/
private $departure;
public function getStop()
{
return $this->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;
}
}

View File

@ -0,0 +1,35 @@
<?php declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20190111212909 extends AbstractMigration
{
public function up(Schema $schema) : void
{
// this up() 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('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');
}
}