caisse-bliss/nope/Entity/Product.php

248 lines
5.2 KiB
PHP
Raw Permalink 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
2023-06-20 19:14:19 +02:00
use App\Traits\Commentable;
use App\Traits\Sellable;
2023-06-28 16:16:11 +02:00
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
2018-03-15 16:04:00 +01:00
use Doctrine\ORM\Mapping as ORM;
2023-06-28 16:19:33 +02:00
use ApiPlatform\Core\Annotation\ApiResource;
2018-03-15 16:04:00 +01:00
/**
2023-06-20 19:14:19 +02:00
* @ORM\Entity(repositoryClass="App\Repository\ProductRepository")
2018-03-15 16:04:00 +01:00
*/
2023-06-28 16:19:33 +02:00
#[ApiResource]
2018-03-15 16:04:00 +01:00
class Product {
2023-06-28 16:19:33 +02:00
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
#[ORM\Column(type: 'integer')]
2018-03-15 16:04:00 +01:00
private $id;
2018-04-20 09:23:44 +02:00
/**
* number of items available
* @ORM\Column(name="stock_count", type="integer")
*/
private $stockCount;
2018-03-15 16:04:00 +01:00
/**
* @ORM\Column(type="string", length=100)
*/
private $name;
/**
2018-04-20 09:40:17 +02:00
* url for image
2018-04-17 16:23:35 +02:00
* @ORM\Column(type="string", length=256, nullable=true)
*/
private $image;
2018-03-15 16:04:00 +01:00
/**
2018-03-15 16:18:06 +01:00
* @ORM\ManyToOne(targetEntity="ProductCategory", inversedBy="products")
2018-03-15 16:04:00 +01:00
*/
private $category;
2018-03-15 16:18:06 +01:00
/**
2023-06-20 19:14:19 +02:00
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="products")
2018-03-15 16:18:06 +01:00
*/
2018-04-05 15:05:04 +02:00
private $user;
2018-04-25 11:48:37 +02:00
/**
2023-06-20 19:14:19 +02:00
* @ORM\OneToMany(targetEntity="App\Entity\ProductSold", mappedBy="product", cascade={"remove"})
2018-04-25 11:48:37 +02:00
*/
private $productsSold;
2018-04-05 15:05:04 +02:00
2024-07-16 12:34:16 +02:00
#[ORM\ManyToMany(targetEntity: User::class, mappedBy: 'users')]
2023-06-28 16:16:11 +02:00
private Collection $admins;
2024-07-16 12:34:16 +02:00
2018-04-05 15:05:04 +02:00
use Sellable;
use Commentable;
/**
* Get id.
*
* @return int
2018-03-15 16:04:00 +01:00
*/
public function getId() {
2024-07-16 12:34:16 +02:00
return $this->id;
}
2018-03-15 16:04:00 +01:00
/**
* Set name.
*
* @param string $name
*
* @return Product
2018-03-15 16:04:00 +01:00
*/
public function setName( $name ) {
2024-07-16 12:34:16 +02:00
$this->name = $name;
return $this;
}
2018-03-15 16:04:00 +01:00
/**
* Get name.
*
* @return string
2018-03-15 16:04:00 +01:00
*/
public function getName() {
2024-07-16 12:34:16 +02:00
return $this->name;
}
2018-03-15 16:04:00 +01:00
/**
* Set image.
*
* @param string|null $image
*
* @return Product
2018-03-15 16:04:00 +01:00
*/
public function setImage( $image = null ) {
2024-07-16 12:34:16 +02:00
$this->image = $image;
return $this;
}
2018-03-15 16:04:00 +01:00
/**
* Get image.
*
* @return string|null
2018-03-15 16:04:00 +01:00
*/
public function getImage() {
2024-07-16 12:34:16 +02:00
return $this->image;
}
2018-03-15 16:04:00 +01:00
/**
* Set category.
*
2023-06-20 19:14:19 +02:00
* @param \App\Entity\ProductCategory|null $category
*
* @return Product
2018-03-15 16:04:00 +01:00
*/
2023-06-20 19:14:19 +02:00
public function setCategory( \App\Entity\ProductCategory $category = null ) {
2024-07-16 12:34:16 +02:00
$this->category = $category;
return $this;
}
2018-03-15 16:04:00 +01:00
/**
* Get category.
*
2023-06-20 19:14:19 +02:00
* @return \App\Entity\ProductCategory|null
2018-03-15 16:04:00 +01:00
*/
public function getCategory() {
2024-07-16 12:34:16 +02:00
return $this->category;
}
2018-03-15 16:04:00 +01:00
/**
* Set user.
*
2023-06-20 19:14:19 +02:00
* @param \App\Entity\User|null $user
*
* @return Product
2018-03-15 16:04:00 +01:00
*/
2023-06-20 19:14:19 +02:00
public function setUser( \App\Entity\User $user = null ) {
2024-07-16 12:34:16 +02:00
$this->user = $user;
return $this;
}
2018-04-05 15:05:04 +02:00
/**
* Get user.
2018-04-05 15:05:04 +02:00
*
2023-06-20 19:14:19 +02:00
* @return \App\Entity\User|null
2018-04-05 15:05:04 +02:00
*/
public function getUser() {
2024-07-16 12:34:16 +02:00
return $this->user;
}
2018-04-20 09:23:44 +02:00
2018-04-20 09:40:17 +02:00
/**
* Set stockCount.
*
* @param int $stockCount
*
* @return Product
*/
public function setStockCount( $stockCount ) {
2024-07-16 12:34:16 +02:00
$this->stockCount = $stockCount;
return $this;
}
2018-04-20 09:40:17 +02:00
/**
* Get stockCount.
*
* @return int
*/
public function getStockCount() {
2024-07-16 12:34:16 +02:00
return $this->stockCount;
}
2018-04-25 11:48:37 +02:00
/**
* Constructor
*/
public function __construct() {
2024-07-16 12:34:16 +02:00
$this->productsSold = new \Doctrine\Common\Collections\ArrayCollection();
$this->admins = new ArrayCollection();
}
2018-04-25 11:48:37 +02:00
/**
* Add productsSold.
*
2023-06-20 19:14:19 +02:00
* @param \App\Entity\User $productsSold
2018-04-25 11:48:37 +02:00
*
* @return Product
*/
2023-06-20 19:14:19 +02:00
public function addProductsSold( \App\Entity\User $productsSold ) {
2024-07-16 12:34:16 +02:00
$this->productsSold[] = $productsSold;
return $this;
}
2018-04-25 11:48:37 +02:00
/**
* Remove productsSold.
*
2023-06-20 19:14:19 +02:00
* @param \App\Entity\User $productsSold
2018-04-25 11:48:37 +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\User $productsSold ) {
2024-07-16 12:34:16 +02:00
return $this->productsSold->removeElement( $productsSold );
}
2018-04-25 11:48:37 +02:00
/**
* Get productsSold.
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getProductsSold() {
2024-07-16 12:34:16 +02:00
return $this->productsSold;
}
2023-06-28 16:16:11 +02:00
/**
* @return Collection<int, Admin>
*/
public function getAdmins(): Collection
{
return $this->admins;
}
public function addAdmin(Admin $admin): static
{
if (!$this->admins->contains($admin)) {
$this->admins->add($admin);
$admin->addProduct($this);
}
return $this;
}
public function removeAdmin(Admin $admin): static
{
if ($this->admins->removeElement($admin)) {
$admin->removeProduct($this);
}
return $this;
}
2018-03-15 16:04:00 +01:00
}