caisse-bliss/nope/Entity/ProductCategory.php

214 lines
4.0 KiB
PHP
Raw Normal View History

2018-03-15 16:04:00 +01:00
<?php
2023-06-20 19:14:19 +02:00
namespace App\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
/**
2023-06-20 19:14:19 +02:00
* @ORM\Entity(repositoryClass="App\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;
/**
* @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
/**
* @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
/**
2023-06-20 19:14:19 +02:00
* @ORM\ManyToMany(targetEntity="App\Entity\User", mappedBy="categories")
2018-04-05 15:05:04 +02:00
*/
private $users;
2023-06-28 16:16:11 +02:00
#[ORM\ManyToOne(inversedBy: 'productCategory')]
private ?Admin $admin = null;
2018-04-05 17:24:43 +02:00
public function __toString() {
2023-06-28 16:16:11 +02:00
return $this->getName() . ' (' . count( $this->getProducts() ) . ' produits)';
}
2018-04-05 17:24:43 +02:00
2018-05-04 17:22:49 +02:00
/**
* @param $userId
*
* @return bool
*/
public function hasUser( $userId ) {
2023-06-28 16:16:11 +02:00
foreach ( $this->getUsers() as $user ) {
if ( $user->getId() === $userId ) {
return true;
}
}
return false;
}
2018-05-04 17:22:49 +02:00
2018-04-05 15:05:04 +02:00
/**
* @return mixed
*/
public function getUsers() {
2023-06-28 16:16:11 +02:00
return $this->users;
}
2018-04-05 15:05:04 +02:00
/**
* @param mixed $users
*/
public function setUsers( $users ) {
2023-06-28 16:16:11 +02:00
$this->users = $users;
}
2018-04-05 15:05:04 +02:00
2018-03-15 16:18:06 +01:00
/**
* @return mixed
*/
public function getProducts() {
2023-06-28 16:16:11 +02:00
return $this->products;
}
2018-03-15 16:18:06 +01:00
/**
* @param mixed $products
*/
public function setProducts( $products ) {
2023-06-28 16:16:11 +02:00
$this->products = $products;
}
2018-03-15 16:18:06 +01:00
2018-03-15 16:04:00 +01:00
/**
* @return mixed
*/
public function getId() {
2023-06-28 16:16:11 +02:00
return $this->id;
}
2018-03-15 16:04:00 +01:00
/**
* @param mixed $id
*/
public function setId( $id ) {
2023-06-28 16:16:11 +02:00
$this->id = $id;
}
2018-03-15 16:04:00 +01:00
/**
* @return mixed
*/
public function getName() {
2023-06-28 16:16:11 +02:00
return $this->name;
}
2018-03-15 16:04:00 +01:00
/**
* @param mixed $name
*/
public function setName( $name ) {
2023-06-28 16:16:11 +02:00
$this->name = $name;
}
2018-03-15 16:04:00 +01:00
2018-04-04 17:42:27 +02:00
/**
* Constructor
*/
public function __construct() {
2023-06-28 16:16:11 +02:00
$this->products = new \Doctrine\Common\Collections\ArrayCollection();
}
2018-04-04 17:42:27 +02:00
/**
* Add product
*
2023-06-20 19:14:19 +02:00
* @param \App\Entity\Product $product
2018-04-04 17:42:27 +02:00
*
* @return ProductCategory
*/
2023-06-20 19:14:19 +02:00
public function addProduct( \App\Entity\Product $product ) {
2023-06-28 16:16:11 +02:00
$this->products[] = $product;
return $this;
}
2018-04-04 17:42:27 +02:00
/**
* Remove product
*
2023-06-20 19:14:19 +02:00
* @param \App\Entity\Product $product
2018-04-04 17:42:27 +02:00
*/
2023-06-20 19:14:19 +02:00
public function removeProduct( \App\Entity\Product $product ) {
2023-06-28 16:16:11 +02:00
$this->products->removeElement( $product );
}
2018-04-17 12:10:21 +02:00
2018-04-17 15:41:00 +02:00
/**
* Add user
*
2023-06-20 19:14:19 +02:00
* @param \App\Entity\User $user
2018-04-17 15:41:00 +02:00
*
* @return ProductCategory
*/
2023-06-20 19:14:19 +02:00
public function addUser( \App\Entity\User $user ) {
2023-06-28 16:16:11 +02:00
$this->users[] = $user;
return $this;
}
2018-04-17 15:41:00 +02:00
/**
* Remove user
*
2023-06-20 19:14:19 +02:00
* @param \App\Entity\User $user
2018-04-17 15:41:00 +02:00
*/
2023-06-20 19:14:19 +02:00
public function removeUser( \App\Entity\User $user ) {
2023-06-28 16:16:11 +02:00
$this->users->removeElement( $user );
}
2018-05-24 15:11:18 +02:00
/**
* Add productsSold.
*
2023-06-20 19:14:19 +02:00
* @param \App\Entity\ProductSold $productsSold
2018-05-24 15:11:18 +02:00
*
* @return ProductCategory
*/
2023-06-20 19:14:19 +02:00
public function addProductsSold(\App\Entity\ProductSold $productsSold)
2018-05-24 15:11:18 +02:00
{
$this->productsSold[] = $productsSold;
return $this;
}
/**
* Remove productsSold.
*
2023-06-20 19:14:19 +02:00
* @param \App\Entity\ProductSold $productsSold
2018-05-24 15:11:18 +02:00
*
* @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
*/
2023-06-20 19:14:19 +02:00
public function removeProductsSold(\App\Entity\ProductSold $productsSold)
2018-05-24 15:11:18 +02:00
{
return $this->productsSold->removeElement($productsSold);
}
/**
* Get productsSold.
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getProductsSold()
{
return $this->productsSold;
}
2023-06-28 16:16:11 +02:00
public function getAdmin(): ?Admin
{
return $this->admin;
}
public function setAdmin(?Admin $admin): static
{
$this->admin = $admin;
return $this;
}
2018-03-15 16:04:00 +01:00
}