src/AtechNet/CoreBundle/Entity/Attribute.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\AtechNet\CoreBundle\Entity;
  3. use App\AtechNet\CoreBundle\Helper\SortableEntityInterface;
  4. use App\AtechNet\CoreBundle\Translation\TranslationHelper;
  5. use App\AtechNet\CoreBundle\Translation\TranslatorInterface;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\ORM\Mapping\Column;
  8. use Doctrine\ORM\Mapping\Entity;
  9. use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
  10. use Doctrine\ORM\Mapping\ManyToMany;
  11. use Doctrine\ORM\Mapping\OneToMany;
  12. use Doctrine\ORM\Mapping\OrderBy;
  13. use Doctrine\ORM\Mapping\Table as Table;
  14. use Symfony\Component\Form\Exception\InvalidArgumentException;
  15. use Symfony\Component\Validator\Constraints as Assert;
  16. /**
  17.  * Attribute
  18.  *
  19.  * @Table(name="attributes")
  20.  * @Entity
  21.  * @HasLifecycleCallbacks
  22.  */
  23. class Attribute extends AbstractSignedEntity implements SortableEntityInterface
  24. {
  25.     public const string TYPE_NONE = '';
  26.     public const string TYPE_HIDDEN_CONFIGURATION = 'hidden-conf';
  27.     public const string TYPE_CONFIGURATION = 'conf';
  28.     public const string TYPE_ACCESSORY = 'acc';
  29.     public const int ATTRIBUTE_ID_SSD = 5;
  30.     public const int ATTRIBUTE_ID_SSD_18 = 390;
  31.     public const int ATTRIBUTE_ID_HDD_25 = 8;
  32.     public const int ATTRIBUTE_ID_HDD_35 = 9;
  33.     public const int ATTRIBUTE_ID_ACCESSORY_SSD = 47;
  34.     public const int ATTRIBUTE_ID_ACCESSORY_OS = 21;
  35.     public const int ATTRIBUTE_ID_ACCESSORY_SOFTWARE_PACKAGE = 22;
  36.     public const int ATTRIBUTE_ID_ACCESSORY_ANTIVIRUS_SOFTWARE = 23;
  37.     public const int ATTRIBUTE_ID_ACCESSORY_OFFICE_365 = 24;
  38.     public const int ATTRIBUTE_ID_ACCESSORY_MOUSE = 27;
  39.     public const int ATTRIBUTE_ID_ACCESSORY_HEADSET = 149;
  40.     public const int ATTRIBUTE_ID_ACCESSORY_NB_RAM_DDR2 = 29;
  41.     public const int ATTRIBUTE_ID_ACCESSORY_NB_RAM_DDR3 = 31;
  42.     public const int ATTRIBUTE_ID_ACCESSORY_NB_RAM_DDR4 = 153;
  43.     public const int ATTRIBUTE_ID_ACCESSORY_PC_RAM_DDR2 = 28;
  44.     public const int ATTRIBUTE_ID_ACCESSORY_PC_RAM_DDR3 = 30;
  45.     public const int ATTRIBUTE_ID_ACCESSORY_PC_RAM_DDR4 = 147;
  46.     public const int ATTRIBUTE_ID_ACCESSORY_AC_ADAPTER = 150;
  47.     public const int ATTRIBUTE_ID_ACCESSORY_AC_ADAPTER_CONF = 245;
  48.     public const int ATTRIBUTE_ID_ACCESSORY_KEYBOARD_REPRINT = 184;
  49.     public const int ATTRIBUTE_ID_ACCESSORY_CABLE = 123;
  50.     public const int ATTRIBUTE_ID_ACCESSORY_DOCKING_STATION = 392;
  51.     public const int ATTRIBUTE_ID_OPERATING_SYSTEM = 41;
  52.     public const int ATTRIBUTE_ID_WEBCAM = 19;
  53.     public const int ATTRIBUTE_ID_BATTERY = 96;
  54.     public const int ATTRIBUTE_ID_NEW_BATTERY = 401;
  55.     public const int ATTRIBUTE_ID_NOTEBOOK_BATTERY = 402;
  56.     public const int ATTRIBUTE_ID_QUALITY = 101;
  57.     public const int ATTRIBUTE_ID_SAS_HDD25 = 314;
  58.     public const int ATTRIBUTE_ID_HDD18 = 166;
  59.     public const int ATTRIBUTE_ID_SSHD25 = 6;
  60.     public const int ATTRIBUTE_ID_SSHD35 = 7;
  61.     public const int ATTRIBUTE_ID_SCREEN_SIZE = 12;
  62.     public const int ATTRIBUTE_ID_MAXIMUM_RESOLUTION = 63;
  63.     public const int ATTRIBUTE_ID_RESPONSE_TIME = 66;
  64.     public const int ATTRIBUTE_ID_DISPLAY_TECHNOLOGY = 118;
  65.     public const int ATTRIBUTE_ID_ASPECT_RATIO = 74;
  66.     public const int ATTRIBUTE_ID_CPU_NB = 33;
  67.     public const int ATTRIBUTE_ID_CPU_NB_FAMILY = 142;
  68.     public const int ATTRIBUTE_ID_RAM_NB = 4;
  69.     public const int ATTRIBUTE_ID_CPU_PC = 32;
  70.     public const int ATTRIBUTE_ID_RAM_PC = 3;
  71.     public const int ATTRIBUTE_ID_VGA = 25;
  72.     public const int ATTRIBUTE_ID_MAX_SPEED = 321;
  73.     public const int ATTRIBUTE_ID_MAX_RANGE = 322;
  74.     public const int ATTRIBUTE_ID_POWER = 325;
  75.     public const int ATTRIBUTE_ID_PRINTING_TECHNOLOGY = 87;
  76.     public const int ATTRIBUTE_ID_PRINTING_COLOR = 88;
  77.     public const int ATTRIBUTE_ID_DUPLEX = 81;
  78.     public const int ATTRIBUTE_ID_PORTS = 85;
  79.     public const int ATTRIBUTE_ID_PRINTING_SPEED = 80;
  80.     public const int ATTRIBUTE_ID_DISPLAY = 170;
  81.     public const int ATTRIBUTE_ID_CPU_PHONE = 114;
  82.     public const int ATTRIBUTE_ID_RAM = 171;
  83.     public const int ATTRIBUTE_ID_NOTEBOOK_SKIN = 320;
  84.     public const int ATTRIBUTE_ID_CPU_GENERATION = 174;
  85.     public const int ATTRIBUTE_ID_FORM = 1;
  86.     public const int ATTRIBUTE_ID_EXTERNAL_CONNECTORS = 45;
  87.     public const int ATTRIBUTE_ID_GRAPHIC_INPUTS = 68;
  88.     public const int ATTRIBUTE_ID_VIEW_ANGLES = 67;
  89.     public const int ATTRIBUTE_ID_CONTRAST = 65;
  90.     public const int ATTRIBUTE_ID_BRIGHTNESS = 64;
  91.     public const int ATTRIBUTE_ID_CONF_OS = 41;
  92.     public const int ATTRIBUTE_ID_PROJECTOR_REMOTE = 218;
  93.     public const int ATTRIBUTE_ID_LUMEN = 182;
  94.     public const int ATTRIBUTE_ID_CPU_PC_FAMILY = 141;
  95.     public const int ATTRIBUTE_ID_CLOCKSPEED = 125;
  96.     public const int ATTRIBUTE_ID_CPU_SOCKET = 128;
  97.     public const int ATTRIBUTE_ID_MEMORY_TYPE = 204;
  98.     public const int ATTRIBUTE_ID_MEMORY_SIZE = 144;
  99.     public const int ATTRIBUTE_ID_MEMORY_FREQUENCY = 206;
  100.     public const int ATTRIBUTE_ID_TOUCH_SCREEN = 139;
  101.     public const int ATTRIBUTE_ID_MEMORY = 79;
  102.     public const int ATTRIBUTE_ID_CONNECTORS = 69;
  103.     public const int ATTRIBUTE_ID_DOCKING_STATION_POWER_INPUT = 223;
  104.     public const int ATTRIBUTE_ID_COLOR = 160;
  105.     public const int ATTRIBUTE_ID_NOTEBOOK_BAG_SIZE = 159;
  106.     public const int ATTRIBUTE_ID_CONF_NOTEBOOK_SKIN = 362;
  107.     public const int ATTRIBUTE_ID_RAM_PC_TYPE = 383;
  108.     public const int ATTRIBUTE_ID_RAM_NB_TYPE = 382;
  109.     public const int ATTRIBUTE_ID_RAM_SIZE = 384;
  110.     public const int ATTRIBUTE_ID_CPU_SERVER = 35;
  111.     public const int ATTRIBUTE_ID_CPU_TABLET = 36;
  112.     public const int ATTRIBUTE_ID_ODD_NB = 11;
  113.     public const int ATTRIBUTE_ID_CONFIG_KEYBOARD_REPRINT = 396;
  114.     public const int ATTRIBUTE_ID_KEYBOARD_LANGUAGE = 94;
  115.     public const int ATTRIBUTE_ID_NUMPAD = 17;
  116.     public const int ATTRIBUTE_ID_OPTICAL_DRIVER = 11;
  117.     public const int ATTRIBUTE_ID_YEAR_OF_PRODUCTION = 396;
  118.     public const int ATTRIBUTE_ID_CPU_MARK = 397;
  119.     public const int ATTRIBUTE_ID_POWER_CABLE = 137;
  120.     public const int ATTRIBUTE_ID_SCREEN_REFRESH_RATE = 176;
  121.     public const int ATTRIBUTE_ID_VESA = 70;
  122.     public const int ATTRIBUTE_ID_SPEAKER = 71;
  123.     public const int ATTRIBUTE_ID_SOUND_CARD = 38;
  124.     public const int ATTRIBUTE_ID_BLUETOOTH = 15;
  125.     public const int ATTRIBUTE_ID_WIFI = 16;
  126.     public const int ATTRIBUTE_ID_CARD_READER = 48;
  127.     public const int ATTRIBUTE_ID_TOUCHPAD = 51;
  128.     public const int ATTRIBUTE_ID_INTERNAL_CONNECTORS_PC = 43;
  129.     public const int ATTRIBUTE_ID_EXTERNAL_CONNECTORS_PC = 46;
  130.     public const int ATTRIBUTE_ID_HEIGH_ADJUSTABLE = 72;
  131.     public const int ATTRIBUTE_ID_PIVOT = 73;
  132.     public const int ATTRIBUTE_ID_COLOR_DEPTH = 75;
  133.     public const int ATTRIBUTE_ID_PIXEL_PITCH = 76;
  134.     public const int ATTRIBUTE_ID_LCD_BACKLIGH = 76;
  135.     public const int ATTRIBUTE_ID_FEATURES = 299;
  136.     public const int ATTRIBUTE_ID_KEYBOARD_AND_MOUSE = 18;
  137.     public const int ATTRIBUTE_ID_SOFTWARE = 93;
  138.     public const int ATTRIBUTE_ID_ACCESSORY_FREE_WEBCAM = 399;
  139.     public const int ATTRIBUTE_ID_EXTENDED_WARRANTY = 104;
  140.     /**
  141.      * @return array
  142.      */
  143.     public static function getTypeChoices(): array
  144.     {
  145.         return [
  146.             self::TYPE_NONE                 => self::TYPE_NONE,
  147.             self::TYPE_CONFIGURATION        => self::TYPE_CONFIGURATION,
  148.             self::TYPE_ACCESSORY            => self::TYPE_ACCESSORY,
  149.             self::TYPE_HIDDEN_CONFIGURATION => self::TYPE_HIDDEN_CONFIGURATION,
  150.         ];
  151.     }
  152.     /**
  153.      * @var string
  154.      *
  155.      * @Assert\NotNull
  156.      *
  157.      * @Column(name="type", type="text")
  158.      */
  159.     private $type;
  160.     /**
  161.      * @var string
  162.      *
  163.      * @Column(name="title", type="text", nullable=true)
  164.      */
  165.     private $title;
  166.     /**
  167.      * @var ArrayCollection
  168.      *
  169.      * @OneToMany(targetEntity="AttributeOption", mappedBy="attribute", cascade={"persist", "remove"})
  170.      * @OrderBy({"sortIndex" = "ASC"})
  171.      **/
  172.     private $options;
  173.     /**
  174.      * @var string
  175.      *
  176.      * @Column(name="help_file", type="string", nullable=true)
  177.      */
  178.     private $helpFile = null;
  179.     /**
  180.      * @var integer
  181.      *
  182.      * @Assert\NotNull
  183.      *
  184.      * @Column(name="sort_index", type="integer")
  185.      */
  186.     private $sortIndex = -1;
  187.     /**
  188.      * @var ArrayCollection
  189.      *
  190.      * @ManyToMany(targetEntity="ProductType", mappedBy="attributes")
  191.      **/
  192.     private $productTypes;
  193.     /**
  194.      * @var ArrayCollection
  195.      *
  196.      * @OneToMany(targetEntity="AttributeMeta", mappedBy="attribute", cascade={"persist", "remove"})
  197.      **/
  198.     private $metas;
  199.     /**
  200.      * @var ArrayCollection
  201.      *
  202.      * @OneToMany(targetEntity="CategoryPageFilterAttribute", mappedBy="attribute")
  203.      * @OrderBy({"delta" = "ASC"})
  204.      */
  205.     private $categoryPages;
  206.     public function __construct()
  207.     {
  208.         parent::__construct();
  209.         $this->options = new ArrayCollection();
  210.         $this->productTypes = new ArrayCollection();
  211.         $this->metas = new ArrayCollection();
  212.     }
  213.     /**
  214.      * @param TranslatorInterface $translator
  215.      *
  216.      * @return string
  217.      */
  218.     public function getTitle(TranslatorInterface $translator = null)
  219.     {
  220.         return is_null($translator) ? $this->title : $translator->trans($this->title);
  221.     }
  222.     /**
  223.      * @param string $title
  224.      */
  225.     public function setTitle($title)
  226.     {
  227.         $this->title = $title;
  228.     }
  229.     /**
  230.      * @return ArrayCollection
  231.      */
  232.     public function getOptions()
  233.     {
  234.         return $this->options;
  235.     }
  236.     /**
  237.      * Add AttributeOption
  238.      *
  239.      * @param AttributeOption $option
  240.      *
  241.      * @return Attribute
  242.      */
  243.     public function addOption($option)
  244.     {
  245.         if (!$this->options->contains($option)) {
  246.             $this->options->add($option);
  247.             $option->setAttribute($this);
  248.         }
  249.         return $this;
  250.     }
  251.     /**
  252.      * Remove AttributeOption
  253.      *
  254.      * @param AttributeOption $option
  255.      *
  256.      * @return Attribute
  257.      */
  258.     public function removeOption($option)
  259.     {
  260.         $this->options->removeElement($option);
  261.         return $this;
  262.     }
  263.     /**
  264.      * @return string
  265.      */
  266.     public function getHelpFile()
  267.     {
  268.         return $this->helpFile;
  269.     }
  270.     /**
  271.      * @param string $helpFile
  272.      */
  273.     public function setHelpFile($helpFile)
  274.     {
  275.         $this->helpFile = $helpFile;
  276.     }
  277.     public function getParentOptions()
  278.     {
  279.         $parentOptions = [];
  280.         /**
  281.          * @var AttributeOption $option
  282.          */
  283.         foreach ($this->options as $option) {
  284.             if ($option->hasParent()) {
  285.                 $parent = $option->getParent();
  286.                 if (!isset($parentOptions[$parent->getId()])) {
  287.                     $parentOptions[$parent->getId()] = $parent;
  288.                 }
  289.             }
  290.         }
  291.         return $parentOptions;
  292.     }
  293.     /**
  294.      * @param TranslatorInterface $translator
  295.      * @param string $ext
  296.      *
  297.      * @return string without php
  298.      * @internal param array $translationArray
  299.      */
  300.     public function getPageFileName(TranslatorInterface $translator = null, $ext = '.php')
  301.     {
  302.         $name = preg_replace('/^\W+|\W+$/', '', TranslationHelper::ascii_convert($this->getTitle($translator)));
  303.         $name = preg_replace('/\W+/', '-', $name);
  304.         return strtolower($name) . $ext;
  305.     }
  306.     /**
  307.      * @return string
  308.      */
  309.     public function getType()
  310.     {
  311.         return $this->type;
  312.     }
  313.     /**
  314.      * @param string $type
  315.      */
  316.     public function setType($type)
  317.     {
  318.         if (!in_array($type, self::getTypeChoices())) {
  319.             throw new InvalidArgumentException($type);
  320.         }
  321.         $this->type = $type;
  322.     }
  323.     public function isConfigurator()
  324.     {
  325.         return $this->type == self::TYPE_CONFIGURATION;
  326.     }
  327.     public function isAccessory()
  328.     {
  329.         return $this->type == self::TYPE_ACCESSORY;
  330.     }
  331.     /**
  332.      * @return int
  333.      */
  334.     public function getSortIndex()
  335.     {
  336.         return $this->sortIndex;
  337.     }
  338.     /**
  339.      * @param int $sortIndex
  340.      */
  341.     public function setSortIndex($sortIndex)
  342.     {
  343.         $this->sortIndex = $sortIndex;
  344.     }
  345.     /**
  346.      * @return ArrayCollection
  347.      */
  348.     public function getProductTypes()
  349.     {
  350.         return $this->productTypes;
  351.     }
  352.     public function addProductType($productType)
  353.     {
  354.         if (!$this->productTypes->contains($productType)) {
  355.             $this->productTypes->add($productType);
  356.             $productType->addAttribute($this);
  357.         }
  358.         return $this;
  359.     }
  360.     /**
  361.      * @return ArrayCollection
  362.      */
  363.     public function getMetas()
  364.     {
  365.         return $this->metas;
  366.     }
  367.     /**
  368.      * @param Domain $domain
  369.      *
  370.      * @return AttributeMeta|null
  371.      */
  372.     public function getDomainMeta(Domain $domain)
  373.     {
  374.         if ($this->getMetas()->count() > 0) {
  375.             foreach ($this->getMetas() as $meta) {
  376.                 if ($meta->getDomain()->getId() == $domain->getId()) {
  377.                     return $meta;
  378.                 }
  379.             }
  380.         }
  381.         return null;
  382.     }
  383.     /**
  384.      * @return ArrayCollection
  385.      */
  386.     public function getCategoryPages()
  387.     {
  388.         return $this->categoryPages;
  389.     }
  390.     /**
  391.      * @param ArrayCollection $categoryPages
  392.      */
  393.     public function setCategoryPages($categoryPages)
  394.     {
  395.         $this->categoryPages = $categoryPages;
  396.     }
  397. }