EquipmentComposition.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. namespace AppBundle\Entity\Product;
  3. use AppBundle\Annotation\ExportSplitFields;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Dunglas\ApiBundle\Annotation\Iri;
  6. use Symfony\Component\Serializer\Annotation\Groups;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. use AppBundle\Entity\Traits\TimestampableEntity;
  9. use AppBundle\Entity\Traits\CreatorUpdaterEntity;
  10. /**
  11. * Equipment composé d'autres Equipments
  12. * Fais le lien entre un équipement parent et des équipements enfants
  13. *
  14. * @Iri("http://schema.org/EquipmentComposition")
  15. */
  16. #[ORM\Entity]
  17. class EquipmentComposition
  18. {
  19. use TimestampableEntity;
  20. use CreatorUpdaterEntity;
  21. /**
  22. * @var int
  23. */
  24. #[ORM\Column(type: 'integer')]
  25. #[ORM\Id]
  26. #[ORM\GeneratedValue(strategy: 'AUTO')]
  27. #[Groups(['equipmentcomposition', 'equipment_list', 'equipment_details'])]
  28. private $id;
  29. /**
  30. * @var Equipment
  31. */
  32. #[ORM\ManyToOne(targetEntity: 'Equipment', inversedBy: 'equipmentComposition')]
  33. #[ORM\JoinColumn(nullable: false)]
  34. #[Assert\NotNull]
  35. #[Groups(['equipmentcomposition'])]
  36. private $parent;
  37. /**
  38. * @var Equipment
  39. */
  40. #[ORM\ManyToOne(targetEntity: 'Equipment')]
  41. #[ORM\JoinColumn(nullable: false)]
  42. #[Assert\NotNull]
  43. #[Groups(['equipmentcomposition', 'equipment_list_equipmentcomposition', 'equipment_details_equipmentcomposition'])]
  44. private $children;
  45. /**
  46. * @var int
  47. */
  48. #[ORM\Column(type: 'integer')]
  49. #[Assert\Type(type: 'integer', message: 'invalid-integer')]
  50. #[Assert\NotNull]
  51. #[Groups(['equipmentcomposition', 'equipment_details_equipmentcomposition'])]
  52. private $quantity;
  53. /**
  54. * @var string
  55. * @ExportSplitFields({"children.equipmentList.familly","children.brand","children.model"})
  56. */
  57. #[Groups(['template'])]
  58. private $fullLabelTemplate;
  59. /**
  60. * Sets id.
  61. *
  62. * @param int $id
  63. *
  64. * @return $this
  65. */
  66. public function setId($id)
  67. {
  68. $this->id = $id;
  69. return $this;
  70. }
  71. /**
  72. * Gets id.
  73. *
  74. * @return int
  75. */
  76. public function getId()
  77. {
  78. return $this->id;
  79. }
  80. /**
  81. * Sets parent.
  82. *
  83. * @param Equipment $parent
  84. *
  85. * @return $this
  86. */
  87. public function setParent(Equipment $parent)
  88. {
  89. $this->parent = $parent;
  90. return $this;
  91. }
  92. /**
  93. * Gets parent.
  94. *
  95. * @return Equipment
  96. */
  97. public function getParent()
  98. {
  99. return $this->parent;
  100. }
  101. /**
  102. * Sets children.
  103. *
  104. * @param Equipment $children
  105. *
  106. * @return $this
  107. */
  108. public function setChildren(Equipment $children)
  109. {
  110. $this->children = $children;
  111. return $this;
  112. }
  113. /**
  114. * Gets children.
  115. *
  116. * @return Equipment
  117. */
  118. public function getChildren()
  119. {
  120. return $this->children;
  121. }
  122. /**
  123. * Sets quantity.
  124. *
  125. * @param int $quantity
  126. *
  127. * @return $this
  128. */
  129. public function setQuantity($quantity)
  130. {
  131. $this->quantity = intval($quantity);
  132. return $this;
  133. }
  134. /**
  135. * Gets quantity.
  136. *
  137. * @return int
  138. */
  139. public function getQuantity()
  140. {
  141. return $this->quantity;
  142. }
  143. /**
  144. * Gets full label.
  145. *
  146. * @return array
  147. */
  148. public function getFullLabelTemplate()
  149. {
  150. $children = $this->getChildren();
  151. if(empty($children))
  152. return [];
  153. return [
  154. ['value' => $children->getEquipmentList() ? $children->getEquipmentList()->getFamilly() : '', 'translate' => true],
  155. $children->getBrand(),
  156. $children->getModel()
  157. ];
  158. }
  159. }