src/Document/DspPublisher.php line 199

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\DspPublisherRepository", collection="dsp_publisher")
  7. * @MongoDB\UniqueIndex(keys={"gitId"="asc", "gitParentId"="asc"})
  8. */
  9. class DspPublisher implements JsonSerializable, SyncDocument, SyncChildDocument
  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. * @var string
  24. * @MongoDB\Field(type="string")
  25. */
  26. protected $gitParentId;
  27. /**
  28. * @var string
  29. * @MongoDB\Field(type="string")
  30. */
  31. protected $gitParentPath;
  32. /**
  33. * @var string
  34. * @MongoDB\Field(type="string")
  35. */
  36. protected $gitHash;
  37. /**
  38. * @MongoDB\Field(type="string", nullable=true)
  39. */
  40. private $country;
  41. /**
  42. * @var bool
  43. * @MongoDB\Field(type="bool", nullable=true, name="open_market")
  44. */
  45. private $openMarket;
  46. /**
  47. * @var bool
  48. * @MongoDB\Field(type="bool", nullable=true, name="private_auction")
  49. */
  50. private $privateAuction;
  51. /**
  52. * @return mixed
  53. */
  54. public function getId()
  55. {
  56. return $this->_id;
  57. }
  58. /**
  59. * @return mixed
  60. */
  61. public function getGitId()
  62. {
  63. return $this->gitId;
  64. }
  65. /**
  66. * @param string $id
  67. * @return Inventory
  68. */
  69. public function setGitId(string $id)
  70. {
  71. $this->gitId = $id;
  72. return $this;
  73. }
  74. /**
  75. * @return string
  76. */
  77. public function getGitParentId(): string
  78. {
  79. return $this->gitParentId;
  80. }
  81. /**
  82. * @param string $gitParentId
  83. * @return DspDeal
  84. */
  85. public function setGitParentId(string $gitParentId): self
  86. {
  87. $this->gitParentId = $gitParentId;
  88. return $this;
  89. }
  90. /**
  91. * @return string
  92. */
  93. public function getGitParentPath(): string
  94. {
  95. return $this->gitParentPath;
  96. }
  97. /**
  98. * @param string $gitParentPath
  99. * @return DspDeal
  100. */
  101. public function setGitParentPath(string $gitParentPath): self
  102. {
  103. $this->gitParentPath = $gitParentPath;
  104. return $this;
  105. }
  106. /**
  107. * @return string
  108. */
  109. public function getGitHash(): string
  110. {
  111. return $this->gitHash;
  112. }
  113. /**
  114. * @param string $gitHash
  115. * @return DspDeal
  116. */
  117. public function setGitHash(string $gitHash): self
  118. {
  119. $this->gitHash = $gitHash;
  120. return $this;
  121. }
  122. /**
  123. * @return mixed
  124. */
  125. public function getCountry(): ?string
  126. {
  127. return $this->country;
  128. }
  129. /**
  130. * @param mixed $country
  131. * @return Publisher
  132. */
  133. public function setCountry(string $country = null) : self
  134. {
  135. $this->country = $country;
  136. return $this;
  137. }
  138. /**
  139. * @return bool
  140. */
  141. public function isOpenMarket(): ?bool
  142. {
  143. return $this->openMarket;
  144. }
  145. /**
  146. * @param bool $openMarket
  147. * @return Publisher
  148. */
  149. public function setOpenMarket(bool $openMarket = null): self
  150. {
  151. $this->openMarket = $openMarket;
  152. return $this;
  153. }
  154. /**
  155. * @return bool
  156. */
  157. public function isPrivateAuction(): ?bool
  158. {
  159. return $this->privateAuction;
  160. }
  161. /**
  162. * @param bool $privateAuction
  163. * @return Publisher
  164. */
  165. public function setPrivateAuction(bool $privateAuction = null): self
  166. {
  167. $this->privateAuction = $privateAuction;
  168. return $this;
  169. }
  170. public function jsonSerialize()
  171. {
  172. return [
  173. 'id' => $this->getId(),
  174. 'gitId' => $this->getGitId(),
  175. 'country' => $this->getCountry(),
  176. 'open_market' => $this->isOpenMarket(),
  177. 'private_auction' => $this->isPrivateAuction(),
  178. ];
  179. }
  180. public function validateMutation(Mutation $m) {
  181. return $m->getOldValue()['country'] === $this->getCountry() &&
  182. $m->getOldValue()['open_market'] === $this->isOpenMarket() &&
  183. $m->getOldValue()['private_auction'] === $this->isPrivateAuction();
  184. }
  185. public function gitSerialize()
  186. {
  187. return [
  188. 'country' => $this->getCountry(),
  189. 'open_market' => $this->isOpenMarket(),
  190. 'private_auction' => $this->isPrivateAuction(),
  191. ];
  192. }
  193. public function gitUnserialize(array $gitData): self
  194. {
  195. return $this->setCountry(isset($gitData['country']) ? $gitData['country'] : null)
  196. ->setOpenMarket(isset($gitData['open_market']) ? $gitData['open_market'] : null)
  197. ->setPrivateAuction(isset($gitData['private_auction']) ? $gitData['private_auction'] : null);
  198. }
  199. }