src/Entity/ProductSponsoredCategory.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Doctrine\ORM\Query\ResultSetMapping;
  7. use App\Entity\ProductSponsored;
  8. /**
  9.  * @ORM\Entity(repositoryClass="App\Repository\ProductSponsoredCategoryRepository")
  10.  */
  11. class ProductSponsoredCategory
  12. {
  13.     /**
  14.      * @ORM\Id()
  15.      * @ORM\GeneratedValue()
  16.      * @ORM\Column(type="integer")
  17.      */
  18.     private $id;
  19.     /**
  20.      * @ORM\ManyToMany(targetEntity="App\Entity\ProductSponsored", inversedBy="categories")
  21.      */
  22.     private $productsSponsored;
  23.     /**
  24.      * @ORM\Column(type="string", length=255)
  25.      */
  26.     private $title;
  27.     /**
  28.      * @ORM\Column(type="string", length=255)
  29.      */
  30.     private $url;
  31.     /**
  32.      * @ORM\Column(type="integer")
  33.      */
  34.     private $displayOrder;
  35.     /**
  36.      * @ORM\ManyToOne(targetEntity="App\Entity\Category")
  37.      */
  38.     private $category;
  39.     /**
  40.      * @ORM\Column(type="boolean", nullable=true)
  41.      */
  42.     private $onSale;
  43.     public function __construct()
  44.     {
  45.         $this->productsSponsored = new ArrayCollection();
  46.     }
  47.     public function getId(): ?int
  48.     {
  49.         return $this->id;
  50.     }
  51.     // This has been refactorised into a more optimized version
  52.     // i'm keeping it for reference but i'll delete this block asap
  53.     //
  54.     // /**
  55.     //  * TODO remove
  56.     //  * @return Collection|ProductSponsored[]
  57.     //  */
  58.     // public function getDisplayProductsSponsored($associationUserIsBrowsing = false)
  59.     // {
  60.     //
  61.     //     if(!empty($this->getCategory())) {
  62.     //
  63.     //         $clean = array();
  64.     //         //Let's get the top 20
  65.     //         $cmtp = 0;
  66.     //         $company = array();
  67.     //
  68.       //       $products = $this->getCategory()->getAllProducts()->toArray();
  69.     //
  70.       //       foreach ($products as $key => $product){
  71.       //           if (!$associationUserIsBrowsing && $product->getIsDisplayedInAssociationOnly()){
  72.       //               unset($products[$key]);
  73.     //             }
  74.     //         }
  75.     //         shuffle($products);
  76.     //
  77.     //         foreach($products as $p){
  78.     //             if($p->isSalable() && $p->isShippedByMaturin()){
  79.     //                 if(empty($company[$p->getCompany()->getId()]) || $company[$p->getCompany()->getId()] < 3 ){
  80.     //                     $t = new ProductSponsored();
  81.     //                     $t->setProduct($p);
  82.     //                     $clean[]= $t;
  83.     //                     $cmtp++;
  84.     //
  85.     //                     if(empty($company[$p->getCompany()->getId()]))
  86.     //                         $company[$p->getcompany()->getId()] = 1;
  87.     //                     else
  88.     //                         $company[$p->getcompany()->getId()]++;
  89.     //                 }
  90.     //                 if($cmtp > 50 || count($clean) > 15)
  91.     //                     break;
  92.     //             }
  93.     //         }
  94.     //
  95.     //         if(count($clean) > 0)
  96.     //             shuffle($clean);
  97.     //
  98.     //         return new ArrayCollection($clean);
  99.     //
  100.     //     }else {
  101.     //
  102.     //         $clean = array();
  103.     //         $now = new \DateTime();
  104.     //         foreach($this->getProductsSponsored() as $p){
  105.     //
  106.     //             if($p->getActive() && $p->getFromDate() <= $now && $p->getToDate() >= $now &&
  107.     //                 ($associationUserIsBrowsing == $p->getProduct()->getIsDisplayedInAssociationOnly())
  108.     //             )
  109.     //                 $clean[]= $p;
  110.     //         }
  111.     //
  112.     //         if(count($clean) > 0)
  113.     //             shuffle($clean);
  114.     //         return new ArrayCollection($clean);
  115.     //     }
  116.     //
  117.     // }
  118.     /**
  119.      * @return Collection|ProductSponsored[]
  120.      */
  121.     public function getProductsSponsored(): Collection
  122.     {
  123.         return $this->productsSponsored;
  124.     }
  125.     public function addProductsSponsored(ProductSponsored $productsSponsored): self
  126.     {
  127.         if (!$this->productsSponsored->contains($productsSponsored)) {
  128.             $this->productsSponsored[] = $productsSponsored;
  129.         }
  130.         return $this;
  131.     }
  132.     public function removeProductsSponsored(ProductSponsored $productsSponsored): self
  133.     {
  134.         if ($this->productsSponsored->contains($productsSponsored)) {
  135.             $this->productsSponsored->removeElement($productsSponsored);
  136.         }
  137.         return $this;
  138.     }
  139.     public function getTitle(): ?string
  140.     {
  141.         return $this->title;
  142.     }
  143.     public function setTitle(string $title): self
  144.     {
  145.         $this->title $title;
  146.         return $this;
  147.     }
  148.     public function getUrl(): ?string
  149.     {
  150.         return $this->url;
  151.     }
  152.     public function setUrl(string $url): self
  153.     {
  154.         $this->url $url;
  155.         return $this;
  156.     }
  157.     public function getDisplayOrder(): ?int
  158.     {
  159.         return $this->displayOrder;
  160.     }
  161.     public function setDisplayOrder(int $displayOrder): self
  162.     {
  163.         $this->displayOrder $displayOrder;
  164.         return $this;
  165.     }
  166.     public function __toString()
  167.     {
  168.         return $this->getTitle();
  169.     }
  170.     public function getCategory(): ?Category
  171.     {
  172.         return $this->category;
  173.     }
  174.     public function setCategory(?Category $category): self
  175.     {
  176.         $this->category $category;
  177.         return $this;
  178.     }
  179.     public function getOnSale(): ?bool
  180.     {
  181.         return $this->onSale;
  182.     }
  183.     public function setOnSale(?bool $onSale): self
  184.     {
  185.         $this->onSale $onSale;
  186.         return $this;
  187.     }
  188. }