src/Entity/Analog.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Service\Helper\DateTimeHelper;
  4. use DateTime;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass="App\Repository\AnalogRepository")
  9.  * @ORM\Table(name="products__analogs" )
  10.  */
  11. class Analog
  12. {
  13.     use IdTrait;
  14.     /**
  15.      * @ORM\Column(name="enabled", type="boolean", nullable=false, options={"default":1})
  16.      */
  17.     private bool $enabled true;
  18.     /**
  19.      * @ORM\ManyToOne(targetEntity="App\Entity\Product", inversedBy="analogs")
  20.      * @ORM\JoinColumn(name="owner_product_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
  21.      */
  22.     private Product $owner;
  23.     /**
  24.      * @ORM\ManyToOne(targetEntity="App\Entity\Product")
  25.      * @ORM\JoinColumn(name="analog_product_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
  26.      */
  27.     private Product $product;
  28.     public function __construct(Product $ownerProduct $analog)
  29.     {
  30.         if($owner === $analog) {
  31.             throw new \Exception('Запчасть не может быть своим же оригиналом');
  32.         }
  33.         $this->owner $owner;
  34.         $this->product $analog;
  35.     }
  36.     public function isEnabled(): bool
  37.     {
  38.         return $this->enabled;
  39.     }
  40.     public function getOwner(): Product
  41.     {
  42.         return $this->owner;
  43.     }
  44.     public function getProduct(): Product
  45.     {
  46.         return $this->product;
  47.     }
  48. }