src/Entity/Category.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CategoryRepository;
  4. use Doctrine\DBAL\Types\Types;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Doctrine\Common\Collections\Collection;        // 追加
  7. use Doctrine\Common\Collections\ArrayCollection;   // 追加
  8. #[ORM\Entity(repositoryClassCategoryRepository::class)]
  9. #[ORM\Table(name"dtb_category")]  // ec-cube側のテーブル名を指定
  10. class Category
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column]
  15.     private ?int $id null;
  16.     // #[ORM\OneToMany(targetEntity: ProductCategory::class, mappedBy: 'product')]
  17.     #[ORM\OneToMany(targetEntityProductCategory::class, mappedBy'category')]
  18.     private Collection $productCategories;
  19.     public function __construct()
  20.     {
  21.         $this->productCategories = new ArrayCollection();
  22.     }
  23.     // /**
  24.     //  * Categoryを取得するためのメソッド
  25.     //  */
  26.     // public function getCategories(): Collection
  27.     // {
  28.     //     return $this->productCategories->map(fn(ProductCategory $pc) => $pc->getCategory());
  29.     // }
  30.     /**
  31.      * Productを取得するためのメソッド
  32.      */
  33.     public function getProducts(): Collection
  34.     {
  35.         return $this->productCategories->map(fn(ProductCategory $pc) => $pc->getProduct());
  36.     }
  37.     #[ORM\Column(nullabletrue)]
  38.     private ?int $parent_category_id null;
  39.     #[ORM\Column(nullabletrue)]
  40.     private ?int $creator_id null;
  41.     #[ORM\Column(length255)]
  42.     private ?string $category_name null;
  43.     #[ORM\Column]
  44.     private ?int $hierarchy null;
  45.     #[ORM\Column]
  46.     private ?int $sort_no null;
  47.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  48.     private ?\DateTimeInterface $create_date null;
  49.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  50.     private ?\DateTimeInterface $update_date null;
  51.     #[ORM\Column(length255)]
  52.     private ?string $discriminator_type null;
  53.     public function getId(): ?int
  54.     {
  55.         return $this->id;
  56.     }
  57.     public function getParentCategoryId(): ?int
  58.     {
  59.         return $this->parent_category_id;
  60.     }
  61.     public function setParentCategoryId(?int $parent_category_id): static
  62.     {
  63.         $this->parent_category_id $parent_category_id;
  64.         return $this;
  65.     }
  66.     public function getCreatorId(): ?int
  67.     {
  68.         return $this->creator_id;
  69.     }
  70.     public function setCreatorId(?int $creator_id): static
  71.     {
  72.         $this->creator_id $creator_id;
  73.         return $this;
  74.     }
  75.     public function getCategoryName(): ?string
  76.     {
  77.         return $this->category_name;
  78.     }
  79.     public function setCategoryName(string $category_name): static
  80.     {
  81.         $this->category_name $category_name;
  82.         return $this;
  83.     }
  84.     public function getHierarchy(): ?int
  85.     {
  86.         return $this->hierarchy;
  87.     }
  88.     public function setHierarchy(int $hierarchy): static
  89.     {
  90.         $this->hierarchy $hierarchy;
  91.         return $this;
  92.     }
  93.     public function getSortNo(): ?int
  94.     {
  95.         return $this->sort_no;
  96.     }
  97.     public function setSortNo(int $sort_no): static
  98.     {
  99.         $this->sort_no $sort_no;
  100.         return $this;
  101.     }
  102.     public function getCreateDate(): ?\DateTimeInterface
  103.     {
  104.         return $this->create_date;
  105.     }
  106.     public function setCreateDate(\DateTimeInterface $create_date): static
  107.     {
  108.         $this->create_date $create_date;
  109.         return $this;
  110.     }
  111.     public function getUpdateDate(): ?\DateTimeInterface
  112.     {
  113.         return $this->update_date;
  114.     }
  115.     public function setUpdateDate(\DateTimeInterface $update_date): static
  116.     {
  117.         $this->update_date $update_date;
  118.         return $this;
  119.     }
  120.     public function getDiscriminatorType(): ?string
  121.     {
  122.         return $this->discriminator_type;
  123.     }
  124.     public function setDiscriminatorType(string $discriminator_type): static
  125.     {
  126.         $this->discriminator_type $discriminator_type;
  127.         return $this;
  128.     }
  129. }