src/Entity/CBRCArticleCategory.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CBRCArticleCategoryRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. /**
  9.  * @ORM\Entity(repositoryClass=CBRCArticleCategoryRepository::class)
  10.  * @UniqueEntity(fields="name", message="La catégorie existe déjà")
  11.  */
  12. class CBRCArticleCategory
  13. {
  14.     /**
  15.      * @ORM\Id
  16.      * @ORM\GeneratedValue
  17.      * @ORM\Column(type="integer")
  18.      */
  19.     private $id;
  20.     /**
  21.      * @ORM\Column(type="string", length=255)
  22.      */
  23.     private $name;
  24.     /**
  25.      * @ORM\Column(type="string", length=255)
  26.      */
  27.     private $bgcolor;
  28.     /**
  29.      * @ORM\Column(type="string", length=255)
  30.      */
  31.     private $textcolor;
  32.     /**
  33.      * @ORM\OneToMany(targetEntity=CBRCArticle::class, mappedBy="category")
  34.      */
  35.     private $articles;
  36.     public function __construct()
  37.     {
  38.         $this->articles = new ArrayCollection();
  39.         $this->bgcolor="#e7c900";
  40.         $this->textcolor="#436B23";
  41.     }
  42.     public function getId(): ?int
  43.     {
  44.         return $this->id;
  45.     }
  46.     public function getName(): ?string
  47.     {
  48.         return $this->name;
  49.     }
  50.     public function setName(string $name): self
  51.     {
  52.         $this->name $name;
  53.         return $this;
  54.     }
  55.     public function getBgcolor(): ?string
  56.     {
  57.         return $this->bgcolor;
  58.     }
  59.     public function setBgcolor(string $bgcolor): self
  60.     {
  61.         $this->bgcolor $bgcolor;
  62.         return $this;
  63.     }
  64.     public function getTextcolor(): ?string
  65.     {
  66.         return $this->textcolor;
  67.     }
  68.     public function setTextcolor(string $textcolor): self
  69.     {
  70.         $this->textcolor $textcolor;
  71.         return $this;
  72.     }
  73.     /**
  74.      * @return Collection|CBRCArticle[]
  75.      */
  76.     public function getArticles(): Collection
  77.     {
  78.         return $this->articles;
  79.     }
  80.     public function addArticle(CBRCArticle $article): self
  81.     {
  82.         if (!$this->articles->contains($article)) {
  83.             $this->articles[] = $article;
  84.             $article->setCategory($this);
  85.         }
  86.         return $this;
  87.     }
  88.     public function removeArticle(CBRCArticle $article): self
  89.     {
  90.         if ($this->articles->removeElement($article)) {
  91.             // set the owning side to null (unless already changed)
  92.             if ($article->getCategory() === $this) {
  93.                 $article->setCategory(null);
  94.             }
  95.         }
  96.         return $this;
  97.     }
  98.     public function getCountpublishedarticles()
  99.     {
  100.         $count=0;
  101.         foreach ($this->articles as $article)
  102.         {
  103.             if($article->getPublisheddate()!=null && $article->getArchiveddate()==null)
  104.                 $count++;
  105.         }
  106.         return $count;
  107.     }
  108. }