Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

107 linhas
2.4KB

  1. <?php
  2. namespace domain\Order\OrderStatusHistory;
  3. use common\components\ActiveRecordCommon;
  4. use domain\Order\Order\Order;
  5. use domain\Order\OrderStatus\OrderStatus;
  6. use domain\User\User\User;
  7. class OrderStatusHistory extends ActiveRecordCommon
  8. {
  9. protected OrderStatus $orderStatusObject;
  10. public function getOrder(): Order
  11. {
  12. return $this->orderRelation;
  13. }
  14. public function setOrder(Order $order): self
  15. {
  16. $this->populateFieldObject('id_order', 'orderRelation', $order);
  17. return $this;
  18. }
  19. public function getUser(): User
  20. {
  21. return $this->userRelation;
  22. }
  23. public function setUser(User $user): self
  24. {
  25. $this->populateFieldObject('id_user', 'userRelation', $user);
  26. return $this;
  27. }
  28. public function getDate(): \DateTime
  29. {
  30. return new \DateTime($this->date);
  31. }
  32. public function setDate(\DateTime $date): self
  33. {
  34. $this->date = $date->format('Y-m-d H:i:s');
  35. return $this;
  36. }
  37. public function getOrderStatusAlias(): string
  38. {
  39. return $this->order_status_alias;
  40. }
  41. public function setOrderStatusAlias(string $orderStatusAlias): self
  42. {
  43. $this->order_status_alias = $orderStatusAlias;
  44. return $this;
  45. }
  46. public function getOrderStatus(): OrderStatus
  47. {
  48. return $this->orderStatusObject;
  49. }
  50. public function setOrderStatus(OrderStatus $orderStatus): self
  51. {
  52. $this->orderStatusObject = $orderStatus;
  53. $this->setOrderStatusAlias($orderStatus->getAlias());
  54. return $this;
  55. }
  56. public static function tableName()
  57. {
  58. return 'order_status_history';
  59. }
  60. public function rules()
  61. {
  62. return [
  63. [['id_order', 'order_status_alias', 'date', 'id_user'], 'required'],
  64. [['id_order', 'id_user'], 'integer'],
  65. [['order_status_alias'], 'string'],
  66. [['date'], 'safe'],
  67. ];
  68. }
  69. public function attributeLabels()
  70. {
  71. return [
  72. 'id' => 'ID',
  73. 'id_order' => 'Commande',
  74. 'order_status_alias' => 'Statut',
  75. 'date' => 'Date',
  76. 'id_user' => 'Utilisateur'
  77. ];
  78. }
  79. /* Relations */
  80. protected function getOrderRelation()
  81. {
  82. return $this->hasOne(Order::class, ['id' => 'id_order']);
  83. }
  84. protected function getUserRelation()
  85. {
  86. return $this->hasOne(User::class, ['id' => 'id_user']);
  87. }
  88. }