<?php
namespace App\AtechNet\CoreBundle\Entity;
use App\AtechNet\CoreBundle\Helper\SortableEntityInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
use Doctrine\ORM\Mapping\ManyToMany;
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\ORM\Mapping\OrderBy;
use Doctrine\ORM\Mapping\Table as Table;
use Symfony\Component\Validator\Constraints as Assert;
/**
* V2Attribute
*
* @Table(name="v2_attributes")
* @Entity
* @HasLifecycleCallbacks
*/
class V2Attribute extends AbstractSignedEntity implements SortableEntityInterface
{
public const int CONFIG_TYPE_MODEL = 0;
public const int CONFIG_TYPE_FIXED = 1;
public const int CONFIG_TYPE_CONFIGURABLE = 2;
public const int CONFIG_TYPE_PERSONALISATION = 3;
public const int FIELD_TYPE_TEXT = 0;
public const int FIELD_TYPE_NUMBER = 1;
public const int FIELD_TYPE_NUMBER_WITH_UNIT = 2;
public const int FIELD_TYPE_YES_NO = 3;
public const int FIELD_TYPE_WITH_ADDITIONAL_FIELDS = 4;
public const int FIELD_TYPE_SELECT = 5;
public const array FIELD_TYPE_LIST = [
self::FIELD_TYPE_TEXT => 'Text field',
self::FIELD_TYPE_NUMBER => 'Number field',
self::FIELD_TYPE_NUMBER_WITH_UNIT => 'Number value + Unit',
self::FIELD_TYPE_YES_NO => 'Boolean field',
self::FIELD_TYPE_WITH_ADDITIONAL_FIELDS => 'Additional fields',
self::FIELD_TYPE_SELECT => 'Select field',
];
public static function getFieldTypeList(bool $isProductModelConfig = false): array
{
$list = self::FIELD_TYPE_LIST;
if ($isProductModelConfig) {
unset($list[self::FIELD_TYPE_WITH_ADDITIONAL_FIELDS]);
} else {
unset($list[self::FIELD_TYPE_SELECT]);
}
return $list;
}
public const int ID_CPU = 1;
public const int ID_GPU = 3;
public const int ID_RAM_MAXIMUM_SIZE = 28;
public const int ID_DISPLAY = 5;
public const int ID_STORAGE_MAXIMUM_SIZE = 30;
public const int ID_TOTAL_USB_2_0_PORTS = 31;
public const int ID_TOTAL_USB_3_0_PORTS = 32;
public const int ID_WEBCAM = 57;
public const int ID_NEW_BATTERY = 58;
public const int ID_OS = 12;
public const int ID_RAM_INSTALLED_SIZE = 13;
public const int ID_STORAGE_INSTALLED_SIZE = 14;
public const int ID_KEYBOARD_REPRINT = 15;
public const int ID_OS_LANGUAGE = 16;
public const int ID_SKIN = 17;
public const int ID_RAM_TECHNOLOGY = 33;
public const int ID_GRADE = 19;
public const int ID_INTEGRATED_RAM = 20;
public const int ID_INTEGRATED_STORAGE = 21;
public const int ID_SATA_TYPE = 26;
public const int ID_RAM_SLOT_COUNT = 34;
public const int ID_STORAGE_SLOT_COUNT = 35;
public const int ID_STORAGE_TYPE = 41;
public const int ID_STORAGE_INSTALLED_SIZE_SSD_HDD = 42;
public const int ID_CPU_GENERATION = 36;
public const array REQUIRED_ATTRIBUTE_LIST = [
'model' => [
self::ID_RAM_MAXIMUM_SIZE,
self::ID_STORAGE_MAXIMUM_SIZE,
self::ID_TOTAL_USB_2_0_PORTS,
self::ID_TOTAL_USB_3_0_PORTS,
self::ID_RAM_TECHNOLOGY,
self::ID_RAM_SLOT_COUNT,
self::ID_STORAGE_SLOT_COUNT,
self::ID_STORAGE_TYPE,
self::ID_WEBCAM,
self::ID_SATA_TYPE,
],
'fixedAndConfigurable' => [
self::ID_CPU,
self::ID_GRADE,
self::ID_DISPLAY,
// self::ID_OS,
self::ID_RAM_INSTALLED_SIZE,
self::ID_STORAGE_INSTALLED_SIZE,
self::ID_STORAGE_INSTALLED_SIZE_SSD_HDD,
// self::ID_KEYBOARD_REPRINT,
// self::ID_OS_LANGUAGE
],
];
/**
* @var int
*
* @Column(name="type", type="integer")
*/
private $type;
/**
* @var string
*
* @Column(name="title", type="text", nullable=true)
*/
private $title;
/**
* @var int
*
* @Column(name="field_type", type="integer")
*/
private $fieldType = 0;
/**
* @var ArrayCollection
*
* @OneToMany(targetEntity="V2AttributeOption", mappedBy="v2Attribute", cascade={"persist", "remove"})
**/
private $v2AttributeOptions;
/**
* @var integer
*
* @Assert\NotNull
*
* @Column(name="sort_index", type="integer")
*/
private $sortIndex = -1;
/**
* @var ArrayCollection
*
* @OneToMany(targetEntity="AttributeAdditionalField", mappedBy="v2Attribute", cascade={"persist", "remove"})
* @OrderBy({"sortIndex" = "ASC"})
**/
private $additionalFields;
/**
* @var ArrayCollection
*
* @ManyToMany(targetEntity="AttributeTemplate", mappedBy="attributes")
**/
private $attributeTemplates;
public function __construct()
{
parent::__construct();
$this->v2AttributeOptions = new ArrayCollection();
$this->additionalFields = new ArrayCollection();
$this->attributeTemplates = new ArrayCollection();
}
/**
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* @param string $title
*/
public function setTitle(string $title)
{
$this->title = $title;
}
/**
* @return ArrayCollection
*/
public function getV2AttributeOptions()
{
return $this->v2AttributeOptions->filter(fn (V2AttributeOption $option) => !$option->isArchived());
}
/**
* @param V2AttributeOption $v2AttributeOption
*
* @return void
*/
public function addOption($v2AttributeOption)
{
if (!$this->v2AttributeOptions->contains($v2AttributeOption)) {
$this->v2AttributeOptions->add($v2AttributeOption);
$v2AttributeOption->setV2Attribute($this);
}
}
/**
* @param V2AttributeOption $v2AttributeOptions
*
* @return void
*/
public function removeOption(V2AttributeOption $v2AttributeOption)
{
$this->v2AttributeOptions->removeElement($v2AttributeOption);
}
/**
* @return ArrayCollection
*/
public function getVariationAdditionalFields()
{
return $this->additionalFields;
}
/**
* @param AttributeAdditionalField $variationAdditionalField
*
* @return void
*/
public function addAdditionalField($variationAdditionalField)
{
if (!$this->additionalFields->contains($variationAdditionalField)) {
$this->additionalFields->add($variationAdditionalField);
$variationAdditionalField->setV2Attribute($this);
}
}
/**
* @param AttributeAdditionalField $additionalFields
*
* @return void
*/
public function removeAdditionalField(AttributeAdditionalField $additionalFields)
{
$this->additionalFields->removeElement($additionalFields);
}
/**
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* @param string $type
*/
public function setType($type)
{
$this->type = $type;
}
/**
* @return int
*/
public function getSortIndex()
{
return $this->sortIndex;
}
/**
* @param int $sortIndex
*/
public function setSortIndex($sortIndex)
{
$this->sortIndex = $sortIndex;
}
/**
* @return int
*/
public function getFieldType()
{
return $this->fieldType;
}
/**
* @param int $fieldType
*/
public function setFieldType(int $fieldType)
{
$this->fieldType = $fieldType;
}
}