<?phpnamespace App\Entity;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;use Doctrine\ORM\Query\ResultSetMapping;use App\Entity\ProductSponsored;/** * @ORM\Entity(repositoryClass="App\Repository\ProductSponsoredCategoryRepository") */class ProductSponsoredCategory{ /** * @ORM\Id() * @ORM\GeneratedValue() * @ORM\Column(type="integer") */ private $id; /** * @ORM\ManyToMany(targetEntity="App\Entity\ProductSponsored", inversedBy="categories") */ private $productsSponsored; /** * @ORM\Column(type="string", length=255) */ private $title; /** * @ORM\Column(type="string", length=255) */ private $url; /** * @ORM\Column(type="integer") */ private $displayOrder; /** * @ORM\ManyToOne(targetEntity="App\Entity\Category") */ private $category; /** * @ORM\Column(type="boolean", nullable=true) */ private $onSale; public function __construct() { $this->productsSponsored = new ArrayCollection(); } public function getId(): ?int { return $this->id; } // This has been refactorised into a more optimized version // i'm keeping it for reference but i'll delete this block asap // // /** // * TODO remove // * @return Collection|ProductSponsored[] // */ // public function getDisplayProductsSponsored($associationUserIsBrowsing = false) // { // // if(!empty($this->getCategory())) { // // $clean = array(); // //Let's get the top 20 // $cmtp = 0; // $company = array(); // // $products = $this->getCategory()->getAllProducts()->toArray(); // // foreach ($products as $key => $product){ // if (!$associationUserIsBrowsing && $product->getIsDisplayedInAssociationOnly()){ // unset($products[$key]); // } // } // shuffle($products); // // foreach($products as $p){ // if($p->isSalable() && $p->isShippedByMaturin()){ // if(empty($company[$p->getCompany()->getId()]) || $company[$p->getCompany()->getId()] < 3 ){ // $t = new ProductSponsored(); // $t->setProduct($p); // $clean[]= $t; // $cmtp++; // // if(empty($company[$p->getCompany()->getId()])) // $company[$p->getcompany()->getId()] = 1; // else // $company[$p->getcompany()->getId()]++; // } // if($cmtp > 50 || count($clean) > 15) // break; // } // } // // if(count($clean) > 0) // shuffle($clean); // // return new ArrayCollection($clean); // // }else { // // $clean = array(); // $now = new \DateTime(); // foreach($this->getProductsSponsored() as $p){ // // if($p->getActive() && $p->getFromDate() <= $now && $p->getToDate() >= $now && // ($associationUserIsBrowsing == $p->getProduct()->getIsDisplayedInAssociationOnly()) // ) // $clean[]= $p; // } // // if(count($clean) > 0) // shuffle($clean); // return new ArrayCollection($clean); // } // // } /** * @return Collection|ProductSponsored[] */ public function getProductsSponsored(): Collection { return $this->productsSponsored; } public function addProductsSponsored(ProductSponsored $productsSponsored): self { if (!$this->productsSponsored->contains($productsSponsored)) { $this->productsSponsored[] = $productsSponsored; } return $this; } public function removeProductsSponsored(ProductSponsored $productsSponsored): self { if ($this->productsSponsored->contains($productsSponsored)) { $this->productsSponsored->removeElement($productsSponsored); } return $this; } public function getTitle(): ?string { return $this->title; } public function setTitle(string $title): self { $this->title = $title; return $this; } public function getUrl(): ?string { return $this->url; } public function setUrl(string $url): self { $this->url = $url; return $this; } public function getDisplayOrder(): ?int { return $this->displayOrder; } public function setDisplayOrder(int $displayOrder): self { $this->displayOrder = $displayOrder; return $this; } public function __toString() { return $this->getTitle(); } public function getCategory(): ?Category { return $this->category; } public function setCategory(?Category $category): self { $this->category = $category; return $this; } public function getOnSale(): ?bool { return $this->onSale; } public function setOnSale(?bool $onSale): self { $this->onSale = $onSale; return $this; }}