diff --git a/migrations/Version20241209201442.php b/migrations/Version20241209201442.php new file mode 100644 index 0000000..0f213d7 --- /dev/null +++ b/migrations/Version20241209201442.php @@ -0,0 +1,42 @@ +addSql('CREATE TABLE item_localization (id SERIAL NOT NULL, item_id INT DEFAULT NULL, title VARCHAR(255) NOT NULL, markdown TEXT NOT NULL, url VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE INDEX IDX_57866286126F525E ON item_localization (item_id)'); + $this->addSql('CREATE TABLE tpait (id SERIAL NOT NULL, item_id INT NOT NULL, rarity INT NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_B0DD552126F525E ON tpait (item_id)'); + $this->addSql('ALTER TABLE item_localization ADD CONSTRAINT FK_57866286126F525E FOREIGN KEY (item_id) REFERENCES item (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE tpait ADD CONSTRAINT FK_B0DD552126F525E FOREIGN KEY (item_id) REFERENCES item (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE item ADD type VARCHAR(255) NOT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('CREATE SCHEMA public'); + $this->addSql('ALTER TABLE item_localization DROP CONSTRAINT FK_57866286126F525E'); + $this->addSql('ALTER TABLE tpait DROP CONSTRAINT FK_B0DD552126F525E'); + $this->addSql('DROP TABLE item_localization'); + $this->addSql('DROP TABLE tpait'); + $this->addSql('ALTER TABLE item DROP type'); + } +} diff --git a/src/Command/Pf2eGenerateCommand.php b/src/Command/Pf2eGenerateCommand.php index 0179296..9228444 100644 --- a/src/Command/Pf2eGenerateCommand.php +++ b/src/Command/Pf2eGenerateCommand.php @@ -87,8 +87,6 @@ class Pf2eGenerateCommand extends Command $io->writeln(""); } - $io->success('You have a new command! Now make it your own! Pass --help to see your options.'); - return Command::SUCCESS; } diff --git a/src/Command/Pf2eImportCommand.php b/src/Command/Pf2eImportCommand.php new file mode 100644 index 0000000..6a48499 --- /dev/null +++ b/src/Command/Pf2eImportCommand.php @@ -0,0 +1,57 @@ +addOption("revision", null, InputOption::VALUE_REQUIRED, "Load index of specific revision. Default value - latest revision.") + ->addOption('type', null, InputOption::VALUE_REQUIRED, 'Specify types to import schema') + ->addOption('all', null, InputOption::VALUE_NONE, 'Generate schema for all types') + ; + } + + private int $revision; + + /** + * @var string[] + */ + private array $types; + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $io = new SymfonyStyle($input, $output); + $arg1 = $input->getArgument('arg1'); + + if ($arg1) { + $io->note(sprintf('You passed an argument: %s', $arg1)); + } + + if ($input->getOption('option1')) { + // ... + } + + $io->success('You have a new command! Now make it your own! Pass --help to see your options.'); + + return Command::SUCCESS; + } +} diff --git a/src/Command/Pf2eSchemaGenerator/Schema.php b/src/Command/Pf2eSchemaGenerator/Schema.php index 5aaffe2..6f7aba5 100644 --- a/src/Command/Pf2eSchemaGenerator/Schema.php +++ b/src/Command/Pf2eSchemaGenerator/Schema.php @@ -33,7 +33,6 @@ class Schema } } - public static function resolveType(mixed $value): string { $type = gettype($value); diff --git a/src/Command/Pf2eSchemaGenerator/SchemaItem.php b/src/Command/Pf2eSchemaGenerator/SchemaItem.php index c4fde13..a64473d 100644 --- a/src/Command/Pf2eSchemaGenerator/SchemaItem.php +++ b/src/Command/Pf2eSchemaGenerator/SchemaItem.php @@ -28,12 +28,17 @@ class SchemaItem $this->type = Schema::mergeTypes($this->type, $type); - if (str_contains($this->type, "[]") && !is_null($this->elements)) { - foreach ($value as $element) { - if (!in_array($element, $this->elements)) { - $this->elements[] = $element; + if (!!is_null($this->elements)) { + if (str_contains($this->type, "[]")) { + foreach ($value as $element) { + if (!in_array($element, $this->elements)) { + $this->elements[] = $element; + } } } + else if (!in_array($value, $this->elements)) { + $this->elements[] = $value; + } if (count($this->elements) > 20) { $this->elements = null; @@ -64,5 +69,4 @@ class SchemaItem return $rows; } - } \ No newline at end of file diff --git a/src/Entity/Item.php b/src/Entity/Item.php index b86ec84..37bf23b 100644 --- a/src/Entity/Item.php +++ b/src/Entity/Item.php @@ -3,6 +3,8 @@ namespace App\Entity; use App\Repository\ItemRepository; +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; use Symfony\Bridge\Doctrine\Types\UuidType; use Symfony\Component\Uid\Uuid; @@ -26,6 +28,17 @@ class Item #[ORM\Column(enumType: ItemTypeEnum::class)] private ?ItemTypeEnum $type = null; + /** + * @var Collection + */ + #[ORM\OneToMany(targetEntity: ItemLocalization::class, mappedBy: 'item')] + private Collection $itemLocalizations; + + public function __construct() + { + $this->itemLocalizations = new ArrayCollection(); + } + public function getId(): ?int { return $this->id; @@ -59,4 +72,34 @@ class Item return $this; } + + /** + * @return Collection + */ + public function getItemLocalizations(): Collection + { + return $this->itemLocalizations; + } + + public function addItemLocalization(ItemLocalization $itemLocalization): static + { + if (!$this->itemLocalizations->contains($itemLocalization)) { + $this->itemLocalizations->add($itemLocalization); + $itemLocalization->setItem($this); + } + + return $this; + } + + public function removeItemLocalization(ItemLocalization $itemLocalization): static + { + if ($this->itemLocalizations->removeElement($itemLocalization)) { + // set the owning side to null (unless already changed) + if ($itemLocalization->getItem() === $this) { + $itemLocalization->setItem(null); + } + } + + return $this; + } } diff --git a/src/Entity/ItemLocalization.php b/src/Entity/ItemLocalization.php new file mode 100644 index 0000000..512bb95 --- /dev/null +++ b/src/Entity/ItemLocalization.php @@ -0,0 +1,81 @@ +id; + } + + public function getItem(): ?Item + { + return $this->item; + } + + public function setItem(?Item $item): static + { + $this->item = $item; + + return $this; + } + + public function getTitle(): ?string + { + return $this->title; + } + + public function setTitle(string $title): static + { + $this->title = $title; + + return $this; + } + + public function getMarkdown(): ?string + { + return $this->markdown; + } + + public function setMarkdown(string $markdown): static + { + $this->markdown = $markdown; + + return $this; + } + + public function getUrl(): ?string + { + return $this->url; + } + + public function setUrl(string $url): static + { + $this->url = $url; + + return $this; + } +} diff --git a/src/Entity/Pf2e/Tpait.php b/src/Entity/Pf2e/Tpait.php new file mode 100644 index 0000000..23ef30e --- /dev/null +++ b/src/Entity/Pf2e/Tpait.php @@ -0,0 +1,53 @@ +id; + } + + public function getRarity(): ?Rarity + { + return $this->rarity; + } + + public function setRarity(Rarity $rarity): static + { + $this->rarity = $rarity; + + return $this; + } + + public function getItem(): ?Item + { + return $this->item; + } + + public function setItem(Item $item): static + { + $this->item = $item; + + return $this; + } +} diff --git a/src/Entity/Rarity.php b/src/Entity/Rarity.php new file mode 100644 index 0000000..eb97beb --- /dev/null +++ b/src/Entity/Rarity.php @@ -0,0 +1,11 @@ + + */ +class ItemLocalizationRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, ItemLocalization::class); + } + +// /** +// * @return ItemLocalization[] Returns an array of ItemLocalization objects +// */ +// public function findByExampleField($value): array +// { +// return $this->createQueryBuilder('i') +// ->andWhere('i.exampleField = :val') +// ->setParameter('val', $value) +// ->orderBy('i.id', 'ASC') +// ->setMaxResults(10) +// ->getQuery() +// ->getResult() +// ; +// } + +// public function findOneBySomeField($value): ?ItemLocalization +// { +// return $this->createQueryBuilder('i') +// ->andWhere('i.exampleField = :val') +// ->setParameter('val', $value) +// ->getQuery() +// ->getOneOrNullResult() +// ; +// } +}