Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
message.php
1<?php
2
3namespace Bitrix\Mail\Item;
4
5class Message extends Base
6{
7
8 private const FIELD_ID = 'ID';
9 private const FIELD_MSG_ID = 'MSG_ID';
10 private const FIELD_MAILBOX_ID = 'MAILBOX_ID';
11 private const FIELD_SUBJECT = 'SUBJECT';
12 private const FIELD_BODY = 'BODY';
13 private const FIELD_BODY_HTML = 'BODY_HTML';
14 private const FIELD_FROM = 'FIELD_FROM';
15 private const FIELD_TO = 'FIELD_TO';
16 private const FIELD_DATE = 'FIELD_DATE';
17
19 private $id;
21 private $msgId;
23 private $mailboxId;
25 private $subject;
27 private $body;
29 private $bodyHtml;
31 private $from;
33 private $to;
35 private $date;
36
37 protected function __construct(int $id, int $mailboxId)
38 {
39 $this->id = $id;
40 $this->mailboxId = $mailboxId;
41 }
42
43 public static function fromArray(array $array): self
44 {
45 if (!isset($array[self::FIELD_ID], $array[self::FIELD_MAILBOX_ID]))
46 {
47 throw new \Bitrix\Main\SystemException('message field error');
48 }
49
50 $item = new self((int)$array[self::FIELD_ID], (int)$array[self::FIELD_MAILBOX_ID]);
51
52 $item->msgId = $array[self::FIELD_MSG_ID] ?? '';
53 $item->subject = $array[self::FIELD_SUBJECT] ?? '';
54 $item->body = $array[self::FIELD_BODY] ?? '';
55 $item->bodyHtml = $array[self::FIELD_BODY_HTML] ?? '';
56 $item->from = $array[self::FIELD_FROM] ?? '';
57 $item->to = $array[self::FIELD_TO] ?? '';
58 $date = $array[self::FIELD_DATE] ?? '';
59 $item->date = $date instanceof \Bitrix\Main\Type\DateTime
60 ? $date
61 : new \Bitrix\Main\Type\DateTime();
62
63 return $item;
64 }
65
69 public function getId(): int
70 {
71 return $this->id;
72 }
73
74 public function getMsgId(): string
75 {
76 return $this->msgId;
77 }
78
79 public function getMailboxId(): int
80 {
81 return $this->mailboxId;
82 }
83
87 public function getFrom(): string
88 {
89 return $this->from;
90 }
91
95 public function getTo(): string
96 {
97 return $this->to;
98 }
99
103 public function getSubject(): string
104 {
105 return $this->subject;
106 }
107
108 public function getBody(): string
109 {
110 return $this->body;
111 }
112
113 public function getBodyHtml(): string
114 {
115 return $this->bodyHtml;
116 }
117
121 public function getDate(): \Bitrix\Main\Type\DateTime
122 {
123 return $this->date;
124 }
125
126 public function toArray(): array
127 {
128 return [
129 self::FIELD_ID => $this->getId(),
130 self::FIELD_MSG_ID => $this->getMsgId(),
131 self::FIELD_MAILBOX_ID => $this->getMailboxId(),
132 self::FIELD_SUBJECT => $this->getSubject(),
133 self::FIELD_BODY => $this->getBody(),
134 self::FIELD_BODY_HTML => $this->getBodyHtml(),
135 self::FIELD_FROM => $this->getFrom(),
136 self::FIELD_TO => $this->getTo(),
137 self::FIELD_DATE => $this->getDate()->format('Y-m-d H:i:s'),
138 ];
139 }
140
141}
__construct(int $id, int $mailboxId)
Definition message.php:37
static fromArray(array $array)
Definition message.php:43