src/Entity/Declaration/Declaration.php line 35

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Declaration;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use ApiPlatform\Core\Annotation\ApiFilter;
  5. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  6. use DateTime;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Gedmo\Mapping\Annotation as Gedmo;
  10. use Gedmo\Timestampable\Traits\Timestampable;
  11. use Roothirsch\CoreBundle\Entity\Traits\TimetrackedTrait;
  12. use Roothirsch\CoreBundle\UserAware\UserAwareInterface;
  13. use Roothirsch\CoreBundle\UserAware\UserAwareTrait;
  14. use Symfony\Component\Serializer\Annotation\Groups;
  15. /**
  16. * @ORM\Entity
  17. * @ORM\Table(name="brunex_declaration_declaration")
  18. * @ApiResource(
  19. * routePrefix="/brunex/declaration",
  20. * normalizationContext={"groups"={"declaration:list"}},
  21. * collectionOperations={
  22. * "duplicate"={"method"="POST", "path"="/declarations/{id}/duplicate", "requirements"={"id"=".+"}},
  23. * "get",
  24. * "post"
  25. * },
  26. * attributes={
  27. * "order"={"createdAt": "DESC"}
  28. * }
  29. * )
  30. * @ApiFilter(OrderFilter::class, properties={"createdAt"}, arguments={"orderParameterName"="order"})
  31. */
  32. class Declaration implements UserAwareInterface
  33. {
  34. use UserAwareTrait;
  35. use TimetrackedTrait;
  36. /**
  37. * @var int
  38. * @ORM\Id
  39. * @ORM\GeneratedValue
  40. * @ORM\Column(type="integer")
  41. * @Groups({"declaration", "declaration:list"})
  42. */
  43. protected $id;
  44. /**
  45. * @var Product
  46. * @ORM\ManyToOne(targetEntity="Product", inversedBy="declarations")
  47. * @Groups({"declaration", "declaration:list"})
  48. */
  49. protected $product;
  50. /**
  51. * @var Collection<Usage>
  52. * @ORM\OneToMany(targetEntity="Usage", mappedBy="declaration", cascade={"persist"})
  53. * _ORM\OrderBy({"name" = "ASC"})
  54. * @Groups({"declaration"})
  55. */
  56. protected $usages;
  57. /**
  58. * @var string
  59. * @ORM\Column(type="text")
  60. * @Groups({"declaration"})
  61. */
  62. protected $company = '';
  63. /**
  64. * @var string
  65. * @ORM\Column(type="text")
  66. * @Groups({"declaration"})
  67. */
  68. protected $name = '';
  69. /**
  70. * @var string
  71. * @ORM\Column(type="text")
  72. * @Groups({"declaration"})
  73. */
  74. protected $street = '';
  75. /**
  76. * @var string
  77. * @ORM\Column(type="integer")
  78. * @Groups({"declaration"})
  79. */
  80. protected $zip;
  81. /**
  82. * @var string
  83. * @ORM\Column(type="text")
  84. * @Groups({"declaration"})
  85. */
  86. protected $city = '';
  87. /**
  88. * @var string
  89. * @ORM\Column(type="text")
  90. * @Groups({"declaration"})
  91. */
  92. protected $phone = '';
  93. /**
  94. * @var string
  95. * @ORM\Column(type="text")
  96. * @Groups({"declaration"})
  97. */
  98. protected $email = '';
  99. /**
  100. * @var string
  101. * @ORM\Column(type="integer")
  102. * @Groups({"declaration", "declaration:list"})
  103. */
  104. protected $kaNumber;
  105. /**
  106. * @var string
  107. * @ORM\Column(type="text")
  108. * @Groups({"declaration", "declaration:list"})
  109. */
  110. protected $customId;
  111. /**
  112. * @var string
  113. * @ORM\Column(type="text")
  114. * @Groups({"declaration", "declaration:list"})
  115. */
  116. protected $position = '';
  117. public function __toString() {
  118. return $this->getKaNummerAndPosition();
  119. }
  120. /**
  121. * @param int $id
  122. */
  123. public function setId($id): void
  124. {
  125. $this->id = $id;
  126. }
  127. /**
  128. * @return int
  129. */
  130. public function getId()
  131. {
  132. return $this->id;
  133. }
  134. /**
  135. * @return Product
  136. */
  137. public function getProduct()
  138. {
  139. return $this->product;
  140. }
  141. /**
  142. * @param Product $product
  143. *
  144. * @return Declaration
  145. */
  146. public function setProduct($product)
  147. {
  148. $this->product = $product;
  149. return $this;
  150. }
  151. /**
  152. * @return Collection
  153. */
  154. public function getUsages()
  155. {
  156. return $this->usages;
  157. }
  158. /**
  159. * @param Collection $usages
  160. *
  161. * @return Declaration
  162. */
  163. public function setUsages($usages)
  164. {
  165. $this->usages = $usages;
  166. return $this;
  167. }
  168. public function addUsage($usage)
  169. {
  170. $this->usages->add($usage);
  171. $usage->setDeclaration($this);
  172. }
  173. /**
  174. * @return string
  175. */
  176. public function getCompany()
  177. {
  178. return $this->company;
  179. }
  180. /**
  181. * @param string $company
  182. *
  183. * @return Declaration
  184. */
  185. public function setCompany($company)
  186. {
  187. $this->company = $company;
  188. return $this;
  189. }
  190. /**
  191. * @return string
  192. */
  193. public function getName()
  194. {
  195. return $this->name;
  196. }
  197. /**
  198. * @param string $name
  199. *
  200. * @return Declaration
  201. */
  202. public function setName($name)
  203. {
  204. $this->name = $name;
  205. return $this;
  206. }
  207. /**
  208. * @return string
  209. */
  210. public function getStreet()
  211. {
  212. return $this->street;
  213. }
  214. /**
  215. * @param string $street
  216. *
  217. * @return Declaration
  218. */
  219. public function setStreet($street)
  220. {
  221. $this->street = $street;
  222. return $this;
  223. }
  224. /**
  225. * @return string
  226. */
  227. public function getZip()
  228. {
  229. return $this->zip;
  230. }
  231. /**
  232. * @param string $zip
  233. *
  234. * @return Declaration
  235. */
  236. public function setZip($zip)
  237. {
  238. $this->zip = $zip;
  239. return $this;
  240. }
  241. /**
  242. * @return string
  243. */
  244. public function getCity()
  245. {
  246. return $this->city;
  247. }
  248. /**
  249. * @param string $city
  250. *
  251. * @return Declaration
  252. */
  253. public function setCity($city)
  254. {
  255. $this->city = $city;
  256. return $this;
  257. }
  258. /**
  259. * @return string
  260. */
  261. public function getPhone()
  262. {
  263. return $this->phone;
  264. }
  265. /**
  266. * @param string $phone
  267. *
  268. * @return Declaration
  269. */
  270. public function setPhone($phone)
  271. {
  272. $this->phone = $phone;
  273. return $this;
  274. }
  275. /**
  276. * @return string
  277. */
  278. public function getEmail()
  279. {
  280. return $this->email;
  281. }
  282. /**
  283. * @param string $email
  284. *
  285. * @return Declaration
  286. */
  287. public function setEmail($email)
  288. {
  289. $this->email = $email;
  290. return $this;
  291. }
  292. /**
  293. * @return string
  294. */
  295. public function getKaNumber()
  296. {
  297. return $this->kaNumber;
  298. }
  299. /**
  300. * @param string $kaNumber
  301. *
  302. * @return Declaration
  303. */
  304. public function setKaNumber($kaNumber)
  305. {
  306. $this->kaNumber = $kaNumber;
  307. return $this;
  308. }
  309. /**
  310. * @return string
  311. */
  312. public function getCustomId()
  313. {
  314. return $this->customId;
  315. }
  316. /**
  317. * @param string $customId
  318. *
  319. * @return Declaration
  320. */
  321. public function setCustomId($customId)
  322. {
  323. $this->customId = $customId;
  324. return $this;
  325. }
  326. /**
  327. * @return string
  328. */
  329. public function getKaNummerAndPosition()
  330. {
  331. return 'KA-' . $this->kaNumber . ' | ' . $this->position;
  332. }
  333. /**
  334. * @return string
  335. */
  336. public function getPosition()
  337. {
  338. return $this->position;
  339. }
  340. /**
  341. * @param string $position
  342. *
  343. * @return Declaration
  344. */
  345. public function setPosition($position)
  346. {
  347. $this->position = $position;
  348. return $this;
  349. }
  350. public function isAvcp1()
  351. {
  352. /** @var Usage $usage */
  353. foreach ($this->getUsages() as $usage) {
  354. if ($usage->getField()->isExap() && $usage->getValue()) {
  355. return true;
  356. }
  357. }
  358. return false;
  359. }
  360. public function __construct()
  361. {
  362. $this->usages = new \Doctrine\Common\Collections\ArrayCollection();
  363. }
  364. }