2018-03-15 16:04:00 +01:00
|
|
|
<?php
|
|
|
|
|
2018-04-04 17:42:27 +02:00
|
|
|
namespace AppBundle\Entity;
|
2018-03-15 16:04:00 +01:00
|
|
|
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
2018-04-04 17:42:27 +02:00
|
|
|
|
2018-03-15 16:04:00 +01:00
|
|
|
/**
|
2018-04-04 17:42:27 +02:00
|
|
|
* @ORM\Entity(repositoryClass="AppBundle\Repository\ProductCategoryRepository")
|
2018-03-15 16:04:00 +01:00
|
|
|
*/
|
|
|
|
class ProductCategory {
|
|
|
|
/**
|
|
|
|
* @ORM\Id
|
|
|
|
* @ORM\GeneratedValue
|
|
|
|
* @ORM\Column(type="integer")
|
|
|
|
*/
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ORM\Column(type="string", length=100)
|
|
|
|
*/
|
|
|
|
private $name;
|
|
|
|
|
|
|
|
/**
|
2019-07-04 19:34:46 +02:00
|
|
|
* @ORM\OneToMany(targetEntity="Product", mappedBy="category", cascade={"remove"})
|
2018-03-15 16:04:00 +01:00
|
|
|
*/
|
|
|
|
private $products;
|
2018-05-24 15:11:18 +02:00
|
|
|
/**
|
2019-07-04 19:34:46 +02:00
|
|
|
* @ORM\OneToMany(targetEntity="ProductSold", mappedBy="product", cascade={"remove"})
|
2018-05-24 15:11:18 +02:00
|
|
|
*/
|
|
|
|
private $productsSold;
|
2018-03-15 16:04:00 +01:00
|
|
|
|
2018-04-05 15:05:04 +02:00
|
|
|
/**
|
|
|
|
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\User", mappedBy="categories")
|
|
|
|
*/
|
|
|
|
private $users;
|
|
|
|
|
2018-04-05 17:24:43 +02:00
|
|
|
public function __toString() {
|
|
|
|
return $this->getName() . ' (' . count( $this->getProducts() ) . ' produits)';
|
|
|
|
}
|
|
|
|
|
2018-05-04 17:22:49 +02:00
|
|
|
/**
|
|
|
|
* @param $userId
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function hasUser( $userId ) {
|
|
|
|
foreach ( $this->getUsers() as $user ) {
|
|
|
|
if ( $user->getId() === $userId ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-04-05 15:05:04 +02:00
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function getUsers() {
|
|
|
|
return $this->users;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param mixed $users
|
|
|
|
*/
|
|
|
|
public function setUsers( $users ) {
|
|
|
|
$this->users = $users;
|
|
|
|
}
|
|
|
|
|
2018-03-15 16:18:06 +01:00
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function getProducts() {
|
|
|
|
return $this->products;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param mixed $products
|
|
|
|
*/
|
|
|
|
public function setProducts( $products ) {
|
|
|
|
$this->products = $products;
|
|
|
|
}
|
|
|
|
|
2018-03-15 16:04:00 +01:00
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function getId() {
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param mixed $id
|
|
|
|
*/
|
|
|
|
public function setId( $id ) {
|
|
|
|
$this->id = $id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function getName() {
|
|
|
|
return $this->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param mixed $name
|
|
|
|
*/
|
|
|
|
public function setName( $name ) {
|
|
|
|
$this->name = $name;
|
|
|
|
}
|
|
|
|
|
2018-04-04 17:42:27 +02:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
|
|
|
public function __construct() {
|
|
|
|
$this->products = new \Doctrine\Common\Collections\ArrayCollection();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add product
|
|
|
|
*
|
|
|
|
* @param \AppBundle\Entity\Product $product
|
|
|
|
*
|
|
|
|
* @return ProductCategory
|
|
|
|
*/
|
|
|
|
public function addProduct( \AppBundle\Entity\Product $product ) {
|
|
|
|
$this->products[] = $product;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove product
|
|
|
|
*
|
|
|
|
* @param \AppBundle\Entity\Product $product
|
|
|
|
*/
|
|
|
|
public function removeProduct( \AppBundle\Entity\Product $product ) {
|
|
|
|
$this->products->removeElement( $product );
|
|
|
|
}
|
2018-04-17 12:10:21 +02:00
|
|
|
|
2018-04-17 15:41:00 +02:00
|
|
|
/**
|
|
|
|
* Add user
|
|
|
|
*
|
|
|
|
* @param \AppBundle\Entity\User $user
|
|
|
|
*
|
|
|
|
* @return ProductCategory
|
|
|
|
*/
|
|
|
|
public function addUser( \AppBundle\Entity\User $user ) {
|
|
|
|
$this->users[] = $user;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove user
|
|
|
|
*
|
|
|
|
* @param \AppBundle\Entity\User $user
|
|
|
|
*/
|
|
|
|
public function removeUser( \AppBundle\Entity\User $user ) {
|
|
|
|
$this->users->removeElement( $user );
|
|
|
|
}
|
2018-05-24 15:11:18 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add productsSold.
|
|
|
|
*
|
|
|
|
* @param \AppBundle\Entity\ProductSold $productsSold
|
|
|
|
*
|
|
|
|
* @return ProductCategory
|
|
|
|
*/
|
|
|
|
public function addProductsSold(\AppBundle\Entity\ProductSold $productsSold)
|
|
|
|
{
|
|
|
|
$this->productsSold[] = $productsSold;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove productsSold.
|
|
|
|
*
|
|
|
|
* @param \AppBundle\Entity\ProductSold $productsSold
|
|
|
|
*
|
|
|
|
* @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
|
|
|
|
*/
|
|
|
|
public function removeProductsSold(\AppBundle\Entity\ProductSold $productsSold)
|
|
|
|
{
|
|
|
|
return $this->productsSold->removeElement($productsSold);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get productsSold.
|
|
|
|
*
|
|
|
|
* @return \Doctrine\Common\Collections\Collection
|
|
|
|
*/
|
|
|
|
public function getProductsSold()
|
|
|
|
{
|
|
|
|
return $this->productsSold;
|
|
|
|
}
|
2018-03-15 16:04:00 +01:00
|
|
|
}
|