Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

5 месяцев назад
5 месяцев назад
5 месяцев назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace domain\User\UserMessage;
  3. use common\components\ActiveRecordCommon;
  4. use domain\User\User\User;
  5. class UserMessage extends ActiveRecordCommon
  6. {
  7. public static function tableName()
  8. {
  9. return 'user_message';
  10. }
  11. public function rules()
  12. {
  13. return [
  14. [['id_user', 'message', 'created_at', 'created_by'], 'required'],
  15. [['message'], 'string'],
  16. [['id_user', 'created_by'], 'integer'],
  17. [['created_at', 'read_at'], 'safe']
  18. ];
  19. }
  20. public function attributeLabels()
  21. {
  22. return [
  23. 'id_user' => 'Utilisateur',
  24. 'message' => 'Message',
  25. 'created_at' => 'Date de création',
  26. 'created_by' => 'Créé par',
  27. 'read_at', 'Date de lecture'
  28. ];
  29. }
  30. /* Getters / Setters */
  31. public function getId(): ?int
  32. {
  33. return $this->id;
  34. }
  35. public function getUser(): User
  36. {
  37. return $this->userRelation;
  38. }
  39. public function setUser(User $user): self
  40. {
  41. $this->populateFieldObject('id_user', 'userRelation', $user);
  42. return $this;
  43. }
  44. public function getMessage(): string
  45. {
  46. return $this->message;
  47. }
  48. public function setMessage(string $message): self
  49. {
  50. $this->message = $message;
  51. return $this;
  52. }
  53. public function getCreatedAt(): \DateTime
  54. {
  55. return new \DateTime($this->created_at);
  56. }
  57. public function setCreatedAt(\DateTime $createdAt): self
  58. {
  59. $this->created_at = $createdAt->format('Y-m-d H:i:s');
  60. return $this;
  61. }
  62. public function getCreatedBy(): User
  63. {
  64. return $this->createdByRelation;
  65. }
  66. public function setCreatedBy(User $createdBy): self
  67. {
  68. $this->populateFieldObject('created_by', 'createdByRelation', $createdBy);
  69. return $this;
  70. }
  71. public function getReadAt(): ?\DateTime
  72. {
  73. if($this->read_at) {
  74. return new \DateTime($this->read_at);
  75. }
  76. return null;
  77. }
  78. public function setReadAt(\DateTime $readAt): self
  79. {
  80. $this->read_at = $readAt->format('Y-m-d H:i:s');
  81. return $this;
  82. }
  83. /* Relations */
  84. public function getUserRelation()
  85. {
  86. return $this->hasOne(User::class, ['id' => 'id_user']);
  87. }
  88. public function getCreatedByRelation()
  89. {
  90. return $this->hasOne(User::class, ['id' => 'created_by']);
  91. }
  92. }