src/Entity/World.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Symfony\Component\Uid\Uuid;
  5. use App\Entity\Person\Person;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. #[ORM\Entity]
  9. #[ORM\Table(name'world')]
  10. #[ORM\HasLifecycleCallbacks]
  11. class World
  12. {
  13.     #[ORM\Id]
  14.     #[ORM\Column(type'uuid'uniquetrue)]
  15.     private $id;
  16.     
  17.     #[ORM\Column(type'json'nullablefalse)]
  18.     private array $promts = [];
  19.     #[ORM\Column(type'boolean'nullablefalse)]
  20.     private bool $isBase false;
  21.     #[ORM\Column(type'uuid'nullabletrue)]
  22.     private ?string $defaultLocationId null;
  23.     #[ORM\Column(type'string'nullablefalse)]
  24.     private ?string $name;
  25.     
  26.     #[ORM\Column(name'save_version'type'integer'nullablefalseoptions: ['default' => 1])]
  27.     private int $saveVersion 1;
  28.     #[ORM\Column(type'text'nullablefalseoptions: ['default' => ''])]
  29.     private string $description '';
  30.     #[ORM\Column(type'string'nullabletrue)]
  31.     private ?string $background null;
  32.     #[ORM\Column(type'boolean'nullablefalseoptions: ['default' => false])]
  33.     private bool $isPublic false;
  34.     #[ORM\Column(type'jsonb'nullabletrue)]
  35.     private ?array $settings = [];
  36.     #[ORM\Column(type'datetime'nullablefalse)]
  37.     private \DateTimeInterface $createdDate;
  38.     #[ORM\Column(type'datetime'nullablefalse)]
  39.     private \DateTimeInterface $editedDate;
  40.     #[ORM\Column(type'datetime'nullabletrue)]
  41.     private ?\DateTimeInterface $publishedDate null;
  42.     #[ORM\Column(type'uuid'nullabletrue)]
  43.     private ?string $createdBy null;
  44.     #[ORM\Column(type'jsonb'nullabletrue)]
  45.     private ?array $badges = [];
  46.     #[ORM\OneToMany(mappedBy'world'targetEntityPerson::class)]
  47.     private Collection $persons;
  48.     
  49.     #[ORM\OneToMany(mappedBy'world'targetEntityLocation\Location::class)]
  50.     private Collection $locations;
  51.     public function __construct()
  52.     {
  53.         $this->id Uuid::v4();
  54.         $this->persons = new ArrayCollection();
  55.         $this->locations = new ArrayCollection();
  56.     }
  57.     #[ORM\PrePersist]
  58.     public function setCreatedDate(): void
  59.     {
  60.         $this->createdDate = new \DateTime();
  61.         $this->editedDate = new \DateTime();
  62.     }
  63.     #[ORM\PreUpdate]
  64.     public function setEditedDate(): void
  65.     {
  66.         $this->editedDate = new \DateTime();
  67.     }
  68.     public function getSettings(): ?array
  69.     {
  70.         return $this->settings;
  71.     }
  72.     public function setSettings(?array $settings): void
  73.     {
  74.         $this->settings $settings;
  75.     }
  76.     public function getCreatedDate(): \DateTimeInterface
  77.     {
  78.         return $this->createdDate;
  79.     }
  80.     public function getEditedDate(): \DateTimeInterface
  81.     {
  82.         return $this->editedDate;
  83.     }
  84.     public function getPublishedDate(): ?\DateTimeInterface
  85.     {
  86.         return $this->publishedDate;
  87.     }
  88.     public function setPublishedDate(?\DateTimeInterface $publishedDate): void
  89.     {
  90.         $this->publishedDate $publishedDate;
  91.     }
  92.     public function getCreatedBy(): ?string
  93.     {
  94.         return $this->createdBy;
  95.     }
  96.     public function setCreatedBy(?string $createdBy): void
  97.     {
  98.         $this->createdBy $createdBy;
  99.     }
  100.     public function getBadges(): ?array
  101.     {
  102.         return $this->badges;
  103.     }
  104.     public function setBadges(?array $badges): void
  105.     {
  106.         $this->badges $badges;
  107.     }
  108.     
  109.     public function getSaveVersion(): int
  110.     {
  111.         return $this->saveVersion;
  112.     }
  113.     public function setSaveVersion(int $saveVersion): void
  114.     {
  115.         $this->saveVersion $saveVersion;
  116.     }
  117.     public function getName(): ?string
  118.     {
  119.         return $this->name;
  120.     }
  121.     public function setName(string $name): void
  122.     {
  123.         $this->name $name;
  124.     }
  125.     public function getDescription(): string
  126.     {
  127.         return $this->description;
  128.     }
  129.     public function setDescription(string $description): void
  130.     {
  131.         $this->description $description;
  132.     }
  133.     public function getBackground(): ?string
  134.     {
  135.         return $this->background;
  136.     }
  137.     public function setBackground(?string $background): void
  138.     {
  139.         $this->background $background;
  140.     }
  141.     public function isPublic(): bool
  142.     {
  143.         return $this->isPublic;
  144.     }
  145.     public function setIsPublic(bool $isPublic): void
  146.     {
  147.         $this->isPublic $isPublic;
  148.     }
  149.     // Getters and setters
  150.     public function getId()
  151.     {
  152.         return $this->id;
  153.     }
  154.     public function getPromts(): array
  155.     {
  156.         return $this->promts;
  157.     }
  158.     public function setPromts(array $promts): void
  159.     {
  160.         $this->promts $promts;
  161.     }
  162.     public function isBase(): bool
  163.     {
  164.         return $this->isBase;
  165.     }
  166.     public function setIsBase(bool $isBase): void
  167.     {
  168.         $this->isBase $isBase;
  169.     }
  170.     public function getDefaultLocationId(): ?string
  171.     {
  172.         return $this->defaultLocationId;
  173.     }
  174.     public function setDefaultLocationId(?string $defaultLocationId): void
  175.     {
  176.         $this->defaultLocationId $defaultLocationId;
  177.     }
  178.     /**
  179.      * @return Collection|Person[]
  180.      */
  181.     public function getPersons(): Collection
  182.     {
  183.         return $this->persons;
  184.     }
  185.     
  186.     /**
  187.      * @return Collection|Location[]
  188.      */
  189.     public function getLocations(): Collection
  190.     {
  191.         return $this->locations;
  192.     }
  193.     public function isReadyToPub(): bool
  194.     {
  195.         if (!$this->getDefaultLocationId()) {
  196.             return false;
  197.         }
  198.         
  199.         if ($this->persons->isEmpty()) {
  200.             return false;
  201.         }
  202.         
  203.         if (!$this->getBackground()) {
  204.             return false;
  205.         }
  206.         return true;
  207.     }
  208.     /**
  209.      * Get public badges for the world
  210.      *
  211.      * @return array
  212.      */
  213.     public function getPublicBadges(): array
  214.     {
  215.         $badges = [];
  216.         
  217.         // Always add "Автор: openrpg" badge
  218.         $badges[] = "Автор: openrpg";
  219.         
  220.         // Check for "бесплатно" badge
  221.         if ($this->settings && isset($this->settings['llm']) && strpos($this->settings['llm'], ':free') !== false) {
  222.             $badges[] = "бесплатно";
  223.         }
  224.         
  225.         // Add all saved badges
  226.         if ($this->badges) {
  227.             $badges array_merge($badges$this->badges);
  228.         }
  229.         
  230.         // Add badge based on location count
  231.         $locationCount count($this->getLocations());
  232.         if ($locationCount 4) {
  233.             $badges[] = "маленькое приключение";
  234.         } elseif ($locationCount <= 15) {
  235.             $badges[] = "средний";
  236.         } elseif ($locationCount <= 30) {
  237.             $badges[] = "огромное";
  238.         } else {
  239.             $badges[] = "игровая вселенная";
  240.         }
  241.         
  242.         return $badges;
  243.     }
  244. }