Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
projectprovider.php
1<?php
2
4
12use Bitrix\Socialnetwork\EO_Workgroup;
13use Bitrix\Socialnetwork\EO_Workgroup_Collection;
27
29{
30 public function __construct(array $options = [])
31 {
32 parent::__construct();
33
34 if (isset($options['project']) && is_bool($options['project']))
35 {
36 $this->options['project'] = $options['project'];
37 }
38
39 if (isset($options['extranet']) && is_bool($options['extranet']))
40 {
41 $this->options['extranet'] = $options['extranet'];
42 }
43
44 if (isset($options['landing']) && is_bool($options['landing']))
45 {
46 $this->options['landing'] = $options['landing'];
47 }
48
49 if (isset($options['features']) && is_array($options['features']))
50 {
51 $this->options['features'] = $options['features'];
52 }
53
54 $this->options['fillRecentTab'] = null; // auto
55 if (isset($options['fillRecentTab']) && is_bool($options['fillRecentTab']))
56 {
57 $this->options['fillRecentTab'] = $options['fillRecentTab'];
58 }
59
60 $this->options['createProjectLink'] = null; // auto
61 if (isset($options['createProjectLink']) && is_bool($options['createProjectLink']))
62 {
63 $this->options['createProjectLink'] = $options['createProjectLink'];
64 }
65
66 if (isset($options['projectId']))
67 {
68 if (is_array($options['projectId']))
69 {
70 $this->options['projectId'] = $options['projectId'];
71 }
72 elseif (is_string($options['projectId']) || is_int($options['projectId']))
73 {
74 $this->options['projectId'] = (int)$options['projectId'];
75 }
76 }
77 elseif (isset($options['!projectId']))
78 {
79 if (is_array($options['!projectId']))
80 {
81 $this->options['!projectId'] = $options['!projectId'];
82 }
83 elseif (is_string($options['!projectId']) || is_int($options['!projectId']))
84 {
85 $this->options['!projectId'] = (int)$options['!projectId'];
86 }
87 }
88 }
89
90 public function isAvailable(): bool
91 {
92 return $GLOBALS['USER']->isAuthorized();
93 }
94
95 public function getItems(array $ids): array
96 {
97 return $this->getProjectItems([
98 'projectId' => $ids
99 ]);
100 }
101
102 public function getSelectedItems(array $ids): array
103 {
104 return $this->getProjectItems([
105 'projectId' => $ids
106 ]);
107 }
108
109 public function fillDialog(Dialog $dialog): void
110 {
111 $limit = 100;
112 $projects = $this->getProjectCollection(['limit' => $limit]);
113 $dialog->addItems($this->makeProjectItems($projects, ['tabs' => 'projects']));
114/*
115 if ($projects->count() < $limit)
116 {
117 $entity = $dialog->getEntity('project');
118 if ($entity)
119 {
120 $entity->setDynamicSearch(false);
121 }
122 }
123*/
124 $icon =
125 'data:image/svg+xml;charset=US-ASCII,%3Csvg%20width%3D%2223%22%20height%3D%2223%22%20'.
126 'fill%3D%22none%22%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%3E%3Cpath%20d%3D%22M11'.
127 '.934%202.213a.719.719%200%2001.719%200l3.103%201.79c.222.13.36.367.36.623V8.21a.719.71'.
128 '9%200%2001-.36.623l-3.103%201.791a.72.72%200%2001-.719%200L8.831%208.832a.719.719%200%'.
129 '2001-.36-.623V4.627c0-.257.138-.495.36-.623l3.103-1.791zM7.038%2010.605a.719.719%200%2'.
130 '001.719%200l3.103%201.792a.72.72%200%2001.359.622v3.583a.72.72%200%2001-.36.622l-3.102'.
131 '%201.792a.719.719%200%2001-.72%200l-3.102-1.791a.72.72%200%2001-.36-.623v-3.583c0-.257'.
132 '.138-.494.36-.622l3.103-1.792zM20.829%2013.02a.719.719%200%2000-.36-.623l-3.102-1.792a'.
133 '.719.719%200%2000-.72%200l-3.102%201.792a.72.72%200%2000-.36.622v3.583a.72.72%200%2000'.
134 '.36.622l3.103%201.792a.719.719%200%2000.719%200l3.102-1.791a.719.719%200%2000.36-.623v'.
135 '-3.583z%22%20fill%3D%22%23ABB1B8%22/%3E%3C/svg%3E';
136
137 $dialog->addTab(new Tab([
138 'id' => 'projects',
139 'title' => Loc::getMessage('SOCNET_ENTITY_SELECTOR_PROJECTS_TAB_TITLE'),
140 'stub' => true,
141 'icon' => [
142 'default' => $icon,
143 'selected' => str_replace('ABB1B8', 'fff', $icon),
144 //'default' => '/bitrix/js/socialnetwork/entity-selector/images/project-tab-icon.svg',
145 //'selected' => '/bitrix/js/socialnetwork/entity-selector/images/project-tab-icon-selected.svg'
146 ]
147 ]));
148
149 $onlyProjectsMode = count($dialog->getEntities()) === 1;
150
151 $fillRecentTab = (
152 $this->options['fillRecentTab'] === true ||
153 ($this->options['fillRecentTab'] !== false && $onlyProjectsMode)
154 );
155
156 if ($fillRecentTab)
157 {
158 $this->fillRecentTab($dialog, $projects);
159 }
160
161 $createProjectLink =
162 $this->options['createProjectLink'] === true ||
163 ($this->options['createProjectLink'] !== false && $onlyProjectsMode)
164 ;
165
166 if ($createProjectLink && self::canCreateProject())
167 {
168 $footerOptions = [];
169 if ($dialog->getFooter() === 'BX.SocialNetwork.EntitySelector.Footer')
170 {
171 // Footer could be set from UserProvider
172 $footerOptions = $dialog->getFooterOptions() ?? [];
173 }
174
175 $footerOptions['createProjectLink'] = self::getCreateProjectUrl(UserProvider::getCurrentUserId());
176 $dialog->setFooter('BX.SocialNetwork.EntitySelector.Footer', $footerOptions);
177 }
178 }
179
180 public function doSearch(SearchQuery $searchQuery, Dialog $dialog): void
181 {
182 $dialog->addItems(
183 $this->getProjectItems(['searchQuery' => $searchQuery->getQuery()])
184 );
185 }
186
187 public function getProjectCollection(array $options = []): EO_Workgroup_Collection
188 {
189 $options = array_merge($this->getOptions(), $options);
190
192 }
193
194 public function getProjectItems(array $options = []): array
195 {
197 }
198
199 public function makeProjectItems(EO_Workgroup_Collection $projects, array $options = []): array
200 {
201 return self::makeItems($projects, array_merge($this->getOptions(), $options));
202 }
203
204 public static function getProjects(array $options = []): EO_Workgroup_Collection
205 {
206 $query = WorkgroupTable::query();
207 $query->setSelect(
208 [
209 'ID',
210 'NAME',
211 'ACTIVE',
212 'PROJECT',
213 'CLOSED',
214 'VISIBLE',
215 'OPENED',
216 'IMAGE_ID',
217 'AVATAR_TYPE',
218 'LANDING'
219 ]
220 );
221
222 if (isset($options['visible']) && is_bool(isset($options['visible'])))
223 {
224 $query->where('VISIBLE', $options['visible'] ? 'Y' : 'N');
225 }
226
227 if (isset($options['open']) && is_bool(isset($options['open'])))
228 {
229 $query->where('OPENED', $options['open'] ? 'Y' : 'N');
230 }
231
232 if (isset($options['closed']) && is_bool(isset($options['closed'])))
233 {
234 $query->where('CLOSED', $options['closed'] ? 'Y' : 'N');
235 }
236
237 if (isset($options['landing']) && is_bool(isset($options['landing'])))
238 {
239 $query->where('LANDING', $options['landing'] ? 'Y' : 'N');
240 }
241
242 if (isset($options['active']) && is_bool(isset($options['active'])))
243 {
244 $query->where('ACTIVE', $options['active'] ? 'Y' : 'N');
245 }
246
247 if (isset($options['project']) && is_bool(isset($options['project'])))
248 {
249 $query->where('PROJECT', $options['project'] ? 'Y' : 'N');
250 }
251
252 if (!empty($options['searchQuery']) && is_string($options['searchQuery']))
253 {
254 $query->whereMatch(
255 'SEARCH_INDEX',
256 Filter\Helper::matchAgainstWildcard(
257 Content::prepareStringToken($options['searchQuery']),
258 '*',
259 1
260 )
261 );
262 }
263
264 $currentUserId = (!empty($options['currentUserId']) && is_int($options['currentUserId'])
265 ? $options['currentUserId'] : $GLOBALS['USER']->getId());
266
267 $query->registerRuntimeField(
268 new Reference(
269 'PROJECT_SITE',
270 WorkgroupSiteTable::class,
271 Join::on('this.ID', 'ref.GROUP_ID'),
272 ['join_type' => 'INNER']
273 )
274 );
275
276 $siteId = !empty($options['siteId']) && is_string($options['siteId']) ? $options['siteId'] : SITE_ID;
277 $query->where('PROJECT_SITE.SITE_ID', $siteId);
278
279 if (
280 (
281 !isset($options['myProjectsOnly'])
282 || $options['myProjectsOnly'] === true
283 )
284 && !\CSocNetUser::isCurrentUserModuleAdmin()
285 )
286 {
287 $query->registerRuntimeField(
288 new Reference(
289 'MY_PROJECT',
290 UserToGroupTable::class,
291 Join::on('this.ID', 'ref.GROUP_ID')
292 ->where('ref.USER_ID', $currentUserId)
293 ->where(
294 'ref.ROLE',
295 '<=',
297 ),
298 ['join_type' => 'INNER']
299 )
300 );
301 }
302
303 if (isset($options['viewed']) && is_bool(isset($options['viewed'])))
304 {
305 $query->registerRuntimeField(
306 new Reference(
307 'VIEWED_PROJECT',
308 WorkgroupViewTable::class,
309 Join::on('this.ID', 'ref.GROUP_ID')->where('ref.USER_ID', $currentUserId),
310 ['join_type' => 'INNER']
311 )
312 );
313 }
314
315 $extranetSiteId = Option::get('extranet', 'extranet_site');
316 $extranetSiteId = (
317 $extranetSiteId
318 && ModuleManager::isModuleInstalled('extranet') ? $extranetSiteId : false
319 );
320 if ($extranetSiteId)
321 {
322 $query->registerRuntimeField(
323 new Reference(
324 'EXTRANET_PROJECT',
325 WorkgroupSiteTable::class,
326 Join::on('this.ID', 'ref.GROUP_ID')->where('ref.SITE_ID', $extranetSiteId),
327 ['join_type' => 'LEFT']
328 )
329 );
330
331 $query->registerRuntimeField(
332 new ExpressionField(
333 'IS_EXTRANET', 'CASE WHEN %s IS NOT NULL THEN \'Y\' ELSE \'N\' END', ['EXTRANET_PROJECT.GROUP_ID']
334 )
335 );
336
337 $query->addSelect('IS_EXTRANET');
338
339 if (isset($options['extranet']) && is_bool($options['extranet']))
340 {
341 if ($options['extranet'])
342 {
343 $query->whereNotNull('EXTRANET_PROJECT.GROUP_ID');
344 }
345 else
346 {
347 $query->whereNull('EXTRANET_PROJECT.GROUP_ID');
348 }
349 }
350 }
351
352 $projectIds = [];
353 $projectFilter = (
354 isset($options['projectId'])
355 ? 'projectId'
356 : (isset($options['!projectId']) ? '!projectId' : null)
357 );
358
359 if (isset($options[$projectFilter]))
360 {
361 if (is_array($options[$projectFilter]) && !empty($options[$projectFilter]))
362 {
363 foreach ($options[$projectFilter] as $id)
364 {
365 $projectIds[] = (int)$id;
366 }
367
368 $projectIds = array_unique($projectIds);
369
370 if (!empty($projectIds))
371 {
372 if ($projectFilter === 'projectId')
373 {
374 $query->whereIn('ID', $projectIds);
375 }
376 else
377 {
378 $query->whereNotIn('ID', $projectIds);
379 }
380 }
381 }
382 else if (!is_array($options[$projectFilter]) && (int)$options[$projectFilter] > 0)
383 {
384 if ($projectFilter === 'projectId')
385 {
386 $query->where('ID', (int)$options[$projectFilter]);
387 }
388 else
389 {
390 $query->whereNot('ID', (int)$options[$projectFilter]);
391 }
392 }
393 }
394
395 if (
396 $projectFilter === 'projectId'
397 && empty($options['order'])
398 && count($projectIds) > 1
399 )
400 {
401 $query->registerRuntimeField(
402 new ExpressionField(
403 'ID_SEQUENCE', 'FIELD(%s, ' . implode(',', $projectIds) . ')', 'ID'
404 )
405 );
406
407 $query->setOrder('ID_SEQUENCE');
408 }
409 elseif (!empty($options['order']) && is_array($options['order']))
410 {
411 $query->setOrder($options['order']);
412 }
413 else
414 {
415 $query->setOrder(['NAME' => 'asc']);
416 }
417
418 $isUserModuleAdmin = \CSocNetUser::isUserModuleAdmin($currentUserId, $siteId);
419
420 if (
421 isset($options['features'])
422 && is_array($options['features'])
423 && !empty($options['features'])
424 )
425 {
426 foreach (array_keys($options['features']) as $feature)
427 {
428 if (!self::isAllowedFeatures($feature))
429 {
430 return new EO_Workgroup_Collection();
431 }
432
433 $featureField = new Reference(
434 "BF_{$feature}",
435 FeatureTable::class,
436 Join::on('this.ID', 'ref.ENTITY_ID')
437 ->where('ref.ENTITY_TYPE', FeatureTable::FEATURE_ENTITY_TYPE_GROUP)
438 ->where('ref.FEATURE', $feature)
439 ->where('ref.ACTIVE', 'N'),
440 ['join_type' => 'LEFT']
441 );
442 $query->registerRuntimeField($featureField);
443
444 $query->whereNull("BF_{$feature}.ENTITY_ID");
445 }
446
447 if (!$isUserModuleAdmin)
448 {
449 $featuresPermissionsQuery = self::getFeaturesPermissionsQuery(
450 $currentUserId,
451 $options['features']
452 );
453 if ($featuresPermissionsQuery)
454 {
455 $query->whereIn('ID', $featuresPermissionsQuery);
456 }
457 }
458 }
459
460 if (isset($options['limit']) && is_int($options['limit']))
461 {
462 $query->setLimit($options['limit']);
463 }
464 elseif ($projectFilter !== 'projectId' || empty($projectIds))
465 {
466 $query->setLimit(100);
467 }
468
469 return $query->exec()->fetchCollection();
470 }
471
472 private static function isAllowedFeatures($feature = ''): bool
473 {
474 static $globalFeatures = null;
475
476 if ($globalFeatures === null)
477 {
478 $globalFeatures = \CSocNetAllowed::getAllowedFeatures();
479 }
480
481 if (
482 !isset($globalFeatures[$feature]['allowed'])
483 || !is_array($globalFeatures[$feature]['allowed'])
484 || !in_array(SONET_ENTITY_GROUP, $globalFeatures[$feature]['allowed'], true)
485 || mb_strlen($feature) <= 0
486 )
487 {
488 return false;
489 }
490
491 return true;
492 }
493
497 public static function getFeatureQuery($alias, $feature = '')
498 {
499 if (!self::isAllowedFeatures($feature))
500 {
501 return false;
502 }
503
504 $subQuery = FeatureTable::query();
505 $subQuery->where('ENTITY_TYPE', FeatureTable::FEATURE_ENTITY_TYPE_GROUP);
506 $subQuery->where('FEATURE', $feature);
507 $subQuery->where('ACTIVE', 'N');
508 $subQuery->registerRuntimeField(
509 new ExpressionField(
510 'IS_INACTIVE_IN_GROUP', "CASE WHEN {$alias}.ID = %s THEN 1 ELSE 0 END", 'ENTITY_ID'
511 )
512 );
513 $subQuery->where('IS_INACTIVE_IN_GROUP', 1);
514
515 return $subQuery;
516 }
517
521 public static function getFeaturesPermissionsQuery($currentUserId, $featuresList = [])
522 {
523 $helper = \Bitrix\Main\Application::getConnection()->getSqlHelper();
524 $globalFeatures = \CSocNetAllowed::getAllowedFeatures();
525
526 $workWithClosedGroups = (Option::get('socialnetwork', 'work_with_closed_groups', 'N') === 'Y');
527
528 $query = new \Bitrix\Main\Entity\Query(WorkgroupTable::getEntity());
529 $query->addSelect('ID');
530
531 if ($currentUserId > 0)
532 {
533 $query->registerRuntimeField(new Reference(
534 'UG',
535 UserToGroupTable::getEntity(),
536 Join::on('this.ID', 'ref.GROUP_ID')
537 ->where('ref.USER_ID', $currentUserId),
538 [ 'join_type' => 'INNER' ]
539 ));
540 }
541
542 $hasFilter = false;
543
544 $featureEntity = clone FeatureTable::getEntity();
545
546 foreach ($featuresList as $feature => $operationsList)
547 {
548 if (empty($operationsList))
549 {
550 continue;
551 }
552
553 $hasFilter = true;
554
555 $defaultPerm = 'A';
556 foreach ($globalFeatures[$feature]['operations'] as $operation => $perms)
557 {
558 if (
559 !in_array($operation, $operationsList, true)
561 )
562 {
563 continue;
564 }
565
566 if ($perms[FeatureTable::FEATURE_ENTITY_TYPE_GROUP] > $defaultPerm)
567 {
568 $defaultPerm = $perms[FeatureTable::FEATURE_ENTITY_TYPE_GROUP];
569 }
570 }
571
572 $query->registerRuntimeField(new Reference(
573 "F_{$feature}",
574 $featureEntity,
575 Join::on('this.ID', 'ref.ENTITY_ID')
576 ->where('ref.ENTITY_TYPE', FeatureTable::FEATURE_ENTITY_TYPE_GROUP)
577 ->where('ref.FEATURE', $feature),
578 [ 'join_type' => 'LEFT' ]
579 ));
580
581 $featureEntity->addField(new Reference(
582 "FP_{$feature}",
583 FeaturePermTable::class,
584 Join::on('this.ID', 'ref.FEATURE_ID'),
585 [ 'join_type' => 'LEFT' ]
586 ));
587
588 $query->where(\Bitrix\Main\Entity\Query::filter()
589 ->logic('or')
590 ->whereIn("F_{$feature}.FP_{$feature}.OPERATION_ID", $operationsList)
591 ->whereNull("F_{$feature}.FP_{$feature}.OPERATION_ID")
592 );
593
594 if ($currentUserId > 0)
595 {
596 $minOperationsList = ($globalFeatures[$feature]['minoperation'] ?? []);
597 if (!is_array($minOperationsList))
598 {
599 $minOperationsList = [ $minOperationsList ];
600 }
601
602 $conditionsList = [];
603 $substitutes = [];
604
605 if (!$workWithClosedGroups && !empty($minOperationsList))
606 {
607 $minOperations = implode(', ', array_map(static function($operation) use ($helper) { return "'" . $helper->forSql($operation) . "'"; }, $minOperationsList));
608 $conditionsList[] = "WHEN %s = 'Y' AND %s NOT IN ({$minOperations}) THEN 'A'";
609 $substitutes[] = 'CLOSED';
610 $substitutes[] = "F_{$feature}.FP_{$feature}.OPERATION_ID";
611 }
612
613 $conditionsList[] = "WHEN %s = 'N' AND %s IN ('N', 'L') THEN 'K'";
614 $substitutes[] = 'VISIBLE';
615 $substitutes[] = "F_{$feature}.FP_{$feature}.ROLE";
616
617 $conditionsList[] = 'WHEN %s IS NOT NULL THEN %s';
618 $substitutes[] = "F_{$feature}.FP_{$feature}.ROLE";
619 $substitutes[] = "F_{$feature}.FP_{$feature}.ROLE";
620
621 $conditions = implode(' ', $conditionsList);
622
623 $query->registerRuntimeField(new ExpressionField(
624 "MIN_PERMISSION_{$feature}",
625 "CASE {$conditions} ELSE '{$defaultPerm}' END",
626 $substitutes
627 ));
628
629 $query->registerRuntimeField(
630 new ExpressionField(
631 "HAS_ACCESS_{$feature}",
632 'CASE WHEN %s <= %s THEN 1 ELSE 0 END',
633 [
634 'UG.ROLE',
635 "MIN_PERMISSION_{$feature}",
636 ]
637 )
638 );
639 $query->where("HAS_ACCESS_{$feature}", 1);
640 }
641 else
642 {
643 $query->registerRuntimeField(new ExpressionField(
644 "MIN_PERMISSION_{$feature}",
645 "CASE WHEN %s IS NOT NULL THEN %s ELSE '{$defaultPerm}' END",
646 [
647 "F_{$feature}.FP_{$feature}.ROLE",
648 "F_{$feature}.FP_{$feature}.ROLE"
649 ]
650 ));
651
652 $query->where("MIN_PERMISSION_{$feature}", 'N');
653 }
654 }
655
656 return ($hasFilter ? $query : false);
657 }
658
659 public static function filterByFeatures(
660 EO_Workgroup_Collection $projects, array $features, int $userId, string $siteId
661 )
662 {
663 if (empty($features))
664 {
665 return $projects;
666 }
667
668 $projectIds = $projects->getIdList();
669 foreach ($features as $feature => $operations)
670 {
671 $availableIds = \CSocNetFeatures::isActiveFeature(SONET_ENTITY_GROUP, $projectIds, $feature);
672 if (!is_array($availableIds))
673 {
674 return new EO_Workgroup_Collection();
675 }
676
677 $hasUnavailableId = false;
678 foreach ($availableIds as $projectId => $isAvailable)
679 {
680 if (!$isAvailable)
681 {
682 $hasUnavailableId = true;
683 $projects->removeByPrimary($projectId);
684 }
685 }
686
687 if ($hasUnavailableId)
688 {
689 $projectIds = $projects->getIdList();
690 }
691 }
692
693 $isUserModuleAdmin = \CSocNetUser::isUserModuleAdmin($userId, $siteId);
694 $availableIdsByFeature = [];
695
696 // Features have logic 'AND', whereas operations have logic 'OR'.
697 foreach ($features as $feature => $operations)
698 {
699 if (!is_array($operations) || empty($operations))
700 {
701 $availableIdsByFeature[] = $projectIds;
702 continue;
703 }
704
705 $availableFeatureIds = [];
706 $ids = $projectIds;
707 foreach ($operations as $operation)
708 {
709 if (empty($ids))
710 {
711 break;
712 }
713
714 $availableIds = \CSocNetFeaturesPerms::canPerformOperation(
715 $userId,
716 SONET_ENTITY_GROUP,
717 $ids,
718 $feature,
719 $operation,
720 $isUserModuleAdmin
721 );
722
723 if (!is_array($availableIds))
724 {
725 continue;
726 }
727
728 foreach ($availableIds as $projectId => $isAvailable)
729 {
730 if ($isAvailable)
731 {
732 $availableFeatureIds[] = $projectId;
733 }
734 }
735
736 $ids = array_diff($ids, $availableFeatureIds);
737 }
738
739 $availableIdsByFeature[] = $availableFeatureIds;
740 }
741
742 $availableIds = [];
743 if (!empty($availableIdsByFeature))
744 {
745 $availableIds = (
746 count($availableIdsByFeature) > 1
747 ? call_user_func_array('array_intersect', $availableIdsByFeature)
748 : $availableIdsByFeature[0]
749 );
750 }
751
752 if (empty($availableIds))
753 {
754 return new EO_Workgroup_Collection();
755 }
756
757 $wrongIds = array_diff($projects->getIdList(), $availableIds);
758 foreach ($wrongIds as $wrongId)
759 {
760 $projects->removeByPrimary($wrongId);
761 }
762
763 return $projects;
764 }
765
766 public static function makeItems(EO_Workgroup_Collection $projects, $options = [])
767 {
768 $result = [];
769 foreach ($projects as $project)
770 {
771 $result[] = self::makeItem($project, $options);
772 }
773
774 return $result;
775 }
776
783 public static function makeItem(EO_Workgroup $project, $options = []): Item
784 {
785 $extranetSiteId = Option::get('extranet', 'extranet_site');
786 $extranetSiteId = ($extranetSiteId && ModuleManager::isModuleInstalled('extranet') ? $extranetSiteId : false);
787
788 $entityType =
789 $extranetSiteId && $project->get('IS_EXTRANET') === 'Y'
790 ? 'extranet'
791 : 'project'
792 ;
793
794 $item = new Item(
795 [
796 'id' => $project->getId(),
797 'entityId' => 'project',
798 'entityType' => $entityType,
799 'title' => $project->getName(),
800 'avatar' => self::makeProjectAvatar($project),
801 'customData' => [
802 'landing' => $project->getLanding(),
803 'active' => $project->getActive(),
804 'visible' => $project->getVisible(),
805 'closed' => $project->getClosed(),
806 'open' => $project->getOpened(),
807 'project' => $project->getProject(),
808 ],
809 ]
810 );
811
812 if (!empty($options['tabs']))
813 {
814 $item->addTab($options['tabs']);
815 }
816
817 return $item;
818 }
819
820 public static function makeProjectAvatar(EO_Workgroup $project): ?string
821 {
822 if (!empty($project->getImageId()))
823 {
824 $avatar = \CFile::resizeImageGet(
825 $project->getImageId(),
826 ['width' => 100, 'height' => 100],
827 BX_RESIZE_IMAGE_EXACT,
828 false
829 );
830
831 return !empty($avatar['src']) ? $avatar['src'] : null;
832 }
833
834 if (!empty($project->getAvatarType()))
835 {
836 $url = \Bitrix\Socialnetwork\Helper\Workgroup::getAvatarEntitySelectorUrl($project->getAvatarType());
837 return !empty($url) ? $url : null;
838 }
839
840 return null;
841 }
842
843 public static function getProjectUrl(?int $projectId = null, ?int $currentUserId = null): string
844 {
845 if (UserProvider::isExtranetUser($currentUserId))
846 {
847 $extranetSiteId = Option::get('extranet', 'extranet_site');
848 $projectPage = Option::get('socialnetwork', 'workgroups_page', false, $extranetSiteId);
849 if (!$projectPage)
850 {
851 $projectPage = '/extranet/workgroups/';
852 }
853 }
854 else
855 {
856 $projectPage = Option::get('socialnetwork', 'workgroups_page', false, SITE_ID);
857 if (!$projectPage)
858 {
859 $projectPage = SITE_DIR.'workgroups/';
860 }
861 }
862
863 return $projectPage.'group/'.($projectId !== null ? $projectId : '#id#').'/';
864 }
865
866 public static function getCreateProjectUrl(?int $currentUserId = null): string
867 {
868 $userPage =
869 UserProvider::isExtranetUser($currentUserId)
870 ? UserProvider::getExtranetUserUrl($currentUserId)
871 : UserProvider::getIntranetUserUrl($currentUserId)
872 ;
873
874 return $userPage . 'groups/create/';
875 }
876
877 public static function canCreateProject(): bool
878 {
879 return \Bitrix\Socialnetwork\Helper\Workgroup\Access::canCreate();
880 }
881
882 private function fillRecentTab(Dialog $dialog, EO_Workgroup_Collection $projects): void
883 {
884 $maxProjectsInRecentTab = 30;
885
886 $recentItems = $dialog->getRecentItems()->getEntityItems('project');
887 if (count($recentItems) < $maxProjectsInRecentTab)
888 {
889 $limit = $maxProjectsInRecentTab - count($recentItems);
890 $recentGlobalItems = $dialog->getGlobalRecentItems()->getEntityItems('project');
891 foreach ($recentGlobalItems as $recentGlobalItem)
892 {
893 if ($limit <= 0)
894 {
895 break;
896 }
897
898 if (!isset($recentItems[$recentGlobalItem->getId()]) && $recentGlobalItem->isLoaded())
899 {
900 $dialog->getRecentItems()->add($recentGlobalItem);
901 $limit--;
902 }
903 }
904
905 $recentItems = $dialog->getRecentItems()->getEntityItems('project');
906 }
907
908 if (count($recentItems) < $maxProjectsInRecentTab)
909 {
910 $recentIds = array_map('intval', array_keys($recentItems));
911
912 $dialog->addRecentItems(
913 $this->getProjectItems([
914 '!projectId' => $recentIds,
915 'viewed' => true,
916 'order' => ['VIEWED_PROJECT.DATE_VIEW' => 'desc'],
917 'limit' => $maxProjectsInRecentTab - count($recentItems)
918 ])
919 );
920
921 $recentItems = $dialog->getRecentItems()->getEntityItems('project');
922 }
923
924 if (count($recentItems) < $maxProjectsInRecentTab)
925 {
926 $limit = $maxProjectsInRecentTab - count($recentItems);
927 foreach ($projects as $project)
928 {
929 if ($limit <= 0)
930 {
931 break;
932 }
933
934 if (isset($recentItems[$project->getId()]))
935 {
936 continue;
937 }
938
939 $dialog->getRecentItems()->add(
940 new RecentItem([
941 'id' => $project->getId(),
942 'entityId' => 'project',
943 'loaded' => true,
944 ])
945 );
946
947 $limit--;
948 }
949 }
950 }
951}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static getProjectUrl(?int $projectId=null, ?int $currentUserId=null)
static makeItems(EO_Workgroup_Collection $projects, $options=[])
static getFeaturesPermissionsQuery($currentUserId, $featuresList=[])
makeProjectItems(EO_Workgroup_Collection $projects, array $options=[])
static filterByFeatures(EO_Workgroup_Collection $projects, array $features, int $userId, string $siteId)
setFooter(string $footer, array $options=[])
Definition dialog.php:175
$GLOBALS['____1444769544']
Definition license.php:1