src/Documents/BaseDocument.php line 33

Open in your IDE?
  1. <?php
  2. namespace App\Documents;
  3. use App\Entity\DeliveryMan;
  4. use App\Entity\Variables\DelivererDocumentStatus;
  5. use App\Repository\DocumentRepository;
  6. use Doctrine\ORM\EntityManager;
  7. use Symfony\Component\HttpFoundation\Response;
  8. class BaseDocument implements DocumentInterface
  9. {
  10. protected int $documentId;
  11. protected string $control1;
  12. protected string $control2;
  13. protected string $control3;
  14. protected string $validationResult;
  15. protected int $documentType;
  16. protected ?DeliveryMan $deliveryMan;
  17. protected DocumentRepository $documentRepository;
  18. protected DocumentChecker $documentChecker;
  19. protected EntityManager $entityManager;
  20. /**
  21. * __construct
  22. *
  23. * @param EntityManager $entityManager
  24. * @param DocumentRepository $documentRepository
  25. * @param DocumentChecker $documentChecker
  26. * @param DeliveryMan $deliveryMan
  27. * @return void
  28. */
  29. public function __construct(EntityManager $entityManager, DocumentRepository $documentRepository, DocumentChecker $documentChecker, DeliveryMan $deliveryMan = null)
  30. {
  31. $this->entityManager = $entityManager;
  32. $this->documentRepository = $documentRepository;
  33. $this->documentChecker = $documentChecker;
  34. $this->deliveryMan = $deliveryMan;
  35. }
  36. /**
  37. * validate
  38. *
  39. * @return array
  40. */
  41. public function validate(): array
  42. {
  43. return [];
  44. }
  45. /**
  46. * save
  47. *
  48. * @param DelivererDocumentStatus $delivererDocumentStatus
  49. * @return void
  50. */
  51. public function save(DelivererDocumentStatus $delivererDocumentStatus): void
  52. {
  53. $document = $this->documentRepository->find($this->documentId);
  54. if (!$document) {
  55. throw new \Exception('Document not found', Response::HTTP_NOT_FOUND);
  56. }
  57. $document->setDocumentStatus($delivererDocumentStatus);
  58. $this->entityManager->persist($document);
  59. $this->entityManager->flush();
  60. }
  61. /**
  62. * @return int
  63. */
  64. public function getDocumentId(): int
  65. {
  66. return $this->documentId;
  67. }
  68. /**
  69. * @param mixed $documentId
  70. * @return self
  71. */
  72. public function setDocumentId(int $documentId): self
  73. {
  74. $this->documentId = $documentId;
  75. return $this;
  76. }
  77. /**
  78. * @return string
  79. */
  80. public function getControl1()
  81. {
  82. return $this->control1;
  83. }
  84. /**
  85. * @param mixed $control1
  86. * @return self
  87. */
  88. public function setControl1(string $control1): self
  89. {
  90. $this->control1 = $control1;
  91. return $this;
  92. }
  93. /**
  94. * @return string
  95. */
  96. public function getControl2()
  97. {
  98. return $this->control2;
  99. }
  100. /**
  101. * @param mixed $control2
  102. * @return self
  103. */
  104. public function setControl2(string $control2): self
  105. {
  106. $this->control2 = $control2;
  107. return $this;
  108. }
  109. /**
  110. * @return string
  111. */
  112. public function getControl3()
  113. {
  114. return $this->control3;
  115. }
  116. /**
  117. * @param mixed $control3
  118. * @return self
  119. */
  120. public function setControl3(string $control3): self
  121. {
  122. $this->control3 = $control3;
  123. return $this;
  124. }
  125. /**
  126. * @return string
  127. */
  128. public function getValidationResult()
  129. {
  130. return $this->validationResult;
  131. }
  132. /**
  133. * @param mixed $validationResult
  134. * @return self
  135. */
  136. public function setValidationResult(string $validationResult): self
  137. {
  138. $this->validationResult = $validationResult;
  139. return $this;
  140. }
  141. /**
  142. * @return int
  143. */
  144. public function getDocumentType()
  145. {
  146. return $this->documentType;
  147. }
  148. /**
  149. * @param int $documentType
  150. * @return self
  151. */
  152. public function setDocumentType(int $documentType): self
  153. {
  154. $this->documentType = $documentType;
  155. return $this;
  156. }
  157. /**
  158. * @return ?DeliveryMan
  159. */
  160. public function getDeliveryMan()
  161. {
  162. return $this->deliveryMan;
  163. }
  164. /**
  165. * setDeliveryMan
  166. *
  167. * @param ?DeliveryMan $deliveryMan
  168. * @return self
  169. */
  170. public function setDeliveryMan(?DeliveryMan $deliveryMan): self
  171. {
  172. $this->deliveryMan = $deliveryMan;
  173. return $this;
  174. }
  175. /**
  176. * @return DocumentRepository
  177. */
  178. public function getDocumentRepository()
  179. {
  180. return $this->documentRepository;
  181. }
  182. /**
  183. * @param DocumentRepository $documentRepository
  184. * @return self
  185. */
  186. public function setDocumentRepository(DocumentRepository $documentRepository): self
  187. {
  188. $this->documentRepository = $documentRepository;
  189. return $this;
  190. }
  191. /**
  192. * @return EntityManager
  193. */
  194. public function getEntityManager()
  195. {
  196. return $this->entityManager;
  197. }
  198. /**
  199. * @param EntityManager $entityManager
  200. *
  201. * @return self
  202. */
  203. public function setEntityManager(EntityManager $entityManager): self
  204. {
  205. $this->entityManager = $entityManager;
  206. return $this;
  207. }
  208. }