3namespace Bitrix\Socialnetwork\Component\WorkgroupList;
7use Bitrix\Main\Entity\Query;
8use Bitrix\Main\ORM\Query\Join;
9use Bitrix\Main\ORM\Fields\Relations\Reference;
10use Bitrix\Main\ORM\Fields\ExpressionField;
11use Bitrix\Main\UserCounterTable;
12use Bitrix\Socialnetwork\Component\WorkgroupList;
13use Bitrix\Socialnetwork\Internals\Counter\CounterFilter;
14use Bitrix\Socialnetwork\WorkgroupSiteTable;
31 private int $currentUserId;
32 private int $contextUserId;
37 private array $numericFieldsList;
41 private array $integerFieldsList;
45 private array $stringFieldsList;
49 private array $booleanFieldsList;
53 private array $dateFieldsList;
54 private bool $hasAccessToTasksCounters;
58 $this->fieldsList = (
$params[
'fieldsList'] ?? []);
59 $this->gridFilter = (
$params[
'gridFilter'] ?? []);
60 $this->currentUserId = (int)(
$params[
'currentUserId'] ?? 0);
61 $this->contextUserId = (int)(
$params[
'contextUserId'] ?? 0);
62 $this->mode = (string)(
$params[
'mode'] ??
'');
63 $this->query = $query;
64 $this->hasAccessToTasksCounters = (boolean)(
$params[
'hasAccessToTasksCounters'] ??
false);
75 if ($this->query ===
null)
81 !empty($this->gridFilter[
'EXTRANET'])
82 && $this->gridFilter[
'EXTRANET'] ===
'Y'
86 $this->query->registerRuntimeField(
89 WorkgroupSiteTable::class,
90 Join::on(
'this.ID',
'ref.GROUP_ID')->where(
'ref.SITE_ID', static::getExtranetSiteId()),
91 [
'join_type' =>
'INNER']
97 !empty($this->gridFilter[
'FAVORITES'])
98 && $this->gridFilter[
'FAVORITES'] ===
'Y'
99 && $this->currentUserId > 0
102 $filter[
'=FAVORITES.USER_ID'] = $this->currentUserId;
105 if ($this->runtimeFieldsManager->has(
'SCRUM'))
107 if ($this->mode === WorkgroupList::MODE_TASKS_SCRUM)
112 elseif ($this->mode === WorkgroupList::MODE_TASKS_PROJECT)
118 $this->initFilterFieldsData();
127 if ($this->hasAccessToTasksCounters)
141 private function initFilterFieldsData(): void
143 $this->numericFieldsList = [
145 'FILTER_FIELD_NAME' =>
'ID',
146 'FIELD_NAME' =>
'ID',
147 'VALUE_FROM' => ($this->gridFilter[
'ID_from'] ??
false),
148 'VALUE_TO' => ($this->gridFilter[
'ID_to'] ??
false)
152 $this->integerFieldsList = [
154 'FILTER_FIELD_NAME' =>
'OWNER',
155 'FIELD_NAME' =>
'OWNER_ID',
157 'VALUE' => preg_replace(
'/^U(\d+)$/',
'$1', ($this->gridFilter[
'OWNER'] ??
'')),
160 'FILTER_FIELD_NAME' =>
'MEMBER',
161 'FIELD_NAME' =>
'MEMBER_ID',
163 'VALUE' => preg_replace(
'/^U(\d+)$/',
'$1', ($this->gridFilter[
'MEMBER'] ??
'')),
167 $this->stringFieldsList = [
169 'FILTER_FIELD_NAME' =>
'NAME',
170 'FIELD_NAME' =>
'NAME',
172 'VALUE' => ($this->gridFilter[
'NAME'] ??
'') .
'%',
175 'FILTER_FIELD_NAME' =>
'TAG',
176 'FIELD_NAME' =>
'TAG',
178 'VALUE' => ($this->gridFilter[
'TAG'] ??
'') .
'%',
182 $this->booleanFieldsList = [
184 'FILTER_FIELD_NAME' =>
'CLOSED',
185 'FIELD_NAME' =>
'CLOSED',
187 'VALUE' => ($this->gridFilter[
'CLOSED'] ??
''),
190 'FILTER_FIELD_NAME' =>
'VISIBLE',
191 'FIELD_NAME' =>
'VISIBLE',
193 'VALUE' => ($this->gridFilter[
'VISIBLE'] ??
''),
196 'FILTER_FIELD_NAME' =>
'OPENED',
197 'FIELD_NAME' =>
'OPENED',
199 'VALUE' => ($this->gridFilter[
'OPENED'] ??
''),
202 'FILTER_FIELD_NAME' =>
'PROJECT',
203 'FIELD_NAME' =>
'PROJECT',
205 'VALUE' => ($this->gridFilter[
'PROJECT'] ??
''),
208 'FILTER_FIELD_NAME' =>
'SCRUM',
209 'FIELD_NAME' =>
'SCRUM',
211 'VALUE' => ($this->gridFilter[
'SCRUM'] ??
''),
214 'FILTER_FIELD_NAME' =>
'LANDING',
215 'FIELD_NAME' =>
'LANDING',
217 'VALUE' => ($this->gridFilter[
'LANDING'] ??
''),
221 $this->dateFieldsList = [
223 'FILTER_FIELD_NAME' =>
'PROJECT_DATE_START',
224 'FIELD_NAME' =>
'PROJECT_DATE_START',
225 'VALUE_FROM' => ($this->gridFilter[
'PROJECT_DATE_START_from'] ??
false),
226 'VALUE_TO' => ($this->gridFilter[
'PROJECT_DATE_START_to'] ??
false)
229 'FILTER_FIELD_NAME' =>
'PROJECT_DATE_FINISH',
230 'FIELD_NAME' =>
'PROJECT_DATE_FINISH',
231 'VALUE_FROM' => ($this->gridFilter[
'PROJECT_DATE_FINISH_from'] ??
false),
232 'VALUE_TO' => ($this->gridFilter[
'PROJECT_DATE_FINISH_to'] ??
false)
240 foreach ($this->integerFieldsList as $field)
245 is_array($field[
'VALUE'])
246 && !empty($field[
'VALUE'])
249 $value = $field[
'VALUE'];
252 !is_array($field[
'VALUE'])
253 && (
string)$field[
'VALUE'] !==
''
256 $value = (int)$field[
'VALUE'];
259 if ($value !==
false)
262 'FILTER_FIELD_NAME' => $field[
'FILTER_FIELD_NAME'],
263 'FIELD_NAME' => $field[
'FIELD_NAME'],
264 'OPERATION' => ($field[
'OPERATION'] ??
'='),
275 foreach ($this->numericFieldsList as $field)
278 empty($field[
'VALUE_FROM'])
279 && empty($field[
'VALUE_TO'])
286 !empty($field[
'VALUE_FROM'])
287 && !empty($field[
'VALUE_TO'])
288 && $field[
'VALUE_FROM'] === $field[
'VALUE_TO'])
290 $filter[
'=' . $field[
'FIELD_NAME']] = $field[
'VALUE_FROM'];
294 if (!empty($field[
'VALUE_FROM']))
296 $filter[
'>=' . $field[
'FIELD_NAME']] = $field[
'VALUE_FROM'];
299 if (!empty($field[
'VALUE_TO']))
301 $filter[
'<=' . $field[
'FIELD_NAME']] = $field[
'VALUE_TO'];
311 foreach ($this->stringFieldsList as $field)
313 if ($field[
'VALUE'] !==
'')
316 'FILTER_FIELD_NAME' => $field[
'FILTER_FIELD_NAME'],
317 'FIELD_NAME' => $field[
'FIELD_NAME'],
318 'OPERATION' => ($field[
'OPERATION'] ??
'%='),
319 'VALUE' => $field[
'VALUE'],
329 foreach ($this->booleanFieldsList as $field)
331 if (in_array($field[
'VALUE'], [
'Y',
'N'],
true))
334 'FILTER_FIELD_NAME' => $field[
'FILTER_FIELD_NAME'],
335 'FIELD_NAME' => $field[
'FIELD_NAME'],
337 'VALUE' => $field[
'VALUE'],
347 foreach ($this->dateFieldsList as $field)
350 !empty($field[
'VALUE_FROM'])
351 || !empty($field[
'VALUE_TO'])
355 'FILTER_FIELD_NAME' => $field[
'FILTER_FIELD_NAME'],
356 'FIELD_NAME' => $field[
'FIELD_NAME'],
357 'VALUE_FROM' => ($field[
'VALUE_FROM'] ?? $this->gridFilter[$field[
'FILTER_FIELD_NAME']]),
358 'VALUE_TO' => ($field[
'VALUE_TO'] ?? $this->gridFilter[$field[
'FILTER_FIELD_NAME']]),
370 isset($this->gridFilter[
'FIND'])
371 && $this->gridFilter[
'FIND']
374 $findFilter = $this->
getFindFilter($this->gridFilter[
'FIND']);
375 if (!empty($findFilter))
387 !in_array($gridFilterField, [
'COUNTERS',
'COMMON_COUNTERS' ],
true)
388 || empty($this->gridFilter[$gridFilterField])
389 || !Loader::includeModule(
'tasks')
395 $this->query->setDistinct(
true);
397 $this->query->registerRuntimeField(
401 Join::on(
'this.ID',
'ref.GROUP_ID')->where(
'ref.USER_ID', $this->contextUserId),
402 [
'join_type' =>
'INNER']
405 $this->runtimeFieldsManager->add(
'TASKS_COUNTER');
407 if ($gridFilterField ===
'COUNTERS')
411 'INCLUDE' => TasksCounter\CounterDictionary::MAP_EXPIRED,
415 'INCLUDE' => TasksCounter\CounterDictionary::MAP_COMMENTS,
418 'PROJECT_EXPIRED' => [
419 'INCLUDE' => array_merge(
420 [
TasksCounter\CounterDictionary::COUNTER_GROUP_EXPIRED ],
423 'EXCLUDE' => TasksCounter\CounterDictionary::MAP_EXPIRED,
425 'PROJECT_NEW_COMMENTS' => [
426 'INCLUDE' => array_merge(
427 [
TasksCounter\CounterDictionary::COUNTER_GROUP_COMMENTS ],
430 'EXCLUDE' => TasksCounter\CounterDictionary::MAP_COMMENTS,
433 $type = $typesMap[$this->gridFilter[$gridFilterField]];
435 elseif ($gridFilterField ===
'COMMON_COUNTERS')
438 'INCLUDE' => array_merge(
439 array_values(
TasksCounter\CounterDictionary::MAP_EXPIRED),
440 array_values(
TasksCounter\CounterDictionary::MAP_COMMENTS),
448 if (
$type[
'EXCLUDE'])
450 $this->query->registerRuntimeField(
451 'EXCLUDED_COUNTER_EXISTS',
453 'EXCLUDED_COUNTER_EXISTS',
460 AND USER_ID = " . $this->contextUserId .
"
461 AND TYPE IN ('" . implode(
"','",
$type[
'EXCLUDE']) .
"')
464 [
'ID',
'TASKS_COUNTER.TASK_ID' ]
467 $this->runtimeFieldsManager->add(
'EXCLUDED_COUNTER_EXISTS');
475 if (empty($this->gridFilter[
'COMMON_COUNTERS']))
495 empty($this->gridFilter[
'PROJECT_DATE_from'])
496 && empty($this->gridFilter[
'PROJECT_DATE_to'])
502 if (!empty($this->gridFilter[
'PROJECT_DATE_from']))
504 $filter[
'>=PROJECT_DATE_START'] = $this->gridFilter[
'PROJECT_DATE_from'];
507 if (!empty($this->gridFilter[
'PROJECT_DATE_to']))
509 $filter[
'<=PROJECT_DATE_FINISH'] = $this->gridFilter[
'PROJECT_DATE_to'];
517 $filterFieldName = (
$params[
'FILTER_FIELD_NAME'] ??
'');
518 $value = (
$params[
'VALUE'] ??
'');
521 $filterFieldName ===
''
530 &&
$params[
'FIELD_NAME'] !==
''
534 $operation = (
$params[
'OPERATION'] ??
'=');
536 if (in_array($fieldName, $this->fieldsList,
true))
538 $filter[$operation . $fieldName] = $value;
546 $filterFieldName = (
$params[
'FILTER_FIELD_NAME'] ??
'');
547 $value = (
$params[
'VALUE'] ??
'');
549 if ($filterFieldName ===
'')
555 && trim($value,
'%') ===
''
563 && empty(array_filter($value,
static function ($item) {
564 return trim($item,
'%') !==
'';
573 &&
$params[
'FIELD_NAME'] !==
''
577 $operation = (
$params[
'OPERATION'] ??
'%=');
579 if (in_array($fieldName, $this->fieldsList,
true))
581 $filter[$operation . $fieldName] = $value;
589 $filterFieldName = (
$params[
'FILTER_FIELD_NAME'] ??
'');
590 $valueFrom = (
$params[
'VALUE_FROM'] ??
'');
591 $valueTo = (
$params[
'VALUE_TO'] ??
'');
594 $filterFieldName ===
''
606 &&
$params[
'FIELD_NAME'] !==
''
611 if (in_array($fieldName, $this->fieldsList,
true))
613 if ($valueFrom !==
'')
615 $filter[
'>=' . $fieldName] = $valueFrom;
619 $filter[
'<=' . $fieldName] = $valueTo;
634 $value = trim($value);
644 $result[
'*SEARCH_INDEX'] = $value;
650 private static function getExtranetSiteId(): string
657 Loader::includeModule(
'extranet')
658 ? \CExtranet::getExtranetSiteId()
static getExtranetAvailability()
static canUseFulltextSearch($token, $type=self::TYPE_STRING)
static prepareIntegerToken($token)
static isIntegerToken($token)
static prepareStringToken($token)
processIntegerFields($filter)
processFind(array $filter)
addFilterInteger(array $filter=[], array $params=[])
__construct(Query $query, RuntimeFieldsManager $runtimeFieldsManager, array $params=[])
processCommonCounterFilter(array $filter)
processTasksCounterFilter(array $filter, string $gridFilterField='COUNTERS')
processBooleanFields(array $filter)
getFindFilter(string $value)
processDateFields(array $filter)
addFilterString(array $filter=[], array $params=[])
processNumericFields($filter)
processStringFields(array $filter)
processProjectDateFilter(array $filter)
addFilterDateTime(array $filter=[], array $params=[])
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']