src/Document/Publisher.php line 127

Open in your IDE?
  1. <?php
  2. namespace App\Document;
  3. use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
  4. use JsonSerializable;
  5. /**
  6. * @MongoDB\Document(repositoryClass="App\Repository\PublisherRepository", collection="publisher")
  7. * @MongoDB\UniqueIndex(keys={"gitId"="asc"})
  8. */
  9. class Publisher implements JsonSerializable, SyncDocument
  10. {
  11. const GIT_FIELDS = ['country', 'open_market', 'private_auction'];
  12. const GIT_ID = 'gitId';
  13. /**
  14. * @MongoDB\Id
  15. */
  16. protected $_id;
  17. /**
  18. * @var string
  19. * @MongoDB\Field(type="string")
  20. */
  21. protected $gitId;
  22. /**
  23. * @MongoDB\Field(type="string", nullable=true)
  24. */
  25. private $country;
  26. /**
  27. * @var bool
  28. * @MongoDB\Field(type="bool", nullable=true, name="open_market")
  29. */
  30. private $openMarket;
  31. /**
  32. * @var bool
  33. * @MongoDB\Field(type="bool", nullable=true, name="private_auction")
  34. */
  35. private $privateAuction;
  36. /**
  37. * @return mixed
  38. */
  39. public function getId()
  40. {
  41. return $this->_id;
  42. }
  43. /**
  44. * @return mixed
  45. */
  46. public function getGitId()
  47. {
  48. return $this->gitId;
  49. }
  50. /**
  51. * @param string $id
  52. * @return Inventory
  53. */
  54. public function setGitId(string $id)
  55. {
  56. $this->gitId = $id;
  57. return $this;
  58. }
  59. /**
  60. * @return mixed
  61. */
  62. public function getCountry(): ?string
  63. {
  64. return $this->country;
  65. }
  66. /**
  67. * @param mixed $country
  68. * @return Publisher
  69. */
  70. public function setCountry(string $country = null) : Publisher
  71. {
  72. $this->country = $country;
  73. return $this;
  74. }
  75. /**
  76. * @return bool
  77. */
  78. public function isOpenMarket(): ?bool
  79. {
  80. return $this->openMarket;
  81. }
  82. /**
  83. * @param bool $openMarket
  84. * @return Publisher
  85. */
  86. public function setOpenMarket(bool $openMarket = null): Publisher
  87. {
  88. $this->openMarket = $openMarket;
  89. return $this;
  90. }
  91. /**
  92. * @return bool
  93. */
  94. public function isPrivateAuction(): ?bool
  95. {
  96. return $this->privateAuction;
  97. }
  98. /**
  99. * @param bool $privateAuction
  100. * @return Publisher
  101. */
  102. public function setPrivateAuction(bool $privateAuction = null): Publisher
  103. {
  104. $this->privateAuction = $privateAuction;
  105. return $this;
  106. }
  107. public function jsonSerialize()
  108. {
  109. return [
  110. 'id' => $this->getId(),
  111. 'gitId' => $this->getGitId(),
  112. 'country' => $this->getCountry(),
  113. 'open_market' => $this->isOpenMarket(),
  114. 'private_auction' => $this->isPrivateAuction(),
  115. ];
  116. }
  117. public function validateMutation(Mutation $m) {
  118. return $m->getOldValue()['country'] === $this->getCountry() &&
  119. $m->getOldValue()['open_market'] === $this->isOpenMarket() &&
  120. $m->getOldValue()['private_auction'] === $this->isPrivateAuction();
  121. }
  122. public function gitSerialize()
  123. {
  124. return [
  125. 'country' => $this->getCountry(),
  126. 'open_market' => $this->isOpenMarket(),
  127. 'private_auction' => $this->isPrivateAuction(),
  128. ];
  129. }
  130. public function gitUnserialize(array $gitData): Publisher
  131. {
  132. return $this->setCountry(isset($gitData['country']) ? $gitData['country'] : null)
  133. ->setOpenMarket(isset($gitData['open_market']) ? $gitData['open_market'] : null)
  134. ->setPrivateAuction(isset($gitData['private_auction']) ? $gitData['private_auction'] : null);
  135. }
  136. }