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. /**
  140. * @var array
  141. * @ORM\Column(type="json", nullable=true)
  142. * @Groups({"read", "company_write", "company_read"})
  143. */
  144. protected $recipients = [];
  145. public function __construct()
  146. {
  147. $this->employees = new \Doctrine\Common\Collections\ArrayCollection();
  148. $this->groups = new ArrayCollection();
  149. $this->address = new Address();
  150. $this->deliveryAddress = new Address();
  151. $this->deliveryAddress->setActive(false);
  152. $this->billingAddress = new Address();
  153. $this->billingAddress->setActive(false);
  154. $this->attributeValues = new ArrayCollection();
  155. $this->groups = new ArrayCollection();
  156. }
  157. public function __toString()
  158. {
  159. return $this->name;
  160. }
  161. /**
  162. * @return mixed
  163. */
  164. public function getId()
  165. {
  166. return $this->id;
  167. }
  168. /**
  169. * @param mixed $id
  170. */
  171. public function setId($id)
  172. {
  173. $this->id = $id;
  174. }
  175. /**
  176. * @return string
  177. */
  178. public function getName()
  179. {
  180. return $this->name;
  181. }
  182. /**
  183. * @param string $name
  184. */
  185. public function setName($name)
  186. {
  187. $this->name = $name;
  188. }
  189. /**
  190. * @return mixed
  191. */
  192. public function getTaxId()
  193. {
  194. return $this->taxId;
  195. }
  196. /**
  197. * @param mixed $taxId
  198. */
  199. public function setTaxId($taxId)
  200. {
  201. $this->taxId = $taxId;
  202. }
  203. /**
  204. * @return mixed
  205. */
  206. public function getVerified()
  207. {
  208. return $this->verified;
  209. }
  210. /**
  211. * @param mixed $verified
  212. */
  213. public function setVerified($verified)
  214. {
  215. $this->verified = $verified;
  216. }
  217. /**
  218. * @return bool
  219. */
  220. public function getBlocked()
  221. {
  222. return $this->blocked;
  223. }
  224. /**
  225. * @param bool $blocked
  226. */
  227. public function setBlocked($blocked)
  228. {
  229. $this->blocked = (bool) $blocked;
  230. }
  231. /**
  232. * @return string
  233. */
  234. public function getCurrency()
  235. {
  236. return $this->currency;
  237. }
  238. /**
  239. * @param string $currency
  240. */
  241. public function setCurrency($currency)
  242. {
  243. $this->currency = $currency;
  244. }
  245. /**
  246. * @return string
  247. */
  248. public function getLanguage()
  249. {
  250. return $this->language;
  251. }
  252. /**
  253. * @param string $language
  254. */
  255. public function setLanguage($language)
  256. {
  257. $this->language = $language;
  258. }
  259. /**
  260. * @return int
  261. */
  262. public function getDiscount()
  263. {
  264. return $this->discount;
  265. }
  266. /**
  267. * @param int $discount
  268. */
  269. public function setDiscount($discount)
  270. {
  271. $this->discount = $discount;
  272. }
  273. /**
  274. * @return User[]
  275. */
  276. public function getEmployees()
  277. {
  278. return $this->employees;
  279. }
  280. /**
  281. * @param mixed $employees
  282. */
  283. public function setEmployees($employees)
  284. {
  285. $this->employees = $employees;
  286. }
  287. /**
  288. * @return mixed
  289. */
  290. public function getAddress()
  291. {
  292. return $this->address;
  293. }
  294. /**
  295. * @param mixed $address
  296. */
  297. public function setAddress($address)
  298. {
  299. $this->address = $address;
  300. }
  301. /**
  302. * @return Address
  303. */
  304. public function getDeliveryAddress()
  305. {
  306. return $this->deliveryAddress;
  307. }
  308. /**
  309. * @param Address $deliveryAddress
  310. */
  311. public function setDeliveryAddress($deliveryAddress)
  312. {
  313. $this->deliveryAddress = $deliveryAddress;
  314. }
  315. /**
  316. * @return Address
  317. */
  318. public function getBillingAddress()
  319. {
  320. return $this->billingAddress;
  321. }
  322. /**
  323. * @param Address $billingAddress
  324. */
  325. public function setBillingAddress($billingAddress)
  326. {
  327. $this->billingAddress = $billingAddress;
  328. }
  329. /**
  330. * @return mixed
  331. */
  332. public function getLogo()
  333. {
  334. return $this->logo;
  335. }
  336. /**
  337. * @param mixed $logo
  338. */
  339. public function setLogo($logo)
  340. {
  341. $this->logo = $logo;
  342. }
  343. /**
  344. * @return mixed
  345. */
  346. public function getDistributor()
  347. {
  348. return $this->distributor;
  349. }
  350. /**
  351. * @param mixed $distributor
  352. */
  353. public function setDistributor($distributor)
  354. {
  355. $this->distributor = $distributor;
  356. }
  357. /**
  358. * @return mixed
  359. */
  360. public function getErpReference()
  361. {
  362. return $this->erpReference;
  363. }
  364. /**
  365. * @param mixed $erpReference
  366. */
  367. public function setErpReference($erpReference)
  368. {
  369. $this->erpReference = $erpReference;
  370. }
  371. /**
  372. * @return mixed
  373. */
  374. public function getCertification()
  375. {
  376. return $this->certification;
  377. }
  378. /**
  379. * @param mixed $certification
  380. */
  381. public function setCertification($certification): void
  382. {
  383. $this->certification = $certification;
  384. }
  385. /**
  386. * @return Collection|Group[]
  387. */
  388. public function getGroups(): Collection
  389. {
  390. return $this->groups;
  391. }
  392. public function addGroup(Group $group): self
  393. {
  394. if (!$this->groups->contains($group)) {
  395. $this->groups[] = $group;
  396. }
  397. return $this;
  398. }
  399. public function removeGroup(Group $group): self
  400. {
  401. $this->groups->removeElement($group);
  402. return $this;
  403. }
  404. public function newValue(AttributeInterface $attribute): AttributeValueInterface
  405. {
  406. return new CompanyAttributeValue($attribute);
  407. }
  408. public function getAttributeValues(): Collection
  409. {
  410. return $this->attributeValues;
  411. }
  412. public function setAttributeValues(Collection $collection): AttributeValueAwareInterface
  413. {
  414. $this->attributeValues = $collection;
  415. return $this;
  416. }
  417. /**
  418. * @return array
  419. */
  420. public function getRecipients(): array
  421. {
  422. return $this->recipients ?? [];
  423. }
  424. /**
  425. * @param array $recipients
  426. */
  427. public function setRecipients(?array $recipients): self
  428. {
  429. $this->recipients = $recipients ?? [];
  430. return $this;
  431. }
  432. }