1<?php 2/** 3 * Copyright since 2007 PrestaShop SA and Contributors 4 * PrestaShop is an International Registered Trademark & Property of PrestaShop SA 5 * 6 * NOTICE OF LICENSE 7 * 8 * This source file is subject to the Open Software License (OSL 3.0) 9 * that is bundled with this package in the file LICENSE.md. 10 * It is also available through the world-wide-web at this URL: 11 * https://opensource.org/licenses/OSL-3.0 12 * If you did not receive a copy of the license and are unable to 13 * obtain it through the world-wide-web, please send an email 14 * to license@prestashop.com so we can send you a copy immediately. 15 * 16 * DISCLAIMER 17 * 18 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer 19 * versions in the future. If you wish to customize PrestaShop for your 20 * needs please refer to https://devdocs.prestashop.com/ for more information. 21 * 22 * @author PrestaShop SA and Contributors <contact@prestashop.com> 23 * @copyright Since 2007 PrestaShop SA and Contributors 24 * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) 25 */ 26 27namespace PrestaShopBundle\Entity; 28 29use Doctrine\Common\Collections\ArrayCollection; 30use Doctrine\Common\Collections\Collection; 31use Doctrine\ORM\Mapping as ORM; 32 33/** 34 * AttributeGroup. 35 * 36 * @ORM\Table() 37 * @ORM\Entity(repositoryClass="PrestaShopBundle\Entity\Repository\AttributeGroupRepository") 38 */ 39class AttributeGroup 40{ 41 /** 42 * @var int 43 * 44 * @ORM\Id 45 * @ORM\Column(name="id_attribute_group", type="integer") 46 * @ORM\GeneratedValue(strategy="AUTO") 47 */ 48 private $id; 49 50 /** 51 * @var bool 52 * 53 * @ORM\Column(name="is_color_group", type="boolean") 54 */ 55 private $isColorGroup; 56 57 /** 58 * @var string 59 * 60 * @ORM\Column(name="group_type", type="string", length=255) 61 */ 62 private $groupType; 63 64 /** 65 * @var int 66 * 67 * @ORM\Column(name="position", type="integer") 68 */ 69 private $position; 70 71 /** 72 * @var ArrayCollection 73 * 74 * @ORM\OneToMany(targetEntity="PrestaShopBundle\Entity\Attribute", mappedBy="attributeGroup", orphanRemoval=true) 75 */ 76 private $attributes; 77 78 /** 79 * @ORM\ManyToMany(targetEntity="PrestaShopBundle\Entity\Shop", cascade={"persist"}) 80 * @ORM\JoinTable( 81 * joinColumns={@ORM\JoinColumn(name="id_attribute_group", referencedColumnName="id_attribute_group")}, 82 * inverseJoinColumns={@ORM\JoinColumn(name="id_shop", referencedColumnName="id_shop", onDelete="CASCADE")} 83 * ) 84 */ 85 private $shops; 86 87 /** 88 * @var ArrayCollection 89 * 90 * @ORM\OneToMany(targetEntity="PrestaShopBundle\Entity\AttributeGroupLang", mappedBy="attributeGroup", orphanRemoval=true) 91 */ 92 private $attributeGroupLangs; 93 94 private $groupTypeAvailable = [ 95 'select', 96 'radio', 97 'color', 98 ]; 99 100 public function __construct() 101 { 102 $this->groupType = 'select'; 103 $this->shops = new ArrayCollection(); 104 $this->attributes = new ArrayCollection(); 105 } 106 107 /** 108 * Get id. 109 * 110 * @return int 111 */ 112 public function getId() 113 { 114 return $this->id; 115 } 116 117 /** 118 * Set isColorGroup. 119 * 120 * @param bool $isColorGroup 121 * 122 * @return AttributeGroup 123 */ 124 public function setIsColorGroup($isColorGroup) 125 { 126 $this->isColorGroup = $isColorGroup; 127 128 return $this; 129 } 130 131 /** 132 * Get isColorGroup. 133 * 134 * @return bool 135 */ 136 public function getIsColorGroup() 137 { 138 return $this->isColorGroup; 139 } 140 141 /** 142 * Set groupType. 143 * 144 * @param string $groupType 145 * 146 * @return AttributeGroup 147 */ 148 public function setGroupType($groupType) 149 { 150 if (!in_array($groupType, $this->groupTypeAvailable)) { 151 throw new \InvalidArgumentException('Invalid group type'); 152 } 153 154 $this->groupType = $groupType; 155 156 return $this; 157 } 158 159 /** 160 * Get groupType. 161 * 162 * @return string 163 */ 164 public function getGroupType() 165 { 166 return $this->groupType; 167 } 168 169 /** 170 * Set position. 171 * 172 * @param int $position 173 * 174 * @return AttributeGroup 175 */ 176 public function setPosition($position) 177 { 178 $this->position = $position; 179 180 return $this; 181 } 182 183 /** 184 * Get position. 185 * 186 * @return int 187 */ 188 public function getPosition() 189 { 190 return $this->position; 191 } 192 193 /** 194 * @return Collection 195 */ 196 public function getAttributes(): Collection 197 { 198 return $this->attributes; 199 } 200 201 /** 202 * Add shop. 203 * 204 * @param \PrestaShopBundle\Entity\Shop $shop 205 * 206 * @return AttributeGroup 207 */ 208 public function addShop(Shop $shop) 209 { 210 $this->shops[] = $shop; 211 212 return $this; 213 } 214 215 /** 216 * Remove shop. 217 * 218 * @param \PrestaShopBundle\Entity\Shop $shop 219 */ 220 public function removeShop(Shop $shop) 221 { 222 $this->shops->removeElement($shop); 223 } 224 225 /** 226 * Get shops. 227 * 228 * @return \Doctrine\Common\Collections\Collection 229 */ 230 public function getShops() 231 { 232 return $this->shops; 233 } 234 235 public function addAttributeGroupLang(AttributeGroupLang $attributeGroupLang) 236 { 237 $this->attributeGroupLangs[] = $attributeGroupLang; 238 239 $attributeGroupLang->setAttributeGroup($this); 240 241 return $this; 242 } 243 244 public function removeAttributeGroupLang(AttributeGroupLang $attributeGroupLang) 245 { 246 $this->attributeGroupLangs->removeElement($attributeGroupLang); 247 } 248 249 public function getAttributeGroupLangs() 250 { 251 return $this->attributeGroupLangs; 252 } 253} 254