More work

This commit is contained in:
2024-12-10 00:27:24 +04:00
parent d89cc832cb
commit f30f0f1adb
10 changed files with 339 additions and 8 deletions
+42
View File
@@ -0,0 +1,42 @@
<?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 Version20241209201442 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->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');
}
}
-2
View File
@@ -87,8 +87,6 @@ class Pf2eGenerateCommand extends Command
$io->writeln(""); $io->writeln("");
} }
$io->success('You have a new command! Now make it your own! Pass --help to see your options.');
return Command::SUCCESS; return Command::SUCCESS;
} }
+57
View File
@@ -0,0 +1,57 @@
<?php
namespace App\Command;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
#[AsCommand(
name: 'pf2e:import',
description: 'Add a short description for your command',
)]
class Pf2eImportCommand extends Command
{
public function __construct()
{
parent::__construct();
}
protected function configure(): void
{
$this
->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;
}
}
@@ -33,7 +33,6 @@ class Schema
} }
} }
public static function resolveType(mixed $value): string public static function resolveType(mixed $value): string
{ {
$type = gettype($value); $type = gettype($value);
@@ -28,12 +28,17 @@ class SchemaItem
$this->type = Schema::mergeTypes($this->type, $type); $this->type = Schema::mergeTypes($this->type, $type);
if (str_contains($this->type, "[]") && !is_null($this->elements)) { if (!!is_null($this->elements)) {
if (str_contains($this->type, "[]")) {
foreach ($value as $element) { foreach ($value as $element) {
if (!in_array($element, $this->elements)) { if (!in_array($element, $this->elements)) {
$this->elements[] = $element; $this->elements[] = $element;
} }
} }
}
else if (!in_array($value, $this->elements)) {
$this->elements[] = $value;
}
if (count($this->elements) > 20) { if (count($this->elements) > 20) {
$this->elements = null; $this->elements = null;
@@ -64,5 +69,4 @@ class SchemaItem
return $rows; return $rows;
} }
} }
+43
View File
@@ -3,6 +3,8 @@
namespace App\Entity; namespace App\Entity;
use App\Repository\ItemRepository; use App\Repository\ItemRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Types\UuidType; use Symfony\Bridge\Doctrine\Types\UuidType;
use Symfony\Component\Uid\Uuid; use Symfony\Component\Uid\Uuid;
@@ -26,6 +28,17 @@ class Item
#[ORM\Column(enumType: ItemTypeEnum::class)] #[ORM\Column(enumType: ItemTypeEnum::class)]
private ?ItemTypeEnum $type = null; private ?ItemTypeEnum $type = null;
/**
* @var Collection<int, ItemLocalization>
*/
#[ORM\OneToMany(targetEntity: ItemLocalization::class, mappedBy: 'item')]
private Collection $itemLocalizations;
public function __construct()
{
$this->itemLocalizations = new ArrayCollection();
}
public function getId(): ?int public function getId(): ?int
{ {
return $this->id; return $this->id;
@@ -59,4 +72,34 @@ class Item
return $this; return $this;
} }
/**
* @return Collection<int, ItemLocalization>
*/
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;
}
} }
+81
View File
@@ -0,0 +1,81 @@
<?php
namespace App\Entity;
use App\Repository\ItemLocalizationRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ItemLocalizationRepository::class)]
class ItemLocalization
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'itemLocalizations')]
private ?Item $item = null;
#[ORM\Column(length: 255)]
private ?string $title = null;
#[ORM\Column(type: Types::TEXT)]
private ?string $markdown = null;
#[ORM\Column(length: 255)]
private ?string $url = null;
public function getId(): ?int
{
return $this->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;
}
}
+53
View File
@@ -0,0 +1,53 @@
<?php
namespace App\Entity\Pf2e;
use App\Entity\Item;
use App\Entity\Rarity;
use App\Repository\Pf2e\TpaitRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: TpaitRepository::class)]
class Tpait
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(enumType: Rarity::class)]
private ?Rarity $rarity = null;
#[ORM\OneToOne(cascade: ['persist', 'remove'])]
#[ORM\JoinColumn(nullable: false)]
private ?Item $item = null;
public function getId(): ?int
{
return $this->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;
}
}
+11
View File
@@ -0,0 +1,11 @@
<?php
namespace App\Entity;
enum Rarity: int
{
case Common = 1;
case Uncommon = 2;
case Rare = 3;
case Unique = 4;
}
@@ -0,0 +1,43 @@
<?php
namespace App\Repository;
use App\Entity\ItemLocalization;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<ItemLocalization>
*/
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()
// ;
// }
}