vendor/roothirsch/core-bundle/Entity/Company.php line 38

Open in your IDE?
  1. <?php
  2. namespace Roothirsch\CoreBundle\Entity;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiProperty;
  5. use ApiPlatform\Core\Annotation\ApiResource;
  6. use ApiPlatform\Metadata\Get;
  7. use App\State\CompanyStateProcessor;
  8. use Dkd\Populate\PopulateTrait;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Roothirsch\CoreBundle\API\Filter\InArrayFilter;
  13. use Roothirsch\CoreBundle\API\Filter\OrSearchFilter;
  14. use Roothirsch\CoreBundle\Behaviors\Attributable\AttributableInterface;
  15. use Roothirsch\CoreBundle\Behaviors\Attributable\Attribute\AttributeInterface;
  16. use Roothirsch\CoreBundle\Behaviors\Attributable\AttributeValue\AttributeValueAwareInterface;
  17. use Roothirsch\CoreBundle\Behaviors\Attributable\AttributeValue\AttributeValueInterface;
  18. use Roothirsch\CoreBundle\Behaviors\Attributable\MappedSuperclass\AbstractAttributable;
  19. use Roothirsch\CoreBundle\Entity\Company\CompanyAttributeValue;
  20. use Symfony\Component\Serializer\Annotation\Groups;
  21. use Symfony\Component\Serializer\Annotation\MaxDepth;
  22. use Symfony\Component\Validator\Constraints as Assert;
  23. /**
  24. * @ORM\Entity(repositoryClass="Roothirsch\CoreBundle\Repository\CompanyRepository")
  25. * @ORM\Table(name="company")
  26. * @ApiFilter(OrSearchFilter::class, properties={
  27. * "name": "partial",
  28. * "address.city": "partial",
  29. * })
  30. * @ApiFilter(InArrayFilter::class, properties={"groups"})
  31. * @ORM\InheritanceType("SINGLE_TABLE")
  32. * @ORM\DiscriminatorColumn(name="type", type="string")
  33. * @ORM\DiscriminatorMap({"company"= "App\Entity\Company", "core_company"= "Roothirsch\CoreBundle\Entity\Company"})
  34. */
  35. class Company extends AbstractAttributable
  36. {
  37. /**
  38. * @ORM\Id
  39. * @ORM\GeneratedValue
  40. * @ORM\Column(type="integer")
  41. * @Groups({"list", "read", "company_read", "company_simple"})
  42. */
  43. protected $id;
  44. /**
  45. * @var string
  46. * @ORM\Column(type="string")
  47. * @Assert\NotBlank()
  48. * @Groups({"list", "read", "company_write", "company_read", "company_simple"})
  49. */
  50. protected $name;
  51. /**
  52. * @var string
  53. * @ORM\Column(type="string", nullable=true)
  54. * @Groups({"list", "read", "company_write", "company_read", "company_simple"})
  55. */
  56. protected $taxId;
  57. /**
  58. * @var string
  59. * @ORM\Column(type="string")
  60. * @Groups({"list", "read", "company_write", "company_read", "company_simple"})
  61. */
  62. protected $currency = 'eur';
  63. /**
  64. * @ORM\Column(type="string")
  65. * @Groups({"list", "read", "company_write", "company_read", "company_simple"})
  66. */
  67. protected $language = 'de_CH';
  68. /**
  69. * @ORM\Column(type="boolean", options={"default"=false})
  70. * @Groups({"read", "company_write", "company_read", "company_simple"})
  71. */
  72. protected $verified = true;
  73. /**
  74. * @ORM\Column(type="boolean", options={"default"=false})
  75. * @Groups({"read", "company_write", "company_read", "company_simple"})
  76. */
  77. protected $blocked = false;
  78. /**
  79. * @ORM\Column(type="integer", options={"default"=0}, nullable=true)
  80. * @Groups({"read", "company_write", "company_read", "company_simple"})
  81. */
  82. protected $discount = 0;
  83. /**
  84. * @var User[]
  85. * @ORM\OneToMany(targetEntity="User", mappedBy="company")
  86. * @Groups({"company_write", "company_read"})
  87. * @MaxDepth(1)
  88. */
  89. protected $employees;
  90. /**
  91. * @var Address
  92. * @ORM\OneToOne(targetEntity="Address", cascade={"persist"})
  93. * @Groups({"list", "read", "company_write", "company_read", "company_simple"})
  94. */
  95. protected $address;
  96. /**
  97. * @var Address
  98. * @ORM\OneToOne(targetEntity="Address", cascade={"persist"})
  99. * @Groups({"list", "read", "company_write", "company_read"})
  100. */
  101. protected $deliveryAddress;
  102. /**
  103. * @var Address
  104. * @ORM\OneToOne(targetEntity="Address", cascade={"persist"})
  105. * @Groups({"read", "company_write", "company_read"})
  106. */
  107. protected $billingAddress;
  108. /**
  109. * @ORM\Column(type="string", nullable=true)
  110. * @Groups({"list", "read", "write", "company_write", "company_read", "company_simple"})
  111. */
  112. protected $logo;
  113. /**
  114. * @ORM\ManyToOne(targetEntity="App\Entity\Company", cascade={"persist"}, fetch="EAGER")
  115. * @Groups({"list", "read", "company_write", "company_read"})
  116. * @ORM\JoinColumn(onDelete="SET NULL")
  117. * @ApiProperty(readableLink=false, writableLink=false)
  118. */
  119. protected $distributor;
  120. /**
  121. * @Orm\Column(type="string", nullable=true)
  122. * @Groups({"list", "company_write", "company_read", "read", "write", "company_simple"})
  123. */
  124. protected $erpReference;
  125. /**
  126. * @Orm\Column(type="string", nullable=true)
  127. * @Groups({"read", "company_write", "company_read", "company_simple"})
  128. */
  129. protected $certification;
  130. /**
  131. * @ORM\ManyToMany(targetEntity=Group::class, inversedBy="companies")
  132. * @ORM\JoinTable(name="core_company_group")
  133. */
  134. protected $groups;
  135. /**
  136. * @ORM\OneToMany(targetEntity=CompanyAttributeValue::class, mappedBy="company", orphanRemoval=true, cascade={"persist"})
  137. */
  138. protected $attributeValues;
  139. public function __construct()
  140. {
  141. $this->employees = new \Doctrine\Common\Collections\ArrayCollection();
  142. $this->groups = new ArrayCollection();
  143. $this->address = new Address();
  144. $this->deliveryAddress = new Address();
  145. $this->deliveryAddress->setActive(false);
  146. $this->billingAddress = new Address();
  147. $this->billingAddress->setActive(false);
  148. $this->attributeValues = new ArrayCollection();
  149. $this->groups = new ArrayCollection();
  150. }
  151. public function __toString()
  152. {
  153. return $this->name;
  154. }
  155. /**
  156. * @return mixed
  157. */
  158. public function getId()
  159. {
  160. return $this->id;
  161. }
  162. /**
  163. * @param mixed $id
  164. */
  165. public function setId($id)
  166. {
  167. $this->id = $id;
  168. }
  169. /**
  170. * @return string
  171. */
  172. public function getName()
  173. {
  174. return $this->name;
  175. }
  176. /**
  177. * @param string $name
  178. */
  179. public function setName($name)
  180. {
  181. $this->name = $name;
  182. }
  183. /**
  184. * @return mixed
  185. */
  186. public function getTaxId()
  187. {
  188. return $this->taxId;
  189. }
  190. /**
  191. * @param mixed $taxId
  192. */
  193. public function setTaxId($taxId)
  194. {
  195. $this->taxId = $taxId;
  196. }
  197. /**
  198. * @return mixed
  199. */
  200. public function getVerified()
  201. {
  202. return $this->verified;
  203. }
  204. /**
  205. * @param mixed $verified
  206. */
  207. public function setVerified($verified)
  208. {
  209. $this->verified = $verified;
  210. }
  211. /**
  212. * @return bool
  213. */
  214. public function getBlocked()
  215. {
  216. return $this->blocked;
  217. }
  218. /**
  219. * @param bool $blocked
  220. */
  221. public function setBlocked($blocked)
  222. {
  223. $this->blocked = (bool) $blocked;
  224. }
  225. /**
  226. * @return string
  227. */
  228. public function getCurrency()
  229. {
  230. return $this->currency;
  231. }
  232. /**
  233. * @param string $currency
  234. */
  235. public function setCurrency($currency)
  236. {
  237. $this->currency = $currency;
  238. }
  239. /**
  240. * @return string
  241. */
  242. public function getLanguage()
  243. {
  244. return $this->language;
  245. }
  246. /**
  247. * @param string $language
  248. */
  249. public function setLanguage($language)
  250. {
  251. $this->language = $language;
  252. }
  253. /**
  254. * @return int
  255. */
  256. public function getDiscount()
  257. {
  258. return $this->discount;
  259. }
  260. /**
  261. * @param int $discount
  262. */
  263. public function setDiscount($discount)
  264. {
  265. $this->discount = $discount;
  266. }
  267. /**
  268. * @return User[]
  269. */
  270. public function getEmployees()
  271. {
  272. return $this->employees;
  273. }
  274. /**
  275. * @param mixed $employees
  276. */
  277. public function setEmployees($employees)
  278. {
  279. $this->employees = $employees;
  280. }
  281. /**
  282. * @return mixed
  283. */
  284. public function getAddress()
  285. {
  286. return $this->address;
  287. }
  288. /**
  289. * @param mixed $address
  290. */
  291. public function setAddress($address)
  292. {
  293. $this->address = $address;
  294. }
  295. /**
  296. * @return Address
  297. */
  298. public function getDeliveryAddress()
  299. {
  300. return $this->deliveryAddress;
  301. }
  302. /**
  303. * @param Address $deliveryAddress
  304. */
  305. public function setDeliveryAddress($deliveryAddress)
  306. {
  307. $this->deliveryAddress = $deliveryAddress;
  308. }
  309. /**
  310. * @return Address
  311. */
  312. public function getBillingAddress()
  313. {
  314. return $this->billingAddress;
  315. }
  316. /**
  317. * @param Address $billingAddress
  318. */
  319. public function setBillingAddress($billingAddress)
  320. {
  321. $this->billingAddress = $billingAddress;
  322. }
  323. /**
  324. * @return mixed
  325. */
  326. public function getLogo()
  327. {
  328. return $this->logo;
  329. }
  330. /**
  331. * @param mixed $logo
  332. */
  333. public function setLogo($logo)
  334. {
  335. $this->logo = $logo;
  336. }
  337. /**
  338. * @return mixed
  339. */
  340. public function getDistributor()
  341. {
  342. return $this->distributor;
  343. }
  344. /**
  345. * @param mixed $distributor
  346. */
  347. public function setDistributor($distributor)
  348. {
  349. $this->distributor = $distributor;
  350. }
  351. /**
  352. * @return mixed
  353. */
  354. public function getErpReference()
  355. {
  356. return $this->erpReference;
  357. }
  358. /**
  359. * @param mixed $erpReference
  360. */
  361. public function setErpReference($erpReference)
  362. {
  363. $this->erpReference = $erpReference;
  364. }
  365. /**
  366. * @return mixed
  367. */
  368. public function getCertification()
  369. {
  370. return $this->certification;
  371. }
  372. /**
  373. * @param mixed $certification
  374. */
  375. public function setCertification($certification): void
  376. {
  377. $this->certification = $certification;
  378. }
  379. /**
  380. * @return Collection|Group[]
  381. */
  382. public function getGroups(): Collection
  383. {
  384. return $this->groups;
  385. }
  386. public function addGroup(Group $group): self
  387. {
  388. if (!$this->groups->contains($group)) {
  389. $this->groups[] = $group;
  390. }
  391. return $this;
  392. }
  393. public function removeGroup(Group $group): self
  394. {
  395. $this->groups->removeElement($group);
  396. return $this;
  397. }
  398. public function newValue(AttributeInterface $attribute): AttributeValueInterface
  399. {
  400. return new CompanyAttributeValue($attribute);
  401. }
  402. public function getAttributeValues(): Collection
  403. {
  404. return $this->attributeValues;
  405. }
  406. public function setAttributeValues(Collection $collection): AttributeValueAwareInterface
  407. {
  408. $this->attributeValues = $collection;
  409. return $this;
  410. }
  411. }