src/AtechNet/CoreBundle/Entity/V2Attribute.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\AtechNet\CoreBundle\Entity;
  3. use App\AtechNet\CoreBundle\Helper\SortableEntityInterface;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\ORM\Mapping\Column;
  6. use Doctrine\ORM\Mapping\Entity;
  7. use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
  8. use Doctrine\ORM\Mapping\ManyToMany;
  9. use Doctrine\ORM\Mapping\OneToMany;
  10. use Doctrine\ORM\Mapping\OrderBy;
  11. use Doctrine\ORM\Mapping\Table as Table;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. /**
  14.  * V2Attribute
  15.  *
  16.  * @Table(name="v2_attributes")
  17.  * @Entity
  18.  * @HasLifecycleCallbacks
  19.  */
  20. class V2Attribute extends AbstractSignedEntity implements SortableEntityInterface
  21. {
  22.     public const int CONFIG_TYPE_MODEL = 0;
  23.     public const int CONFIG_TYPE_FIXED = 1;
  24.     public const int CONFIG_TYPE_CONFIGURABLE = 2;
  25.     public const int CONFIG_TYPE_PERSONALISATION = 3;
  26.     public const int FIELD_TYPE_TEXT = 0;
  27.     public const int FIELD_TYPE_NUMBER = 1;
  28.     public const int FIELD_TYPE_NUMBER_WITH_UNIT = 2;
  29.     public const int FIELD_TYPE_YES_NO = 3;
  30.     public const int FIELD_TYPE_WITH_ADDITIONAL_FIELDS = 4;
  31.     public const int FIELD_TYPE_SELECT = 5;
  32.     public const array FIELD_TYPE_LIST = [
  33.         self::FIELD_TYPE_TEXT                   => 'Text field',
  34.         self::FIELD_TYPE_NUMBER                 => 'Number field',
  35.         self::FIELD_TYPE_NUMBER_WITH_UNIT       => 'Number value + Unit',
  36.         self::FIELD_TYPE_YES_NO                 => 'Boolean field',
  37.         self::FIELD_TYPE_WITH_ADDITIONAL_FIELDS => 'Additional fields',
  38.         self::FIELD_TYPE_SELECT                 => 'Select field',
  39.     ];
  40.     public static function getFieldTypeList(bool $isProductModelConfig = false): array
  41.     {
  42.         $list = self::FIELD_TYPE_LIST;
  43.         if ($isProductModelConfig) {
  44.             unset($list[self::FIELD_TYPE_WITH_ADDITIONAL_FIELDS]);
  45.         } else {
  46.             unset($list[self::FIELD_TYPE_SELECT]);
  47.         }
  48.         return $list;
  49.     }
  50.     public const int ID_CPU = 1;
  51.     public const int ID_GPU = 3;
  52.     public const int ID_RAM_MAXIMUM_SIZE = 28;
  53.     public const int ID_DISPLAY = 5;
  54.     public const int ID_STORAGE_MAXIMUM_SIZE = 30;
  55.     public const int ID_TOTAL_USB_2_0_PORTS = 31;
  56.     public const int ID_TOTAL_USB_3_0_PORTS = 32;
  57.     public const int ID_WEBCAM = 57;
  58.     public const int ID_NEW_BATTERY = 58;
  59.     public const int ID_OS = 12;
  60.     public const int ID_RAM_INSTALLED_SIZE = 13;
  61.     public const int ID_STORAGE_INSTALLED_SIZE = 14;
  62.     public const int ID_KEYBOARD_REPRINT = 15;
  63.     public const int ID_OS_LANGUAGE = 16;
  64.     public const int ID_SKIN = 17;
  65.     public const int ID_RAM_TECHNOLOGY = 33;
  66.     public const int ID_GRADE = 19;
  67.     public const int ID_INTEGRATED_RAM = 20;
  68.     public const int ID_INTEGRATED_STORAGE = 21;
  69.     public const int ID_SATA_TYPE = 26;
  70.     public const int ID_RAM_SLOT_COUNT = 34;
  71.     public const int ID_STORAGE_SLOT_COUNT = 35;
  72.     public const int ID_STORAGE_TYPE = 41;
  73.     public const int ID_STORAGE_INSTALLED_SIZE_SSD_HDD = 42;
  74.     public const int ID_CPU_GENERATION = 36;
  75.     public const array REQUIRED_ATTRIBUTE_LIST = [
  76.         'model' => [
  77.             self::ID_RAM_MAXIMUM_SIZE,
  78.             self::ID_STORAGE_MAXIMUM_SIZE,
  79.             self::ID_TOTAL_USB_2_0_PORTS,
  80.             self::ID_TOTAL_USB_3_0_PORTS,
  81.             self::ID_RAM_TECHNOLOGY,
  82.             self::ID_RAM_SLOT_COUNT,
  83.             self::ID_STORAGE_SLOT_COUNT,
  84.             self::ID_STORAGE_TYPE,
  85.             self::ID_WEBCAM,
  86.             self::ID_SATA_TYPE,
  87.         ],
  88.         'fixedAndConfigurable' => [
  89.             self::ID_CPU,
  90.             self::ID_GRADE,
  91.             self::ID_DISPLAY,
  92.             // self::ID_OS,
  93.             self::ID_RAM_INSTALLED_SIZE,
  94.             self::ID_STORAGE_INSTALLED_SIZE,
  95.             self::ID_STORAGE_INSTALLED_SIZE_SSD_HDD,
  96.             // self::ID_KEYBOARD_REPRINT,
  97.             // self::ID_OS_LANGUAGE
  98.         ],
  99.     ];
  100.     /**
  101.      * @var int
  102.      *
  103.      * @Column(name="type", type="integer")
  104.      */
  105.     private $type;
  106.     /**
  107.      * @var string
  108.      *
  109.      * @Column(name="title", type="text", nullable=true)
  110.      */
  111.     private $title;
  112.     /**
  113.      * @var int
  114.      *
  115.      * @Column(name="field_type", type="integer")
  116.      */
  117.     private $fieldType = 0;
  118.     /**
  119.      * @var ArrayCollection
  120.      *
  121.      * @OneToMany(targetEntity="V2AttributeOption", mappedBy="v2Attribute", cascade={"persist", "remove"})
  122.      **/
  123.     private $v2AttributeOptions;
  124.     /**
  125.      * @var integer
  126.      *
  127.      * @Assert\NotNull
  128.      *
  129.      * @Column(name="sort_index", type="integer")
  130.      */
  131.     private $sortIndex = -1;
  132.     /**
  133.      * @var ArrayCollection
  134.      *
  135.      * @OneToMany(targetEntity="AttributeAdditionalField", mappedBy="v2Attribute", cascade={"persist", "remove"})
  136.      * @OrderBy({"sortIndex" = "ASC"})
  137.      **/
  138.     private $additionalFields;
  139.     /**
  140.      * @var ArrayCollection
  141.      *
  142.      * @ManyToMany(targetEntity="AttributeTemplate", mappedBy="attributes")
  143.      **/
  144.     private $attributeTemplates;
  145.     public function __construct()
  146.     {
  147.         parent::__construct();
  148.         $this->v2AttributeOptions = new ArrayCollection();
  149.         $this->additionalFields = new ArrayCollection();
  150.         $this->attributeTemplates = new ArrayCollection();
  151.     }
  152.     /**
  153.      * @return string
  154.      */
  155.     public function getTitle()
  156.     {
  157.         return $this->title;
  158.     }
  159.     /**
  160.      * @param string $title
  161.      */
  162.     public function setTitle(string $title)
  163.     {
  164.         $this->title = $title;
  165.     }
  166.     /**
  167.      * @return ArrayCollection
  168.      */
  169.     public function getV2AttributeOptions()
  170.     {
  171.         return $this->v2AttributeOptions->filter(fn (V2AttributeOption $option) => !$option->isArchived());
  172.     }
  173.     /**
  174.      * @param V2AttributeOption $v2AttributeOption
  175.      *
  176.      * @return void
  177.      */
  178.     public function addOption($v2AttributeOption)
  179.     {
  180.         if (!$this->v2AttributeOptions->contains($v2AttributeOption)) {
  181.             $this->v2AttributeOptions->add($v2AttributeOption);
  182.             $v2AttributeOption->setV2Attribute($this);
  183.         }
  184.     }
  185.     /**
  186.      * @param V2AttributeOption $v2AttributeOptions
  187.      *
  188.      * @return void
  189.      */
  190.     public function removeOption(V2AttributeOption $v2AttributeOption)
  191.     {
  192.         $this->v2AttributeOptions->removeElement($v2AttributeOption);
  193.     }
  194.     /**
  195.      * @return ArrayCollection
  196.      */
  197.     public function getVariationAdditionalFields()
  198.     {
  199.         return $this->additionalFields;
  200.     }
  201.     /**
  202.      * @param AttributeAdditionalField $variationAdditionalField
  203.      *
  204.      * @return void
  205.      */
  206.     public function addAdditionalField($variationAdditionalField)
  207.     {
  208.         if (!$this->additionalFields->contains($variationAdditionalField)) {
  209.             $this->additionalFields->add($variationAdditionalField);
  210.             $variationAdditionalField->setV2Attribute($this);
  211.         }
  212.     }
  213.     /**
  214.      * @param AttributeAdditionalField $additionalFields
  215.      *
  216.      * @return void
  217.      */
  218.     public function removeAdditionalField(AttributeAdditionalField $additionalFields)
  219.     {
  220.         $this->additionalFields->removeElement($additionalFields);
  221.     }
  222.     /**
  223.      * @return string
  224.      */
  225.     public function getType()
  226.     {
  227.         return $this->type;
  228.     }
  229.     /**
  230.      * @param string $type
  231.      */
  232.     public function setType($type)
  233.     {
  234.         $this->type = $type;
  235.     }
  236.     /**
  237.      * @return int
  238.      */
  239.     public function getSortIndex()
  240.     {
  241.         return $this->sortIndex;
  242.     }
  243.     /**
  244.      * @param int $sortIndex
  245.      */
  246.     public function setSortIndex($sortIndex)
  247.     {
  248.         $this->sortIndex = $sortIndex;
  249.     }
  250.     /**
  251.      * @return int
  252.      */
  253.     public function getFieldType()
  254.     {
  255.         return $this->fieldType;
  256.     }
  257.     /**
  258.      * @param int $fieldType
  259.      */
  260.     public function setFieldType(int $fieldType)
  261.     {
  262.         $this->fieldType = $fieldType;
  263.     }
  264. }