You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

184 lines
5.1KB

  1. <?php
  2. namespace domain\PointSale\SharedPointSale;
  3. use common\components\ActiveRecordCommon;
  4. use domain\PointSale\PointSale\PointSale;
  5. use domain\Producer\Producer\Producer;
  6. use domain\User\User\User;
  7. class SharedPointSale extends ActiveRecordCommon
  8. {
  9. public function getPointSale(): PointSale
  10. {
  11. return $this->pointSaleRelation;
  12. }
  13. public function setPointSale(PointSale $pointSale): self
  14. {
  15. $this->populateFieldObject('id_point_sale', 'pointSaleRelation', $pointSale);
  16. return $this;
  17. }
  18. public function getProducerWithSharing(): Producer
  19. {
  20. return $this->producerWithSharingRelation;
  21. }
  22. public function setProducerWithSharing(Producer $producerWithSharing): self
  23. {
  24. $this->populateFieldObject('id_producer_with_sharing', 'producerWithSharingRelation', $producerWithSharing);
  25. return $this;
  26. }
  27. public function getPointSaleWithSharing(): ?PointSale
  28. {
  29. return $this->pointSaleWithSharing;
  30. }
  31. public function setPointSaleWithSharing(PointSale $pointSaleWithSharing = null): self
  32. {
  33. if($pointSaleWithSharing) {
  34. $this->populateFieldObject('id_point_sale_with_sharing', 'pointSaleWithSharingRelation', $pointSaleWithSharing);
  35. }
  36. return $this;
  37. }
  38. public function getStatus(): int
  39. {
  40. return $this->status;
  41. }
  42. public function setStatus(int $status): self
  43. {
  44. $this->status = $status;
  45. return $this;
  46. }
  47. public function getCreatedAt(): \DateTime
  48. {
  49. return new \DateTime($this->created_at);
  50. }
  51. public function setCreatedAt(\DateTime $createdAt): self
  52. {
  53. $this->created_at = $createdAt->format('Y-m-d H:i:s');
  54. return $this;
  55. }
  56. public function getConfirmedAt(): \DateTime
  57. {
  58. return new \DateTime($this->confirmed_at);
  59. }
  60. public function setConfirmedAt(\DateTime $confirmedAt): self
  61. {
  62. $this->confirmed_at = $confirmedAt->format('Y-m-d H:i:s');
  63. return $this;
  64. }
  65. public function getDeclinedAt(): \DateTime
  66. {
  67. return new \DateTime($this->declined_at);
  68. }
  69. public function setDeclinedAt(\DateTime $declinedAt): self
  70. {
  71. $this->declined_at = $declinedAt->format('Y-m-d H:i:s');
  72. return $this;
  73. }
  74. public function getCreatedBy(): User
  75. {
  76. return $this->createdByRelation;
  77. }
  78. public function setCreatedBy(User $createdBy): SharedPointSale
  79. {
  80. $this->populateFieldObject('created_by', 'createdByRelation', $createdBy);
  81. return $this;
  82. }
  83. public function getConfirmedBy(): User
  84. {
  85. return $this->confirmedByRelation;
  86. }
  87. public function setConfirmedBy(User $confirmedBy): SharedPointSale
  88. {
  89. $this->populateFieldObject('confirmed_by', 'confirmedByRelation', $confirmedBy);
  90. return $this;
  91. }
  92. public function getDeclinedBy(): User
  93. {
  94. return $this->declinedByRelation;
  95. }
  96. public function setDeclinedBy(User $declinedBy): SharedPointSale
  97. {
  98. $this->populateFieldObject('declined_by', 'declinedByRelation', $declinedBy);
  99. return $this;
  100. }
  101. public static function tableName()
  102. {
  103. return 'shared_point_sale';
  104. }
  105. public function rules()
  106. {
  107. return [
  108. [['id_point_sale', 'id_producer_with_sharing', 'created_at', 'created_by'], 'required'],
  109. [['id_point_sale', 'id_producer_with_sharing', 'id_point_sale_with_sharing', 'status',
  110. 'created_by', 'confirmed_by', 'declined_by'], 'integer'],
  111. [['created_at', 'confirmed_at', 'declined_at'], 'safe'],
  112. ['id_point_sale', 'exist', 'targetClass' => PointSale::class, 'targetAttribute' => 'id'],
  113. ['id_producer_with_sharing', 'exist', 'targetClass' => Producer::class, 'targetAttribute' => 'id'],
  114. [['created_by', 'confirmed_by', 'declined_by'], 'exist', 'targetClass' => User::class, 'targetAttribute' => 'id'],
  115. ];
  116. }
  117. public function attributeLabels()
  118. {
  119. return [
  120. 'id_point_sale' => 'Point de vente que vous souhaitez partager',
  121. 'id_producer_with_sharing' => 'Producteur avec qui vous souhaitez partager un point de vente',
  122. 'id_point_sale_with_sharing' => 'Point de vente du producteur avec qui vous souhaitez partager ce point de vente',
  123. ];
  124. }
  125. /* Relations */
  126. public function getPointSaleRelation()
  127. {
  128. return $this->hasOne(PointSale::class, ['id' => 'id_point_sale']);
  129. }
  130. public function getProducerWithSharingRelation()
  131. {
  132. return $this->hasOne(Producer::class, ['id' => 'id_producer_with_sharing']);
  133. }
  134. public function getPointSaleWithSharingRelation()
  135. {
  136. return $this->hasOne(PointSale::class, ['id' => 'id_point_sale_with_sharing']);
  137. }
  138. public function getCreatedByRelation()
  139. {
  140. return $this->hasOne(User::class, ['id' => 'created_by']);
  141. }
  142. public function getConfirmedByRelation()
  143. {
  144. return $this->hasOne(User::class, ['id' => 'confirmed_by']);
  145. }
  146. public function getDeclinedByRelation()
  147. {
  148. return $this->hasOne(User::class, ['id' => 'declined_by']);
  149. }
  150. }