<?php
namespace App\Entity;
use App\Repository\CBRCArticleCategoryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity(repositoryClass=CBRCArticleCategoryRepository::class)
* @UniqueEntity(fields="name", message="La catégorie existe déjà")
*/
class CBRCArticleCategory
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="string", length=255)
*/
private $bgcolor;
/**
* @ORM\Column(type="string", length=255)
*/
private $textcolor;
/**
* @ORM\OneToMany(targetEntity=CBRCArticle::class, mappedBy="category")
*/
private $articles;
public function __construct()
{
$this->articles = new ArrayCollection();
$this->bgcolor="#e7c900";
$this->textcolor="#436B23";
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getBgcolor(): ?string
{
return $this->bgcolor;
}
public function setBgcolor(string $bgcolor): self
{
$this->bgcolor = $bgcolor;
return $this;
}
public function getTextcolor(): ?string
{
return $this->textcolor;
}
public function setTextcolor(string $textcolor): self
{
$this->textcolor = $textcolor;
return $this;
}
/**
* @return Collection|CBRCArticle[]
*/
public function getArticles(): Collection
{
return $this->articles;
}
public function addArticle(CBRCArticle $article): self
{
if (!$this->articles->contains($article)) {
$this->articles[] = $article;
$article->setCategory($this);
}
return $this;
}
public function removeArticle(CBRCArticle $article): self
{
if ($this->articles->removeElement($article)) {
// set the owning side to null (unless already changed)
if ($article->getCategory() === $this) {
$article->setCategory(null);
}
}
return $this;
}
public function getCountpublishedarticles()
{
$count=0;
foreach ($this->articles as $article)
{
if($article->getPublisheddate()!=null && $article->getArchiveddate()==null)
$count++;
}
return $count;
}
}