Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. <?php
  2.  
  3. declare(strict_types=1);
  4.  
  5. namespace App\Import\Tab\Converter;
  6.  
  7. use App\Entity\Dictionary\DocumentType;
  8. use App\Entity\Dictionary\TaskGroup;
  9. use App\Repository\Dictionary\TaskGroupRepository;
  10. use Doctrine\ORM\NonUniqueResultException;
  11.  
  12. class TaskGroupConverter extends ObjectConverter implements ContextAwareInterface
  13. {
  14. use ContextTrait;
  15.  
  16. private const COLUMN_CASE_TYPE = 'caseType';
  17. private const COLUMN_CONTRACT = 'coPartnership';
  18. private const COLUMN_UTILITY_TYPE = 'utilityType';
  19.  
  20. /**
  21. * @param null|string $value
  22. *
  23. * @throws NonUniqueResultException
  24. * @throws \App\Exception\ConvertingFailedException
  25. *
  26. * @return null|object|TaskGroup
  27. */
  28. public function convert(?string $value)
  29. {
  30. if(
  31. $this->context[self::COLUMN_CASE_TYPE]->getName() === DocumentType::NAME_SWITCH_SELLER_INFORMATION ||
  32. $this->context[self::COLUMN_CASE_TYPE]->getName() === DocumentType::NAME_RELEASE
  33. ) {
  34. return parent::convert('IZZ');
  35. }
  36.  
  37. if(
  38. $this->context[self::COLUMN_CASE_TYPE]->getName() === DocumentType::NAME_SWITCH_SELLER_INTERRUPT ||
  39. $this->context[self::COLUMN_CASE_TYPE]->getName() === DocumentType::NAME_INTERRUPT
  40. ) {
  41. return parent::convert('IoW');
  42. }
  43.  
  44. /** @var TaskGroupRepository $repo */
  45. $repo = $this->registry
  46. ->getManagerForClass(TaskGroup::class)
  47. ->getRepository(TaskGroup::class);
  48.  
  49. $taskGroup = $repo->findTaskGroup(
  50. $this->context[self::COLUMN_CONTRACT],
  51. $this->context[self::COLUMN_CASE_TYPE],
  52. $this->context[self::COLUMN_UTILITY_TYPE]
  53. );
  54.  
  55. if ($taskGroup) {
  56. return $taskGroup;
  57. }
  58.  
  59. return parent::convert('INNE');
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement