src/Entity/Item/Item.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Item;
  3. use App\Entity\Another;
  4. use App\Entity\JobLevel;
  5. use App\Entity\Search\SearchTechnology;
  6. use App\Entity\Traits\IdTrait;
  7. use App\Search\PhraseDistanceScoreCalculator;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\ORM\Mapping as ORM;
  11. /**
  12.  * @ORM\Entity(repositoryClass=ItemRepository::class)
  13.  */
  14. class Item
  15. {
  16.     use IdTrait;
  17.     /**
  18.      * @ORM\Column(type="datetime",nullable=true)
  19.      */
  20.     private $createdAt = null;
  21.     /**
  22.      * @ORM\Column(type="datetime",nullable=true)
  23.      */
  24.     private $updatedAt = null;
  25.     /**
  26.      * @ORM\Column(type="text",  nullable=true)
  27.      */
  28.     private $name = null;
  29.     /**
  30.      * @ORM\Column(type="text",  nullable=true)
  31.      */
  32.     private $nameEn = null;
  33.     /**
  34.      * @ORM\ManyToMany(targetEntity=ItemCategory::class, inversedBy="items",cascade={"persist","remove","refresh"})
  35.      * @ORM\JoinColumn(nullable=true)
  36.      */
  37.     private $itemCategories;
  38.     /**
  39.      * @ORM\Column(type="boolean", nullable=true)
  40.      */
  41.     private $approved = null;
  42.     /**
  43.      * @ORM\Column(type="json",nullable=true)
  44.      */
  45.     private $secondLevel = [];
  46.     /**
  47.      * @ORM\Column(type="json",nullable=true)
  48.      */
  49.     private $thirdLevel = [];
  50.     /**
  51.      * @ORM\Column(type="boolean",nullable=true)
  52.      */
  53.     private $canBeNiceToHave = null;
  54.     /**
  55.      * @ORM\Column(type="text", nullable=true)
  56.      */
  57.     private $type = null;
  58.     /**
  59.      * @ORM\Column(type="text", nullable=true)
  60.      */
  61.     private $salary = null;
  62.     /**
  63.      * @ORM\Column(type="text",nullable=true)
  64.      */
  65.     private $placeholder = null;
  66.     /**
  67.      * @ORM\Column(type="integer", nullable=true)
  68.      */
  69.     private ?int $useCount = null;
  70.     /**
  71.      * @ORM\Column(type="string", length=255, nullable=true)
  72.      */
  73.     private ?string $searchSlug = null;
  74.     /**
  75.      * @ORM\OneToMany(targetEntity=Another::class, mappedBy="item")
  76.      */
  77.     private $anothers = null;
  78.     /**
  79.      * @ORM\Column(type="boolean", nullable=true)
  80.      */
  81.     private ?bool $can_show = null;
  82.     /**
  83.      * @ORM\ManyToMany(targetEntity=JobLevel::class)
  84.      */
  85.     private $jobLevels;
  86.     /**
  87.      * @ORM\OneToMany(targetEntity=SearchTechnology::class, mappedBy="item")
  88.      */
  89.     private $searchTechnologies;
  90.     public function __construct($createdAt, $updatedAt, $name, $nameEn, $approved, $secondLevel, $thirdLevel, $canBeNiceToHave, $type, $salary = null, $placeholder = "")
  91.     {
  92.         $this->createdAt = $createdAt;
  93.         $this->updatedAt = $updatedAt;
  94.         $this->name = $name;
  95.         $this->nameEn = $nameEn;
  96.         $this->itemCategories = new ArrayCollection();
  97.         $this->approved = $approved;
  98.         $this->secondLevel = $secondLevel;
  99.         $this->thirdLevel = $thirdLevel;
  100.         $this->canBeNiceToHave = $canBeNiceToHave;
  101.         $this->type = $type;
  102.         $this->salary = $salary;
  103.         $this->placeholder = $placeholder;
  104.         $this->itemPoints = new ArrayCollection();
  105.         $this->anothers = new ArrayCollection();
  106.         $this->can_show = true;
  107.         $this->jobLevels = new ArrayCollection();
  108.         $this->searchTechnologies = new ArrayCollection();
  109.     }
  110.     public function __clone()
  111.     {
  112.         $this->id = null;
  113.     }
  114.     public function cloneObject(): self
  115.     {
  116.         return clone $this;
  117.     }
  118.     public function getId(): ?int
  119.     {
  120.         return $this->id;
  121.     }
  122.     public function getCreatedAt(): ?\DateTimeInterface
  123.     {
  124.         return $this->createdAt;
  125.     }
  126.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  127.     {
  128.         $this->createdAt = $createdAt;
  129.         return $this;
  130.     }
  131.     public function getUpdatedAt(): ?\DateTimeInterface
  132.     {
  133.         return $this->updatedAt;
  134.     }
  135.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  136.     {
  137.         $this->updatedAt = $updatedAt;
  138.         return $this;
  139.     }
  140.     public function getName(): ?string
  141.     {
  142.         return $this->name;
  143.     }
  144.     public function setName(string $name): self
  145.     {
  146.         $this->name = $name;
  147.         return $this;
  148.     }
  149.     public function getNameEn(): ?string
  150.     {
  151.         return $this->nameEn;
  152.     }
  153.     public function setNameEn(string $nameEn): self
  154.     {
  155.         $this->nameEn = $nameEn;
  156.         return $this;
  157.     }
  158.     /**
  159.      * @return Collection|\App\Entity\Item\ItemCategory[]
  160.      */
  161.     public function getItemCategories(): Collection
  162.     {
  163.         return $this->itemCategories;
  164.     }
  165.     public function addItemCategory(ItemCategory $itemCategory): self
  166.     {
  167.         if (!$this->itemCategories->contains($itemCategory)) {
  168.             $this->itemCategories[] = $itemCategory;
  169.         }
  170.         return $this;
  171.     }
  172.     public function removeItemCategory(ItemCategory $itemCategory): self
  173.     {
  174.         $this->itemCategories->removeElement($itemCategory);
  175.         return $this;
  176.     }
  177.     public function getApproved(): ?bool
  178.     {
  179.         return $this->approved;
  180.     }
  181.     public function setApproved(bool $approved): self
  182.     {
  183.         $this->approved = $approved;
  184.         return $this;
  185.     }
  186.     public function getSecondLevel(): ?array
  187.     {
  188.         return $this->secondLevel;
  189.     }
  190.     public function setSecondLevel(array $secondLevel): self
  191.     {
  192.         $this->secondLevel = $secondLevel;
  193.         return $this;
  194.     }
  195.     public function getThirdLevel(): ?array
  196.     {
  197.         return $this->thirdLevel;
  198.     }
  199.     public function setThirdLevel(array $thirdLevel): self
  200.     {
  201.         $this->thirdLevel = $thirdLevel;
  202.         return $this;
  203.     }
  204.     public function getCanBeNiceToHave(): ?bool
  205.     {
  206.         return $this->canBeNiceToHave;
  207.     }
  208.     public function setCanBeNiceToHave(bool $canBeNiceToHave): self
  209.     {
  210.         $this->canBeNiceToHave = $canBeNiceToHave;
  211.         return $this;
  212.     }
  213.     public function getType(): ?string
  214.     {
  215.         return $this->type;
  216.     }
  217.     public function setType(string $type): self
  218.     {
  219.         $this->type = $type;
  220.         return $this;
  221.     }
  222.     public function getSalary(): ?string
  223.     {
  224.         return $this->salary;
  225.     }
  226.     public function setSalary(string $salary): ?self
  227.     {
  228.         $this->salary = $salary;
  229.         return $this;
  230.     }
  231.     public function getPlaceholder(): ?string
  232.     {
  233.         return $this->placeholder;
  234.     }
  235.     public function setPlaceholder(string $placeholder): ?self
  236.     {
  237.         $this->placeholder = $placeholder;
  238.         return $this;
  239.     }
  240.     public function checkIfItemCategoryIsInItem(?ItemCategory $itemCategory): void
  241.     {
  242.         if (is_null($itemCategory)) {
  243.             return;
  244.         }
  245.         $itemCategoryItems = $itemCategory->getItems()->toArray();
  246.         foreach ($itemCategoryItems as $item){
  247.             if($item->getId() === $this->getId()){ return; }
  248.             $itemCategory->addItem($this);
  249.         }
  250.     }
  251.     /**
  252.      * @return int|null
  253.      */
  254.     public function getUseCount(): ?int
  255.     {
  256.         return $this->useCount;
  257.     }
  258.     /**
  259.      * @param int|null $useCount
  260.      */
  261.     public function setUseCount(?int $useCount): self
  262.     {
  263.         $this->useCount = $useCount;
  264.         return $this;
  265.     }
  266.     /**
  267.      * @return string|null
  268.      */
  269.     public function getSearchSlug(): ?string
  270.     {
  271.         return $this->searchSlug;
  272.     }
  273.     /**
  274.      * @param string|null $searchSlug
  275.      */
  276.     public function setSearchSlug(?string $searchSlug): self
  277.     {
  278.         $this->searchSlug = $searchSlug;
  279.         return $this;
  280.     }
  281.     /**
  282.      * @return Collection|Another[]
  283.      */
  284.     public function getAnothers(): Collection
  285.     {
  286.         return $this->anothers;
  287.     }
  288.     public function addAnother(Another $another): self
  289.     {
  290.         if (!$this->anothers->contains($another)) {
  291.             $this->anothers[] = $another;
  292.             $another->setItem($this);
  293.         }
  294.         return $this;
  295.     }
  296.     public function removeAnother(Another $another): self
  297.     {
  298.         if ($this->anothers->removeElement($another)) {
  299.             // set the owning side to null (unless already changed)
  300.             if ($another->getItem() === $this) {
  301.                 $another->setItem(null);
  302.             }
  303.         }
  304.         return $this;
  305.     }
  306.     /**
  307.      * @return bool
  308.      */
  309.     public function isShow(): bool
  310.     {
  311.         return $this->can_show;
  312.     }
  313.     /**
  314.      * @param bool $show
  315.      */
  316.     public function setShow(bool $can_show): self
  317.     {
  318.         $this->can_show = $can_show;
  319.         return $this;
  320.     }
  321.     /**
  322.      * @return Collection|JobLevel[]
  323.      */
  324.     public function getJobLevels(): Collection
  325.     {
  326.         return $this->jobLevels;
  327.     }
  328.     public function addJobLevel(JobLevel $jobLevel): self
  329.     {
  330.         if (!$this->jobLevels->contains($jobLevel)) {
  331.             $this->jobLevels[] = $jobLevel;
  332.         }
  333.         return $this;
  334.     }
  335.     public function removeJobLevel(JobLevel $jobLevel): self
  336.     {
  337.         $this->jobLevels->removeElement($jobLevel);
  338.         return $this;
  339.     }
  340.     public function getPointFromLevenshtein(array $search, string $itemPL, string $itemEN, PhraseDistanceScoreCalculator $phraseDistanceScoreCalculator): float
  341.     {
  342.         $points = 0.0;
  343.         foreach($search as $searchElement){
  344.             $searchElement       = strtolower($searchElement);
  345.             $itemPL              = strtolower($itemPL);
  346.             $itemEN              = strtolower($itemEN);
  347.             $industryPLPoint     = $phraseDistanceScoreCalculator->getScore($searchElement, $itemPL);
  348.             $industryENPoint     = $phraseDistanceScoreCalculator->getScore($searchElement, $itemEN);
  349.             $itemPoints          = $this->getHighestValueFromTwo($industryPLPoint, $industryENPoint);
  350.             $points             += $itemPoints;
  351.         }
  352.         return $points;
  353.     }
  354.     private function getHighestValueFromTwo(?int $first, ?int $second): int{
  355.         if(is_null($first)) { $first = 0; }
  356.         if(is_null($second)){ $second = 0; }
  357.         return max($first, $second);
  358.     }
  359.     public function getSearchTechnologies(): Collection
  360.     {
  361.         return $this->searchTechnologies;
  362.     }
  363.     public function addSearchTechnology(SearchTechnology $searchTechnology): self
  364.     {
  365.         if (!$this->searchTechnologies->contains($searchTechnology)) {
  366.             $this->searchTechnologies[] = $searchTechnology;
  367.             $searchTechnology->setItem($this);
  368.         }
  369.         return $this;
  370.     }
  371.     public function removeSearchTechnology(SearchTechnology $searchTechnology): self
  372.     {
  373.         if ($this->searchTechnologies->removeElement($searchTechnology)) {
  374.             // set the owning side to null (unless already changed)
  375.             if ($searchTechnology->getItem() === $this) {
  376.                 $searchTechnology->setItem(null);
  377.             }
  378.         }
  379.         return $this;
  380.     }
  381. }