<?php
namespace App\Entity\Item;
use App\Entity\Another;
use App\Entity\JobLevel;
use App\Entity\Search\SearchTechnology;
use App\Entity\Traits\IdTrait;
use App\Search\PhraseDistanceScoreCalculator;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=ItemRepository::class)
*/
class Item
{
use IdTrait;
/**
* @ORM\Column(type="datetime",nullable=true)
*/
private $createdAt = null;
/**
* @ORM\Column(type="datetime",nullable=true)
*/
private $updatedAt = null;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $name = null;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $nameEn = null;
/**
* @ORM\ManyToMany(targetEntity=ItemCategory::class, inversedBy="items",cascade={"persist","remove","refresh"})
* @ORM\JoinColumn(nullable=true)
*/
private $itemCategories;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $approved = null;
/**
* @ORM\Column(type="json",nullable=true)
*/
private $secondLevel = [];
/**
* @ORM\Column(type="json",nullable=true)
*/
private $thirdLevel = [];
/**
* @ORM\Column(type="boolean",nullable=true)
*/
private $canBeNiceToHave = null;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $type = null;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $salary = null;
/**
* @ORM\Column(type="text",nullable=true)
*/
private $placeholder = null;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private ?int $useCount = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $searchSlug = null;
/**
* @ORM\OneToMany(targetEntity=Another::class, mappedBy="item")
*/
private $anothers = null;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private ?bool $can_show = null;
/**
* @ORM\ManyToMany(targetEntity=JobLevel::class)
*/
private $jobLevels;
/**
* @ORM\OneToMany(targetEntity=SearchTechnology::class, mappedBy="item")
*/
private $searchTechnologies;
public function __construct($createdAt, $updatedAt, $name, $nameEn, $approved, $secondLevel, $thirdLevel, $canBeNiceToHave, $type, $salary = null, $placeholder = "")
{
$this->createdAt = $createdAt;
$this->updatedAt = $updatedAt;
$this->name = $name;
$this->nameEn = $nameEn;
$this->itemCategories = new ArrayCollection();
$this->approved = $approved;
$this->secondLevel = $secondLevel;
$this->thirdLevel = $thirdLevel;
$this->canBeNiceToHave = $canBeNiceToHave;
$this->type = $type;
$this->salary = $salary;
$this->placeholder = $placeholder;
$this->itemPoints = new ArrayCollection();
$this->anothers = new ArrayCollection();
$this->can_show = true;
$this->jobLevels = new ArrayCollection();
$this->searchTechnologies = new ArrayCollection();
}
public function __clone()
{
$this->id = null;
}
public function cloneObject(): self
{
return clone $this;
}
public function getId(): ?int
{
return $this->id;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getNameEn(): ?string
{
return $this->nameEn;
}
public function setNameEn(string $nameEn): self
{
$this->nameEn = $nameEn;
return $this;
}
/**
* @return Collection|\App\Entity\Item\ItemCategory[]
*/
public function getItemCategories(): Collection
{
return $this->itemCategories;
}
public function addItemCategory(ItemCategory $itemCategory): self
{
if (!$this->itemCategories->contains($itemCategory)) {
$this->itemCategories[] = $itemCategory;
}
return $this;
}
public function removeItemCategory(ItemCategory $itemCategory): self
{
$this->itemCategories->removeElement($itemCategory);
return $this;
}
public function getApproved(): ?bool
{
return $this->approved;
}
public function setApproved(bool $approved): self
{
$this->approved = $approved;
return $this;
}
public function getSecondLevel(): ?array
{
return $this->secondLevel;
}
public function setSecondLevel(array $secondLevel): self
{
$this->secondLevel = $secondLevel;
return $this;
}
public function getThirdLevel(): ?array
{
return $this->thirdLevel;
}
public function setThirdLevel(array $thirdLevel): self
{
$this->thirdLevel = $thirdLevel;
return $this;
}
public function getCanBeNiceToHave(): ?bool
{
return $this->canBeNiceToHave;
}
public function setCanBeNiceToHave(bool $canBeNiceToHave): self
{
$this->canBeNiceToHave = $canBeNiceToHave;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
public function getSalary(): ?string
{
return $this->salary;
}
public function setSalary(string $salary): ?self
{
$this->salary = $salary;
return $this;
}
public function getPlaceholder(): ?string
{
return $this->placeholder;
}
public function setPlaceholder(string $placeholder): ?self
{
$this->placeholder = $placeholder;
return $this;
}
public function checkIfItemCategoryIsInItem(?ItemCategory $itemCategory): void
{
if (is_null($itemCategory)) {
return;
}
$itemCategoryItems = $itemCategory->getItems()->toArray();
foreach ($itemCategoryItems as $item){
if($item->getId() === $this->getId()){ return; }
$itemCategory->addItem($this);
}
}
/**
* @return int|null
*/
public function getUseCount(): ?int
{
return $this->useCount;
}
/**
* @param int|null $useCount
*/
public function setUseCount(?int $useCount): self
{
$this->useCount = $useCount;
return $this;
}
/**
* @return string|null
*/
public function getSearchSlug(): ?string
{
return $this->searchSlug;
}
/**
* @param string|null $searchSlug
*/
public function setSearchSlug(?string $searchSlug): self
{
$this->searchSlug = $searchSlug;
return $this;
}
/**
* @return Collection|Another[]
*/
public function getAnothers(): Collection
{
return $this->anothers;
}
public function addAnother(Another $another): self
{
if (!$this->anothers->contains($another)) {
$this->anothers[] = $another;
$another->setItem($this);
}
return $this;
}
public function removeAnother(Another $another): self
{
if ($this->anothers->removeElement($another)) {
// set the owning side to null (unless already changed)
if ($another->getItem() === $this) {
$another->setItem(null);
}
}
return $this;
}
/**
* @return bool
*/
public function isShow(): bool
{
return $this->can_show;
}
/**
* @param bool $show
*/
public function setShow(bool $can_show): self
{
$this->can_show = $can_show;
return $this;
}
/**
* @return Collection|JobLevel[]
*/
public function getJobLevels(): Collection
{
return $this->jobLevels;
}
public function addJobLevel(JobLevel $jobLevel): self
{
if (!$this->jobLevels->contains($jobLevel)) {
$this->jobLevels[] = $jobLevel;
}
return $this;
}
public function removeJobLevel(JobLevel $jobLevel): self
{
$this->jobLevels->removeElement($jobLevel);
return $this;
}
public function getPointFromLevenshtein(array $search, string $itemPL, string $itemEN, PhraseDistanceScoreCalculator $phraseDistanceScoreCalculator): float
{
$points = 0.0;
foreach($search as $searchElement){
$searchElement = strtolower($searchElement);
$itemPL = strtolower($itemPL);
$itemEN = strtolower($itemEN);
$industryPLPoint = $phraseDistanceScoreCalculator->getScore($searchElement, $itemPL);
$industryENPoint = $phraseDistanceScoreCalculator->getScore($searchElement, $itemEN);
$itemPoints = $this->getHighestValueFromTwo($industryPLPoint, $industryENPoint);
$points += $itemPoints;
}
return $points;
}
private function getHighestValueFromTwo(?int $first, ?int $second): int{
if(is_null($first)) { $first = 0; }
if(is_null($second)){ $second = 0; }
return max($first, $second);
}
public function getSearchTechnologies(): Collection
{
return $this->searchTechnologies;
}
public function addSearchTechnology(SearchTechnology $searchTechnology): self
{
if (!$this->searchTechnologies->contains($searchTechnology)) {
$this->searchTechnologies[] = $searchTechnology;
$searchTechnology->setItem($this);
}
return $this;
}
public function removeSearchTechnology(SearchTechnology $searchTechnology): self
{
if ($this->searchTechnologies->removeElement($searchTechnology)) {
// set the owning side to null (unless already changed)
if ($searchTechnology->getItem() === $this) {
$searchTechnology->setItem(null);
}
}
return $this;
}
}