Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
TaskItem.php
1<?php
2
4
6use Bitrix\Im\Model\EO_LinkTask;
10
12{
13
17 public function __construct($source = null)
18 {
19 $this->initByDefault();
20
21 if (!empty($source))
22 {
23 $this->load($source);
24 }
25 }
26
27 public static function getDataClass(): string
28 {
29 return LinkTaskTable::class;
30 }
31
32 public static function getEntityClassName(): string
33 {
34 return \Bitrix\Im\V2\Entity\Task\TaskItem::class;
35 }
36
37 public static function getRestEntityName(): string
38 {
39 return 'link';
40 }
41
42 public static function initByRow(array $row): self
43 {
44 $entity = \Bitrix\Im\V2\Entity\Task\TaskItem::initByRow($row);
45 $link = new static();
46 $link
47 ->setEntity($entity)
48 ->setId($row['IM_CHAT_ID'])
49 ->setChatId($row['IM_CHAT_CHAT_ID'])
50 ->setMessageId($row['IM_CHAT_MESSAGE_ID'])
51 ->setAuthorId($row['IM_CHAT_AUTHOR_ID'])
52 ->setDateCreate(new DateTime($row['CREATED_DATE']))
53 ;
54
55 return $link;
56 }
57
58 public static function getByEntity(\Bitrix\Im\V2\Entity\Task\TaskItem $entity): ?self
59 {
60 $chatTask = LinkTaskTable::query()
61 ->setSelect(['ID', 'MESSAGE_ID', 'CHAT_ID', 'TASK_ID', 'AUTHOR_ID', 'DATE_CREATE'])
62 ->where('TASK_ID', $entity->getTaskId())
63 ->setLimit(1)
64 ->fetchObject()
65 ;
66
67 if ($chatTask === null)
68 {
69 return null;
70 }
71
72 $taskItem = new static($chatTask);
73 $taskItem->setEntity($entity);
74
75 return $taskItem;
76 }
77
78 public static function getByMessageId(int $messageId): ?self
79 {
80 $chatTask = LinkTaskTable::query()
81 ->setSelect(['ID', 'MESSAGE_ID', 'CHAT_ID', 'TASK_ID', 'AUTHOR_ID', 'DATE_CREATE'])
82 ->where('MESSAGE_ID', $messageId)
83 ->setLimit(1)
84 ->fetchObject()
85 ;
86
87 if ($chatTask === null)
88 {
89 return null;
90 }
91
92 return new static($chatTask);
93 }
94
95 protected static function getEntityIdFieldName(): string
96 {
97 return 'TASK_ID';
98 }
99
103 public function getEntity(): RestEntity
104 {
105 if (isset($this->entity))
106 {
107 return $this->entity;
108 }
109
110 if ($this->getEntityId() !== null)
111 {
112 $entity = \Bitrix\Im\V2\Entity\Task\TaskItem::getById($this->getEntityId());
113 if (isset($entity))
114 {
115 $this->entity = $entity;
116 }
117 }
118
119 return $this->entity;
120 }
121}