classes/XLite/Model/AttributeGroup.php line 125

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright (c) 2011-present Qualiteam software Ltd. All rights reserved.
  4.  * See https://www.x-cart.com/license-agreement.html for license details.
  5.  */
  6. namespace XLite\Model;
  7. use ApiPlatform\Core\Annotation as ApiPlatform;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use XLite\API\Endpoint\AttributeGroup\DTO\AttributeGroupInput as Input;
  10. use XLite\API\Endpoint\AttributeGroup\DTO\AttributeGroupOutput as Output;
  11. use XLite\Controller\API\AttributeGroup\Post;
  12. /**
  13.  * @ORM\Entity
  14.  * @ORM\Table (name="attribute_groups")
  15.  * @ApiPlatform\ApiResource(
  16.  *     shortName="Attribute Group",
  17.  *     input=Input::class,
  18.  *     output=Output::class,
  19.  *     itemOperations={
  20.  *          "get"={
  21.  *              "method"="GET",
  22.  *              "path"="/attribute_groups/{id}.{_format}",
  23.  *              "identifiers"={"id"},
  24.  *              "openapi_context"={
  25.  *                  "summary"="Retrieve an attribute group",
  26.  *             },
  27.  *           },
  28.  *          "put"={
  29.  *              "method"="PUT",
  30.  *              "path"="/attribute_groups/{id}.{_format}",
  31.  *              "identifiers"={"id"},
  32.  *              "openapi_context"={
  33.  *                  "summary"="Update an attribute group",
  34.  *             },
  35.  *           },
  36.  *          "delete"={
  37.  *              "method"="DELETE",
  38.  *              "path"="/attribute_groups/{id}.{_format}",
  39.  *              "identifiers"={"id"},
  40.  *              "openapi_context"={
  41.  *                  "summary"="Delete an attribute group",
  42.  *             },
  43.  *           },
  44.  *          "product_class_based_get_subresource"={
  45.  *              "method"="GET",
  46.  *              "path"="/product_classes/{class_id}/attribute_groups/{id}.{_format}",
  47.  *              "identifiers"={"id"},
  48.  *              "openapi_context"={
  49.  *                  "summary"="Retrieve an attribute group from a product class",
  50.  *                  "parameters"={
  51.  *                     {"name"="class_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  52.  *                     {"name"="id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  53.  *                  }
  54.  *              }
  55.  *          },
  56.  *          "product_class_based_put_subresource"={
  57.  *              "method"="PUT",
  58.  *              "path"="/product_classes/{class_id}/attribute_groups/{id}.{_format}",
  59.  *              "identifiers"={"id"},
  60.  *              "openapi_context"={
  61.  *                  "summary"="Update an attribute group of a product class",
  62.  *                  "parameters"={
  63.  *                     {"name"="class_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  64.  *                     {"name"="id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  65.  *                  }
  66.  *              }
  67.  *          },
  68.  *          "product_class_based_delete_subresource"={
  69.  *              "method"="DELETE",
  70.  *              "path"="/product_classes/{class_id}/attribute_groups/{id}.{_format}",
  71.  *              "identifiers"={"id"},
  72.  *              "openapi_context"={
  73.  *                  "summary"="Delete an attribute group from a product class",
  74.  *                  "parameters"={
  75.  *                     {"name"="class_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  76.  *                     {"name"="id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  77.  *                  }
  78.  *              }
  79.  *          },
  80.  *     },
  81.  *     collectionOperations={
  82.  *          "get"={
  83.  *              "method"="GET",
  84.  *              "path"="/attribute_groups.{_format}",
  85.  *              "identifiers"={"id"},
  86.  *          },
  87.  *          "post"={
  88.  *              "method"="POST",
  89.  *              "path"="/attribute_groups.{_format}",
  90.  *              "identifiers"={"id"},
  91.  *              "openapi_context"={
  92.  *                  "summary"="Create an attribute group",
  93.  *             },
  94.  *          },
  95.  *          "product_class_based_get_subresources"={
  96.  *              "method"="GET",
  97.  *              "path"="/product_classes/{class_id}/attribute_groups.{_format}",
  98.  *              "identifiers"={"id"},
  99.  *              "openapi_context"={
  100.  *                  "summary"="Retrieve a list of attribute groups from a product class",
  101.  *                  "parameters"={
  102.  *                     {"name"="class_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  103.  *                  }
  104.  *              }
  105.  *          },
  106.  *          "product_class_based_post_subresources"={
  107.  *              "method"="POST",
  108.  *              "path"="/product_classes/{class_id}/attribute_groups.{_format}",
  109.  *              "identifiers"={"id"},
  110.  *              "controller"=Post::class,
  111.  *              "openapi_context"={
  112.  *                  "summary"="Add an attribute group to a product class",
  113.  *                  "parameters"={
  114.  *                     {"name"="class_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  115.  *                  }
  116.  *              }
  117.  *          }
  118.  *     }
  119.  * )
  120.  */
  121. class AttributeGroup extends \XLite\Model\Base\I18n
  122. {
  123.     /**
  124.      * @var int
  125.      *
  126.      * @ORM\Id
  127.      * @ORM\GeneratedValue (strategy="AUTO")
  128.      * @ORM\Column (type="integer", options={"unsigned": true})
  129.      */
  130.     protected $id;
  131.     /**
  132.      * @var int
  133.      *
  134.      * @ORM\Column (type="integer")
  135.      */
  136.     protected $position 0;
  137.     /**
  138.      * @var \XLite\Model\ProductClass
  139.      *
  140.      * @ORM\ManyToOne (targetEntity="XLite\Model\ProductClass", inversedBy="attribute_groups")
  141.      * @ORM\JoinColumn (name="product_class_id", referencedColumnName="id", onDelete="CASCADE")
  142.      */
  143.     protected $productClass;
  144.     /**
  145.      * @var \Doctrine\Common\Collections\Collection
  146.      *
  147.      * @ORM\OneToMany (targetEntity="XLite\Model\Attribute", mappedBy="attributeGroup")
  148.      */
  149.     protected $attributes;
  150.     /**
  151.      * @var \Doctrine\Common\Collections\Collection
  152.      *
  153.      * @ORM\OneToMany (targetEntity="XLite\Model\AttributeGroupTranslation", mappedBy="owner", cascade={"all"})
  154.      */
  155.     protected $translations;
  156.     /**
  157.      * Constructor
  158.      *
  159.      * @param array $data Entity properties OPTIONAL
  160.      *
  161.      * @return void
  162.      */
  163.     public function __construct(array $data = [])
  164.     {
  165.         $this->attributes = new \Doctrine\Common\Collections\ArrayCollection();
  166.         parent::__construct($data);
  167.     }
  168.     /**
  169.      * Return number of attributes associated with this class
  170.      *
  171.      * @return integer
  172.      */
  173.     public function getAttributesCount()
  174.     {
  175.         return count($this->getAttributes());
  176.     }
  177.     /**
  178.      * Get id
  179.      *
  180.      * @return integer
  181.      */
  182.     public function getId()
  183.     {
  184.         return $this->id;
  185.     }
  186.     /**
  187.      * Set position
  188.      *
  189.      * @param integer $position
  190.      * @return AttributeGroup
  191.      */
  192.     public function setPosition($position)
  193.     {
  194.         $this->position $position;
  195.         return $this;
  196.     }
  197.     /**
  198.      * Get position
  199.      *
  200.      * @return integer
  201.      */
  202.     public function getPosition()
  203.     {
  204.         return $this->position;
  205.     }
  206.     /**
  207.      * Set productClass
  208.      *
  209.      * @param \XLite\Model\ProductClass $productClass
  210.      * @return AttributeGroup
  211.      */
  212.     public function setProductClass(\XLite\Model\ProductClass $productClass null)
  213.     {
  214.         $this->productClass $productClass;
  215.         return $this;
  216.     }
  217.     /**
  218.      * Get productClass
  219.      *
  220.      * @return \XLite\Model\ProductClass
  221.      */
  222.     public function getProductClass()
  223.     {
  224.         return $this->productClass;
  225.     }
  226.     /**
  227.      * Add attributes
  228.      *
  229.      * @param \XLite\Model\Attribute $attributes
  230.      * @return AttributeGroup
  231.      */
  232.     public function addAttributes(\XLite\Model\Attribute $attributes)
  233.     {
  234.         $this->attributes[] = $attributes;
  235.         return $this;
  236.     }
  237.     /**
  238.      * Get attributes
  239.      *
  240.      * @return \Doctrine\Common\Collections\Collection
  241.      */
  242.     public function getAttributes()
  243.     {
  244.         return $this->attributes;
  245.     }
  246. }