src/Entity/Category.php line 15
<?phpnamespace App\Entity;use App\Repository\CategoryRepository;use DateTimeImmutable;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\DBAL\Types\Types;use Doctrine\ORM\Mapping as ORM;#[ORM\Entity(repositoryClass: CategoryRepository::class)]#[ORM\HasLifecycleCallbacks]#[ORM\Table(name: 'categories')]class Category {#[ORM\Id]#[ORM\GeneratedValue]#[ORM\Column]private ?int $id = null;public function getThumbUploadPath(): ?string {return $_ENV['CATEGORY_THUMB_PATH'] . '/' . date('Y/m/d/');}public function getImageUploadPath(): ?string {return $_ENV['CATEGORY_IMAGE_PATH'] . '/' . date('Y/m/d/');}#[ORM\Column(length: 255)]private ?string $title = null;#[ORM\Column(length: 255, nullable: true,)]private ?string $title2 = null;#[ORM\Column(length: 255, nullable: true,)]private ?string $title3 = null;#[ORM\ManyToOne(fetch: 'LAZY')]#[ORM\JoinColumn(nullable: true)]private ?User $editBy = null;#[ORM\Column]private bool $isSuspended = false;#[ORM\Column]private bool $isImages = false;#[ORM\Column(type: Types::TEXT, nullable: true,)]private ?string $description = null;#[ORM\Column(length: 255, nullable: true)]private ?string $metaTitle;#[ORM\Column(length: 255, nullable: true)]private ?string $metaDescription;#[ORM\Column(length: 255, nullable: true)]private ?string $metaKeywords;#[ORM\Column]private DateTimeImmutable $created;#[ORM\Column]private DateTimeImmutable $updated;#[ORM\ManyToOne(targetEntity: self::class, fetch: "LAZY")]private ?self $parent = null;#[ORM\OneToMany(mappedBy: 'category', targetEntity: Product::class, fetch: "LAZY")]private Collection $products;#[ORM\ManyToOne(fetch: "LAZY", inversedBy: 'category')]private ?Choice $choice = null;#[ORM\ManyToOne(inversedBy: 'categories')]private ?Image $slika = null;public function __construct() {$this->products = new ArrayCollection();}#[ORM\PrePersist]public function prePersist(): void {$this->created = new DateTimeImmutable();$this->updated = new DateTimeImmutable();}#[ORM\PreUpdate]public function preUpdate(): void {$this->updated = new DateTimeImmutable();}public function getId(): ?int {return $this->id;}public function getTitle(): ?string {return $this->title;}function reverseParenthesizedOrder($inputString) {// Regularni izraz za pronalaženje teksta unutar zagrada$pattern = '/\(([^)]+)\)/';// Funkcija za obradu podudaranja$callback = function ($matches) use (&$prefix) {// Razdvajamo string unutar zagrada koristeći '/' kao delimiter$parts = explode(' /', $matches[1]);// Dodajemo prefiks na osnovu broja elemenataif (count($parts) == 1) {$prefix = '-';} elseif (count($parts) == 2) {$prefix = '--';} elseif (count($parts) >= 3) {$prefix = '---';}// Ako ima više od jednog elementa, obrćemo redosledif (count($parts) > 1) {$parts = array_reverse($parts);}// Ponovo spajamo elemente u string koristeći '/' kao delimiterreturn '(' . implode(' /', $parts) . ')';};// Zamena teksta unutar zagrada koristeći regularni izraz i callback funkciju$reversedString = preg_replace_callback($pattern, $callback, $inputString);// Dodajemo prefiks na početak ulaznog stringa$reversedString = $prefix . $reversedString;return $reversedString;}public function getTitleForSale(): ?string {$naziv = $this->title;if (!is_null($this->parent)) {$naziv = $naziv . ' u (' . $this->parent->title;if (!is_null($this->parent->parent)) {$naziv = $naziv . ' / ' . $this->parent->parent->title;if (!is_null($this->parent->parent->parent)) {$naziv = $naziv . ' / ' . $this->parent->parent->parent->title;}}$naziv = $naziv . ')';}return $this->reverseParenthesizedOrder($naziv);}public function setTitle(string $title): self {$this->title = $title;return $this;}/*** @return User|null*/public function getEditBy(): ?User {return $this->editBy;}/*** @param User|null $editBy*/public function setEditBy(?User $editBy): void {$this->editBy = $editBy;}/*** @return DateTimeImmutable*/public function getCreated(): DateTimeImmutable {return $this->created;}/*** @param DateTimeImmutable $created*/public function setCreated(DateTimeImmutable $created): void {$this->created = $created;}/*** @return DateTimeImmutable*/public function getUpdated(): DateTimeImmutable {return $this->updated;}/*** @param DateTimeImmutable $updated*/public function setUpdated(DateTimeImmutable $updated): void {$this->updated = $updated;}/*** @return bool*/public function isSuspended(): bool {return $this->isSuspended;}/*** @param bool $isSuspended*/public function setIsSuspended(bool $isSuspended): void {$this->isSuspended = $isSuspended;}public function getBadgeByStatus(): string {if ($this->isSuspended) {return '<span class="badge bg-warning text-primary">Deaktivirana</span>';}return '<span class="badge bg-primary text-white">Aktivna</span>';}/*** @return string|null*/public function getMetaTitle(): ?string {return $this->metaTitle;}/*** @param string|null $metaTitle*/public function setMetaTitle(?string $metaTitle): void {$this->metaTitle = $metaTitle;}/*** @return string|null*/public function getMetaDescription(): ?string {return $this->metaDescription;}/*** @param string|null $metaDescription*/public function setMetaDescription(?string $metaDescription): void {$this->metaDescription = $metaDescription;}/*** @return string|null*/public function getMetaKeywords(): ?string {return $this->metaKeywords;}/*** @param string|null $metaKeywords*/public function setMetaKeywords(?string $metaKeywords): void {$this->metaKeywords = $metaKeywords;}public function getParent(): ?self {return $this->parent;}public function setParent(?self $parent): self {$this->parent = $parent;return $this;}/*** @return string|null*/public function getDescription(): ?string {return $this->description;}/*** @param string|null $description*/public function setDescription(?string $description): void {$this->description = $description;}/*** @return Collection<int, Product>*/public function getProducts(): Collection {return $this->products;}public function addProduct(Product $product): self {if (!$this->products->contains($product)) {$this->products->add($product);$product->setCategory($this);}return $this;}public function removeProduct(Product $product): self {if ($this->products->removeElement($product)) {// set the owning side to null (unless already changed)if ($product->getCategory() === $this) {$product->setCategory(null);}}return $this;}/*** @return string|null*/public function getTitle2(): ?string {return $this->title2;}/*** @param string|null $title2*/public function setTitle2(?string $title2): void {$this->title2 = $title2;}public function getChoice(): ?Choice {return $this->choice;}public function setChoice(?Choice $choice): self {$this->choice = $choice;return $this;}/*** @return string|null*/public function getTitle3(): ?string {return $this->title3;}/*** @param string|null $title3*/public function setTitle3(?string $title3): void {$this->title3 = $title3;}public function isImages(): bool {return $this->isImages;}public function setIsImages(bool $isImages): void {$this->isImages = $isImages;}public function getSlika(): ?Image{return $this->slika;}public function setSlika(?Image $slika): self{$this->slika = $slika;return $this;}}