Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
createtask.php
1<?php
2
4
8
9Loc::loadMessages(__FILE__);
10
12{
13 public const TYPE = 'CREATETASK';
14 public const POST_TEXT = 'commentAuxCreateTask';
15
16 public function getText(): string
17 {
18 static $userPage = null;
19 static $parser = null;
20
21 $result = '';
24
25 $siteId = (!empty($options['siteId']) ? $options['siteId'] : SITE_ID);
26
27 if (
28 !isset($params['sourcetype'], $params['sourceid'], $params['taskid'])
29 || (int)$params['sourceid'] <= 0
30 || (int)$params['taskid'] <= 0
31 || !in_array($params['sourcetype'], $this->getSourceTypeList(), true)
32 )
33 {
34 return $result;
35 }
36
37 if ($provider = $this->getLivefeedProvider())
38 {
39 $options['suffix'] = $provider->getSuffix($options['suffix']);
40 }
41
42 if ($userPage === null)
43 {
44 $userPage = Option::get(
45 'socialnetwork',
46 'user_page',
47 SITE_DIR . 'company/personal/',
48 $siteId
49 ) . 'user/#user_id#/';
50 }
51
52 if ($task = $this->getTask($params['taskid'], false))
53 {
54 $taskPath = (
55 (!isset($options['cache']) || !$options['cache'])
56 && (!isset($options['im']) || !$options['im'])
57 && (!isset($options['bPublicPage']) || !$options['bPublicPage'])
58 ? str_replace(array("#user_id#", "#USER_ID#"), $task['RESPONSIBLE_ID'], $userPage).'tasks/task/view/'.$task['ID'].'/'
59 : ''
60 );
61
62 $taskTitle = $task['TITLE'];
63 }
64 else
65 {
66 $taskPath = '';
67 $taskTitle = Loc::getMessage('SONET_COMMENTAUX_CREATETASK_NOT_FOUND');
68 }
69
70 if (in_array($params['sourcetype'], $this->getCommentTypeList(), true))
71 {
72 $sourceData = $this->getSourceCommentData([
73 'userPage' => $userPage,
74 ]);
75
76 $suffix = (
77 $options['suffix']
78 ? '_' . $options['suffix']
79 : (!empty($sourceData['suffix']) ? '_' . $sourceData['suffix'] : '')
80 );
81
82 $result = Loc::getMessage('SONET_COMMENTAUX_CREATETASK_COMMENT_' . $params['sourcetype'] . $suffix, [
83 '#TASK_NAME#' => (!empty($taskPath) ? '[URL=' . $taskPath . ']' . $taskTitle . '[/URL]' : $taskTitle),
84 '#A_BEGIN#' => (!empty($sourceData['path']) ? '[URL=' . $sourceData['path'] . ']' : ''),
85 '#A_END#' => (!empty($sourceData['path']) ? '[/URL]' : '')
86 ]);
87 }
88 elseif (in_array($params['sourcetype'], $this->getPostTypeList(), true))
89 {
90 $suffix = ($options['suffix'] ?? ($params['sourcetype'] === static::SOURCE_TYPE_BLOG_POST ? '2' : ''));
91
92 $result = Loc::getMessage('SONET_COMMENTAUX_CREATETASK_POST_' . $params['sourcetype'].(!empty($suffix) ? '_' . $suffix : ''), [
93 '#TASK_NAME#' => (!empty($taskPath) ? '[URL='.$taskPath.']'.$taskTitle.'[/URL]' : $taskTitle),
94 ]);
95 }
96
97 if (!empty($result))
98 {
99 if ($parser === null)
100 {
101 $parser = new \CTextParser();
102 $parser->allow = [ 'HTML' => 'N', 'ANCHOR' => 'Y' ];
103 }
104 $result = $parser->convertText($result);
105 }
106
107 return $result;
108 }
109
110 public function checkRecalcNeeded($fields, $params): bool
111 {
112 $result = false;
113
114 if (
115 !empty($params['bPublicPage'])
116 && $params['bPublicPage']
117 )
118 {
119 $result = true;
120 }
121 else
122 {
123 $handlerParams = $this->getParamsFromFields($fields);
124
125 if (
126 !empty($handlerParams)
127 && !empty($handlerParams['taskid'])
128 && (int)$handlerParams['taskid'] > 0
129 && ($this->getTask((int)$handlerParams['taskid']))
130 )
131 {
132 $result = true;
133 }
134 }
135
136 return $result;
137 }
138
139 public function getTask($taskId, $checkPermissions = true)
140 {
141 static $cache = array(
142 'Y' => [],
143 'N' => [],
144 );
145
146 $result = false;
147 $permissionCacheKey = ($checkPermissions ? 'Y' : 'N');
148
149 if (isset($cache[$permissionCacheKey][$taskId]))
150 {
151 $result = $cache[$permissionCacheKey][$taskId];
152 }
153 elseif (Loader::includeModule('tasks'))
154 {
155 $res = \CTasks::getByID((int)$taskId, $checkPermissions);
156 if ($task = $res->fetch())
157 {
158 $result = $cache[$permissionCacheKey][$taskId] = $task;
159 }
160 elseif(!$checkPermissions)
161 {
162 $result = $cache[$permissionCacheKey][$taskId] = false;
163 }
164 }
165
166 return $result;
167 }
168
169 protected function getForumType(): string
170 {
171 return \Bitrix\Forum\Comments\Service\Manager::TYPE_TASK_CREATED;
172 }
173
174 protected function getForumServiceData(array $commentData = [])
175 {
176 return (!empty($commentData['SERVICE_DATA']) ? $commentData['SERVICE_DATA'] : $commentData['POST_MESSAGE']);
177 }
178
179 protected function getForumMessageFields(): array
180 {
181 return [ 'SERVICE_DATA', 'POST_MESSAGE' ];
182 }
183
184 protected function getSocNetData($data = ''): array
185 {
186 $result = [];
187
188 $paramsList = explode('|', $data);
189
190 if (!empty($paramsList))
191 {
192 foreach ($paramsList as $pair)
193 {
194 [ $key, $value ] = explode('=', $pair);
195 if (isset($key, $value))
196 {
197 $result[$key] = $value;
198 }
199 }
200 }
201
202 return $result;
203 }
204}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
getSourceCommentData(array $additionalParams=[])
getTask($taskId, $checkPermissions=true)