<?php
namespace App\AtechNet\CoreBundle\Entity;
use App\AtechNet\CoreBundle\Helper\SortableEntityInterface;
use App\AtechNet\CoreBundle\Translation\TranslationHelper;
use App\AtechNet\CoreBundle\Translation\TranslatorInterface;
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\Form\Exception\InvalidArgumentException;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Attribute
*
* @Table(name="attributes")
* @Entity
* @HasLifecycleCallbacks
*/
class Attribute extends AbstractSignedEntity implements SortableEntityInterface
{
public const string TYPE_NONE = '';
public const string TYPE_HIDDEN_CONFIGURATION = 'hidden-conf';
public const string TYPE_CONFIGURATION = 'conf';
public const string TYPE_ACCESSORY = 'acc';
public const int ATTRIBUTE_ID_SSD = 5;
public const int ATTRIBUTE_ID_SSD_18 = 390;
public const int ATTRIBUTE_ID_HDD_25 = 8;
public const int ATTRIBUTE_ID_HDD_35 = 9;
public const int ATTRIBUTE_ID_ACCESSORY_SSD = 47;
public const int ATTRIBUTE_ID_ACCESSORY_OS = 21;
public const int ATTRIBUTE_ID_ACCESSORY_SOFTWARE_PACKAGE = 22;
public const int ATTRIBUTE_ID_ACCESSORY_ANTIVIRUS_SOFTWARE = 23;
public const int ATTRIBUTE_ID_ACCESSORY_OFFICE_365 = 24;
public const int ATTRIBUTE_ID_ACCESSORY_MOUSE = 27;
public const int ATTRIBUTE_ID_ACCESSORY_HEADSET = 149;
public const int ATTRIBUTE_ID_ACCESSORY_NB_RAM_DDR2 = 29;
public const int ATTRIBUTE_ID_ACCESSORY_NB_RAM_DDR3 = 31;
public const int ATTRIBUTE_ID_ACCESSORY_NB_RAM_DDR4 = 153;
public const int ATTRIBUTE_ID_ACCESSORY_PC_RAM_DDR2 = 28;
public const int ATTRIBUTE_ID_ACCESSORY_PC_RAM_DDR3 = 30;
public const int ATTRIBUTE_ID_ACCESSORY_PC_RAM_DDR4 = 147;
public const int ATTRIBUTE_ID_ACCESSORY_AC_ADAPTER = 150;
public const int ATTRIBUTE_ID_ACCESSORY_AC_ADAPTER_CONF = 245;
public const int ATTRIBUTE_ID_ACCESSORY_KEYBOARD_REPRINT = 184;
public const int ATTRIBUTE_ID_ACCESSORY_CABLE = 123;
public const int ATTRIBUTE_ID_ACCESSORY_DOCKING_STATION = 392;
public const int ATTRIBUTE_ID_OPERATING_SYSTEM = 41;
public const int ATTRIBUTE_ID_WEBCAM = 19;
public const int ATTRIBUTE_ID_BATTERY = 96;
public const int ATTRIBUTE_ID_NEW_BATTERY = 401;
public const int ATTRIBUTE_ID_NOTEBOOK_BATTERY = 402;
public const int ATTRIBUTE_ID_QUALITY = 101;
public const int ATTRIBUTE_ID_SAS_HDD25 = 314;
public const int ATTRIBUTE_ID_HDD18 = 166;
public const int ATTRIBUTE_ID_SSHD25 = 6;
public const int ATTRIBUTE_ID_SSHD35 = 7;
public const int ATTRIBUTE_ID_SCREEN_SIZE = 12;
public const int ATTRIBUTE_ID_MAXIMUM_RESOLUTION = 63;
public const int ATTRIBUTE_ID_RESPONSE_TIME = 66;
public const int ATTRIBUTE_ID_DISPLAY_TECHNOLOGY = 118;
public const int ATTRIBUTE_ID_ASPECT_RATIO = 74;
public const int ATTRIBUTE_ID_CPU_NB = 33;
public const int ATTRIBUTE_ID_CPU_NB_FAMILY = 142;
public const int ATTRIBUTE_ID_RAM_NB = 4;
public const int ATTRIBUTE_ID_CPU_PC = 32;
public const int ATTRIBUTE_ID_RAM_PC = 3;
public const int ATTRIBUTE_ID_VGA = 25;
public const int ATTRIBUTE_ID_MAX_SPEED = 321;
public const int ATTRIBUTE_ID_MAX_RANGE = 322;
public const int ATTRIBUTE_ID_POWER = 325;
public const int ATTRIBUTE_ID_PRINTING_TECHNOLOGY = 87;
public const int ATTRIBUTE_ID_PRINTING_COLOR = 88;
public const int ATTRIBUTE_ID_DUPLEX = 81;
public const int ATTRIBUTE_ID_PORTS = 85;
public const int ATTRIBUTE_ID_PRINTING_SPEED = 80;
public const int ATTRIBUTE_ID_DISPLAY = 170;
public const int ATTRIBUTE_ID_CPU_PHONE = 114;
public const int ATTRIBUTE_ID_RAM = 171;
public const int ATTRIBUTE_ID_NOTEBOOK_SKIN = 320;
public const int ATTRIBUTE_ID_CPU_GENERATION = 174;
public const int ATTRIBUTE_ID_FORM = 1;
public const int ATTRIBUTE_ID_EXTERNAL_CONNECTORS = 45;
public const int ATTRIBUTE_ID_GRAPHIC_INPUTS = 68;
public const int ATTRIBUTE_ID_VIEW_ANGLES = 67;
public const int ATTRIBUTE_ID_CONTRAST = 65;
public const int ATTRIBUTE_ID_BRIGHTNESS = 64;
public const int ATTRIBUTE_ID_CONF_OS = 41;
public const int ATTRIBUTE_ID_PROJECTOR_REMOTE = 218;
public const int ATTRIBUTE_ID_LUMEN = 182;
public const int ATTRIBUTE_ID_CPU_PC_FAMILY = 141;
public const int ATTRIBUTE_ID_CLOCKSPEED = 125;
public const int ATTRIBUTE_ID_CPU_SOCKET = 128;
public const int ATTRIBUTE_ID_MEMORY_TYPE = 204;
public const int ATTRIBUTE_ID_MEMORY_SIZE = 144;
public const int ATTRIBUTE_ID_MEMORY_FREQUENCY = 206;
public const int ATTRIBUTE_ID_TOUCH_SCREEN = 139;
public const int ATTRIBUTE_ID_MEMORY = 79;
public const int ATTRIBUTE_ID_CONNECTORS = 69;
public const int ATTRIBUTE_ID_DOCKING_STATION_POWER_INPUT = 223;
public const int ATTRIBUTE_ID_COLOR = 160;
public const int ATTRIBUTE_ID_NOTEBOOK_BAG_SIZE = 159;
public const int ATTRIBUTE_ID_CONF_NOTEBOOK_SKIN = 362;
public const int ATTRIBUTE_ID_RAM_PC_TYPE = 383;
public const int ATTRIBUTE_ID_RAM_NB_TYPE = 382;
public const int ATTRIBUTE_ID_RAM_SIZE = 384;
public const int ATTRIBUTE_ID_CPU_SERVER = 35;
public const int ATTRIBUTE_ID_CPU_TABLET = 36;
public const int ATTRIBUTE_ID_ODD_NB = 11;
public const int ATTRIBUTE_ID_CONFIG_KEYBOARD_REPRINT = 396;
public const int ATTRIBUTE_ID_KEYBOARD_LANGUAGE = 94;
public const int ATTRIBUTE_ID_NUMPAD = 17;
public const int ATTRIBUTE_ID_OPTICAL_DRIVER = 11;
public const int ATTRIBUTE_ID_YEAR_OF_PRODUCTION = 396;
public const int ATTRIBUTE_ID_CPU_MARK = 397;
public const int ATTRIBUTE_ID_POWER_CABLE = 137;
public const int ATTRIBUTE_ID_SCREEN_REFRESH_RATE = 176;
public const int ATTRIBUTE_ID_VESA = 70;
public const int ATTRIBUTE_ID_SPEAKER = 71;
public const int ATTRIBUTE_ID_SOUND_CARD = 38;
public const int ATTRIBUTE_ID_BLUETOOTH = 15;
public const int ATTRIBUTE_ID_WIFI = 16;
public const int ATTRIBUTE_ID_CARD_READER = 48;
public const int ATTRIBUTE_ID_TOUCHPAD = 51;
public const int ATTRIBUTE_ID_INTERNAL_CONNECTORS_PC = 43;
public const int ATTRIBUTE_ID_EXTERNAL_CONNECTORS_PC = 46;
public const int ATTRIBUTE_ID_HEIGH_ADJUSTABLE = 72;
public const int ATTRIBUTE_ID_PIVOT = 73;
public const int ATTRIBUTE_ID_COLOR_DEPTH = 75;
public const int ATTRIBUTE_ID_PIXEL_PITCH = 76;
public const int ATTRIBUTE_ID_LCD_BACKLIGH = 76;
public const int ATTRIBUTE_ID_FEATURES = 299;
public const int ATTRIBUTE_ID_KEYBOARD_AND_MOUSE = 18;
public const int ATTRIBUTE_ID_SOFTWARE = 93;
public const int ATTRIBUTE_ID_ACCESSORY_FREE_WEBCAM = 399;
public const int ATTRIBUTE_ID_EXTENDED_WARRANTY = 104;
/**
* @return array
*/
public static function getTypeChoices(): array
{
return [
self::TYPE_NONE => self::TYPE_NONE,
self::TYPE_CONFIGURATION => self::TYPE_CONFIGURATION,
self::TYPE_ACCESSORY => self::TYPE_ACCESSORY,
self::TYPE_HIDDEN_CONFIGURATION => self::TYPE_HIDDEN_CONFIGURATION,
];
}
/**
* @var string
*
* @Assert\NotNull
*
* @Column(name="type", type="text")
*/
private $type;
/**
* @var string
*
* @Column(name="title", type="text", nullable=true)
*/
private $title;
/**
* @var ArrayCollection
*
* @OneToMany(targetEntity="AttributeOption", mappedBy="attribute", cascade={"persist", "remove"})
* @OrderBy({"sortIndex" = "ASC"})
**/
private $options;
/**
* @var string
*
* @Column(name="help_file", type="string", nullable=true)
*/
private $helpFile = null;
/**
* @var integer
*
* @Assert\NotNull
*
* @Column(name="sort_index", type="integer")
*/
private $sortIndex = -1;
/**
* @var ArrayCollection
*
* @ManyToMany(targetEntity="ProductType", mappedBy="attributes")
**/
private $productTypes;
/**
* @var ArrayCollection
*
* @OneToMany(targetEntity="AttributeMeta", mappedBy="attribute", cascade={"persist", "remove"})
**/
private $metas;
/**
* @var ArrayCollection
*
* @OneToMany(targetEntity="CategoryPageFilterAttribute", mappedBy="attribute")
* @OrderBy({"delta" = "ASC"})
*/
private $categoryPages;
public function __construct()
{
parent::__construct();
$this->options = new ArrayCollection();
$this->productTypes = new ArrayCollection();
$this->metas = new ArrayCollection();
}
/**
* @param TranslatorInterface $translator
*
* @return string
*/
public function getTitle(TranslatorInterface $translator = null)
{
return is_null($translator) ? $this->title : $translator->trans($this->title);
}
/**
* @param string $title
*/
public function setTitle($title)
{
$this->title = $title;
}
/**
* @return ArrayCollection
*/
public function getOptions()
{
return $this->options;
}
/**
* Add AttributeOption
*
* @param AttributeOption $option
*
* @return Attribute
*/
public function addOption($option)
{
if (!$this->options->contains($option)) {
$this->options->add($option);
$option->setAttribute($this);
}
return $this;
}
/**
* Remove AttributeOption
*
* @param AttributeOption $option
*
* @return Attribute
*/
public function removeOption($option)
{
$this->options->removeElement($option);
return $this;
}
/**
* @return string
*/
public function getHelpFile()
{
return $this->helpFile;
}
/**
* @param string $helpFile
*/
public function setHelpFile($helpFile)
{
$this->helpFile = $helpFile;
}
public function getParentOptions()
{
$parentOptions = [];
/**
* @var AttributeOption $option
*/
foreach ($this->options as $option) {
if ($option->hasParent()) {
$parent = $option->getParent();
if (!isset($parentOptions[$parent->getId()])) {
$parentOptions[$parent->getId()] = $parent;
}
}
}
return $parentOptions;
}
/**
* @param TranslatorInterface $translator
* @param string $ext
*
* @return string without php
* @internal param array $translationArray
*/
public function getPageFileName(TranslatorInterface $translator = null, $ext = '.php')
{
$name = preg_replace('/^\W+|\W+$/', '', TranslationHelper::ascii_convert($this->getTitle($translator)));
$name = preg_replace('/\W+/', '-', $name);
return strtolower($name) . $ext;
}
/**
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* @param string $type
*/
public function setType($type)
{
if (!in_array($type, self::getTypeChoices())) {
throw new InvalidArgumentException($type);
}
$this->type = $type;
}
public function isConfigurator()
{
return $this->type == self::TYPE_CONFIGURATION;
}
public function isAccessory()
{
return $this->type == self::TYPE_ACCESSORY;
}
/**
* @return int
*/
public function getSortIndex()
{
return $this->sortIndex;
}
/**
* @param int $sortIndex
*/
public function setSortIndex($sortIndex)
{
$this->sortIndex = $sortIndex;
}
/**
* @return ArrayCollection
*/
public function getProductTypes()
{
return $this->productTypes;
}
public function addProductType($productType)
{
if (!$this->productTypes->contains($productType)) {
$this->productTypes->add($productType);
$productType->addAttribute($this);
}
return $this;
}
/**
* @return ArrayCollection
*/
public function getMetas()
{
return $this->metas;
}
/**
* @param Domain $domain
*
* @return AttributeMeta|null
*/
public function getDomainMeta(Domain $domain)
{
if ($this->getMetas()->count() > 0) {
foreach ($this->getMetas() as $meta) {
if ($meta->getDomain()->getId() == $domain->getId()) {
return $meta;
}
}
}
return null;
}
/**
* @return ArrayCollection
*/
public function getCategoryPages()
{
return $this->categoryPages;
}
/**
* @param ArrayCollection $categoryPages
*/
public function setCategoryPages($categoryPages)
{
$this->categoryPages = $categoryPages;
}
}